Skip to content

Fix markdown character escaping bug (issue #1236)#1741

Open
amidou-naba wants to merge 2 commits intopy-pdf:masterfrom
amidou-naba:CHANGELOG.md
Open

Fix markdown character escaping bug (issue #1236)#1741
amidou-naba wants to merge 2 commits intopy-pdf:masterfrom
amidou-naba:CHANGELOG.md

Conversation

@amidou-naba
Copy link

@amidou-naba amidou-naba commented Feb 4, 2026

e.g. Fixes #0

Checklist:

  • A unit test is covering the code added / modified by this PR

  • In case of a new feature, docstrings have been added, with also some documentation in the docs/ folder

  • A mention of the change is present in CHANGELOG.md

  • This PR is ready to be merged

By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.

@andersonhc andersonhc changed the title Bug #1236 has been fixed Fix markdown character escaping bug (issue #1236) Feb 4, 2026
@andersonhc
Copy link
Collaborator

Thank you for opening this PR @amidou-naba
I'll try to complete the review later today.

@amidou-naba
Copy link
Author

Hello,
I am submitting my PR related to bug #1236, which I worked on.
This issue required updating several files and fixing parts of the code.
I also fixed some escaping characters that were not working correctly.
The effects of these fixes can be seen in merge_fragments, where the additional issues have been resolved.

Thank you for the review.

Copy link
Collaborator

@andersonhc andersonhc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR, it looks really good!
I am adding some comments on what needs to be fixed before we can merge it.

text = text[2:]
continue


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are removing characters from the input text even when markdown=False. This portion of code should be inside an if markdown: block

frags = tuple(FPDF()._parse_chars("****BOLD**", True))
expected = (Fragment("****BOLD", GSTATE, k=PDF.k),)
expected = (Fragment("**BOLD", GSTATE_B, k=PDF.k),)
frags = merge_fragments(tuple(FPDF()._parse_chars("\\****BOLD**\\**", True)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you missing an assert after line 200

Comment on lines +4470 to +4475
if self.MARKDOWN_ESCAPE_CHARACTER == tlt[0] and tlt[1:] in [
"**",
"__",
"~~",
"--",
]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if self.MARKDOWN_ESCAPE_CHARACTER == tlt[0] and tlt[1:] in [
"**",
"__",
"~~",
"--",
]:
if tlt.startswith(self.MARKDOWN_ESCAPE_CHARACTER) and tlt[1:] in (
self.MARKDOWN_BOLD_MARKER,
self.MARKDOWN_ITALICS_MARKER,
self.MARKDOWN_STRIKETHROUGH_MARKER,
self.MARKDOWN_UNDERLINE_MARKER,
):

This change would make it easier to read - less 'magic values' across the code.

@amidou-naba
Copy link
Author

amidou-naba commented Feb 5, 2026 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants