Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure markdown parsing does not choke on partial links #6535

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions panel/pane/markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,16 @@ def _transform_object(self, obj: Any) -> Dict[str, Any]:
**self.renderer_options
)
else:
html = self._get_parser(
parser = self._get_parser(
self.renderer, tuple(self.plugins), **self.renderer_options
).render(obj)
)
try:
html = parser.render(obj)
except IndexError:
# Likely markdown-it mdurl parser error
with parser.reset_rules():
parser.disable('link')
html = parser.render(obj)
return dict(object=escape(html))

def _process_param_change(self, params):
Expand Down
15 changes: 14 additions & 1 deletion panel/tests/pane/test_markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def test_markdown_pane_newline(document, comm):
assert pane._models[model.ref['id']][0] is model
assert model.text == "<p>Hello\nWorld\nI'm here!</p>\n"


def test_markdown_pane_markdown_it_renderer(document, comm):
pane = Markdown("""
- [x] Task1
Expand All @@ -122,6 +121,20 @@ def test_markdown_pane_markdown_it_renderer(document, comm):
'type="checkbox"> Task2</li>\n</ul>\n'
)

def test_markdown_pane_markdown_it_renderer_partial_links(document, comm):
pane = Markdown("[Test](http:/", renderer='markdown-it')

model = pane.get_root(document, comm=comm)

assert model.text == '<p>[Test](http:/</p>\n'

pane.object = "[Test](http://"

assert model.text == '<p>[Test](http://</p>\n'

pane.object = "[Test](http://google.com)"
assert model.text == '<p><a href="http://google.com">Test</a></p>\n'

def test_markdown_pane_extensions(document, comm):
pane = Markdown("""
```python
Expand Down
Loading