mirror of
https://github.com/Textualize/rich.git
synced 2025-12-23 07:08:35 +00:00
Merge 22f38ec40e into 4d6d631a3d
This commit is contained in:
commit
2865c8d19b
2 changed files with 12 additions and 1 deletions
|
|
@ -508,6 +508,7 @@ class Markdown(JupyterMixin):
|
|||
enabled. Defaults to None.
|
||||
inline_code_theme: (Optional[str], optional): Pygments theme for inline code
|
||||
highlighting, or None for no highlighting. Defaults to None.
|
||||
breaks (bool, optional): Enable line breaks. Defaults to False.
|
||||
"""
|
||||
|
||||
elements: ClassVar[dict[str, type[MarkdownElement]]] = {
|
||||
|
|
@ -540,6 +541,7 @@ class Markdown(JupyterMixin):
|
|||
hyperlinks: bool = True,
|
||||
inline_code_lexer: str | None = None,
|
||||
inline_code_theme: str | None = None,
|
||||
breaks: bool = False,
|
||||
) -> None:
|
||||
parser = MarkdownIt().enable("strikethrough").enable("table")
|
||||
self.markup = markup
|
||||
|
|
@ -550,6 +552,7 @@ class Markdown(JupyterMixin):
|
|||
self.hyperlinks = hyperlinks
|
||||
self.inline_code_lexer = inline_code_lexer
|
||||
self.inline_code_theme = inline_code_theme or code_theme
|
||||
self.breaks = breaks
|
||||
|
||||
def _flatten_tokens(self, tokens: Iterable[Token]) -> Iterable[Token]:
|
||||
"""Flattens the token stream."""
|
||||
|
|
@ -592,7 +595,7 @@ class Markdown(JupyterMixin):
|
|||
elif node_type == "hardbreak":
|
||||
context.on_text("\n", node_type)
|
||||
elif node_type == "softbreak":
|
||||
context.on_text(" ", node_type)
|
||||
context.on_text("\n" if self.breaks else " ", node_type)
|
||||
elif node_type == "link_open":
|
||||
href = str(token.attrs.get("href", ""))
|
||||
if self.hyperlinks:
|
||||
|
|
|
|||
|
|
@ -198,6 +198,14 @@ def test_table_with_empty_cells() -> None:
|
|||
expected = len(render(complete_table).splitlines())
|
||||
assert result == expected
|
||||
|
||||
# write a test where markdown breaks is set to true
|
||||
def test_markdown_render_breaks():
|
||||
markdown = Markdown("this is a breaks test", breaks=True)
|
||||
result = render(markdown)
|
||||
print(repr(result))
|
||||
|
||||
expected = ('this is a breaks test \n')
|
||||
assert result == expected
|
||||
|
||||
if __name__ == "__main__":
|
||||
markdown = Markdown(MARKDOWN)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue