Skip to content

Link Conversion Fails with Preceding or Following Square Brackets #552

@syntaxsurge

Description

@syntaxsurge

Issue Description

I've encountered an issue with the markdown2 library where links are not properly converted to HTML when there are square brackets immediately before or after the link syntax. This issue disrupts the expected formatting and link functionality in the converted Markdown text.

Steps to Reproduce

  1. Use the markdown2 library to convert a Markdown string that includes a link surrounded by square brackets.
  2. Observe that the link is not correctly converted into an HTML anchor tag.

Sample Python Code to Reproduce the Issue

The following Python code snippet can be used to reproduce the issue with the markdown2 library:

import markdown2

# Sample Markdown string with a link surrounded by square brackets
markdown_text = '''
[before]
[Triggers of Alarm Systems](https://www.youtube.com/watch?v=aJOTlE1K90k&list=RDGMEMQ1dJ7wXfLlqCjwV0xfSNbA&index=3)
[after]
'''

# Convert Markdown to HTML
html_output = markdown2.markdown(markdown_text, extras=['tables', 'footnotes', 'markdown-in-html', 'cuddled-lists'])

# Print the HTML output
print("HTML Output:")
print(html_output)

Expected Result

The link in the Markdown string should be converted into an HTML anchor tag, producing an output similar to:

<p>[before]
<a href="https://www.youtube.com/watch?v=aJOTlE1K90k&list=RDGMEMQ1dJ7wXfLlqCjwV0xfSNbA&index=3">Triggers of Alarm Systems</a>
[after]</p>

Actual Result

The actual output keeps the Markdown link syntax without converting it into an HTML anchor tag:

<p>[before]
[Triggers of Alarm Systems](https://www.youtube.com/watch?v=aJOTlE1K90k&amp;list=RDGMEMQ1dJ7wXfLlqCjwV0xfSNbA&amp;index=3)
[after]</p>

This code snippet should help in replicating the issue for troubleshooting and resolving the problem.

Additional Context

This issue seems to be specific to cases where square brackets immediately surround the Markdown link syntax. Removing the surrounding square brackets results in correct HTML conversion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions