Output code block :param str content: code string :param str language: language of code :param int rows: The max lines of code can be displayed, no limit by default. The scroll bar will be displayed when the content exceeds. :param int scope, position: Those arguments have the
(content: str, language: str = '', rows: int = None, scope: str = None,
position: int = OutputPosition.BOTTOM)
| 480 | |
| 481 | |
| 482 | def put_code(content: str, language: str = '', rows: int = None, scope: str = None, |
| 483 | position: int = OutputPosition.BOTTOM) -> Output: |
| 484 | """ |
| 485 | Output code block |
| 486 | |
| 487 | :param str content: code string |
| 488 | :param str language: language of code |
| 489 | :param int rows: The max lines of code can be displayed, no limit by default. The scroll bar will be displayed when the content exceeds. |
| 490 | :param int scope, position: Those arguments have the same meaning as for `put_text()` |
| 491 | """ |
| 492 | if not isinstance(content, str): |
| 493 | content = str(content) |
| 494 | |
| 495 | # For fenced code blocks, escaping the backtick need to use more backticks |
| 496 | backticks = '```' |
| 497 | while backticks in content: |
| 498 | backticks += '`' |
| 499 | |
| 500 | code = "%s%s\n%s\n%s" % (backticks, language, content, backticks) |
| 501 | out = put_markdown(code, scope=scope, position=position) |
| 502 | if rows is not None: |
| 503 | max_height = rows * 19 + 32 # 32 is the code css padding |
| 504 | out.style("max-height: %spx" % max_height) |
| 505 | return out |
| 506 | |
| 507 | |
| 508 | def _left_strip_multiple_line_string_literal(s): |
no test coverage detected
searching dependent graphs…