failed WRONG_FIX UNSUBMITTED wrong_fix_unsubmitted(None) · None tool calls · 0 s · Textualize/rich
Fix markdown table rendering issue with inline styles/links ## Type of changes - [x] Bug fix - [ ] New feature - [ ] Documentation / docstrings - [x] Tests - [ ] Other ## Checklist - [x] I've run the latest [black](https://github.com/psf/black) with default args on new code. - [x] I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate. - [x] I've added tests for new code. - [x] I accept that @willmcgugan may be pedantic in the code review. ## Description The table data elements were not interacting well with inline styles (in the rich sense) and the table data element would have its content overridden every time we found another excerpt of text with a different style. The fix was to do something similar to what `TextElement` does in its method `on_text`, which is to append the new content instead of replacing it. This fixes #3115.
| # | Tool | Arguments | Result |
|---|---|---|---|
| No trace captured. | |||
--- a/rich/markdown.py
+++ b/rich/markdown.py
@@ -314,7 +314,7 @@ class TableDataElement(MarkdownElement):
@classmethod
def create(cls, markdown: "Markdown", token: Token) -> "MarkdownElement":
- style = str(token.attrs.get("style" "")) or ""
+ style = str(token.attrs.get("style")) or ""
justify: JustifyMethod
if "text-align:right" in style:
@@ -330,15 +330,13 @@ def create(cls, markdown: "Markdown", token: Token) -> "MarkdownElement":
return cls(justify=justify)
def __init__(self, justify: JustifyMethod) -> None:
- self.content: TextType = ""
+ self.content: Text = Text("", justify=justify)
self.justify = justify
def on_text(self, context: "MarkdownContext", text: TextType) -> None:
- plain = text.plain if isinstance(text, Text) else text
- style = text.style if isinstance(text, Text) else ""
- self.content = Text(
- plain, justify=self.justify, style=context.style_stack.current
- )
+ text = Text(text) if isinstance(text, str) else text
+ text.stylize(context.current_style)
+ self.content.append_text(text)
class ListElement(MarkdownElement):\x1b[0m\n\x1b[1;33m \x1b[0m\x1b[48;2;39;40;34m \x1b[0m\x1b[48;2;39;40;34mCode block \x1b[0m\x1b[48;2;39;40;34m \x1b[0m\n\x1b[1;33m \x1b[0m\x1b[48;2;39;40;34m \x1b[0m\n" > assert rendered_markdown == expected E AssertionError: assert '┏━━━━━━━━━━━... \n' == '┏━━━━━━━━━━━... \x1b[0m\n' E E Skipping 1211 identical leading characters in diff, use -v to show E - d[0m, [1;36;40mmonospace[0m. E ? ------ E + d[0m, [1mmonospace[0m. E E Horizontal rule: ... E E ...Full output truncated (85 lines hidden), use '-vv' to show tests/test_markdown.py:103: AssertionError ----------------------------- Captured stdout call ----------------------------- '┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n┃ \x1b[1mHeading\x1b[0m ┃\n┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n\n\n \x1b[1;4mSub-heading\x1b[0m \n\n \x1b[1mHeading\x1b[0m \n\n \x1b[1;2mH4 Heading\x1b[0m \n\n \x1b[4mH5 Heading\x1b[0m \n\n \x1b[3mH6 Heading\x1b[0m \n\nParagraphs are separated by a blank line. \n\nTwo spaces at the end of a line \nproduces a line break. \n\nText attributes \x1b[3mitalic\x1b[0m, \x1b[1mbold\x1b[0m, \x1b[1mmonospace\x1b[0m. \n\nHorizontal rule: \n\n────────────────────────────────────────────────────────────────────────────────────────────────────\nBullet list: \n\n\x1b[1m • \x1b[0mapples \n\x1b[1m • \x1b[0moranges \n\x1b[1m • \x1b[0mpears \n\nNumbered list: \n\n\x1b[1m 1 \x1b[0mlather \n\x1b[1m 2 \x1b[0mrinse \n\x1b[1m 3 \x1b[0mrepeat \n\nAn \x1b]8;id=0;foo\x1b\\\x1b[4mexample\x1b[0m\x1b]8;;\x1b\\. \n\n▌ Markdown uses email-style > characters for blockquoting. \n▌ Lorem ipsum \n\n🌆 \x1b]8;id=0;foo\x1b\\progress\x1b]8;;\x1b\\ \n\n \n a=1 \n \n\n \n import this \n \n\n \n foobar \n \n\n \n import this \n \n\n\x1b[1m 1 \x1b[0mList item \n\x1b[1m \x1b[0m \n\x1b[1m \x1b[0m Code block \n\x1b[1m \x1b[0m \n' !!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!! 1 failed in 0.20s