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

Escape character escaping multiple consecutive markdown characters #1236

Open
JoseMezaMendieta opened this issue Jul 30, 2024 · 4 comments · May be fixed by #1257
Open

Escape character escaping multiple consecutive markdown characters #1236

JoseMezaMendieta opened this issue Jul 30, 2024 · 4 comments · May be fixed by #1257

Comments

@JoseMezaMendieta
Copy link

Error details
The documentation says that the escape character "" behaves in the same way that it generally does for Python. To my understanding, in Python the escape character only applies to 1 single instance immediately after the escape character. However, the escape character seems to be escaping multiple instances of special characters immediately after it. In the following code example, I am trying to escape the first instance of double asterisks, then enable bold, print the word in bold, disable bold, then print double asterisks again. All this should be done with no spaces in between, however, the output is not what was expected.

Minimal code
Please include some minimal Python code reproducing your issue:

from fpdf import FPDF

pdf = FPDF(format=(30, 10))
pdf.set_margin(2)
pdf.add_page()
pdf.set_font("Times", size=12)

txt = "\\****Lorem**\\**"
pdf.cell(w=50, text=txt, align='L', new_x='RIGHT', new_y='TOP', border=0, markdown=True,)

pdf.output("md.pdf")

Expected output:
image

Actual output:
image

Environment
Please provide the following information:

@gmischler
Copy link
Collaborator

Thanks for reporting this, @JoseMezaMendieta , and welcome to fpdf2!

The equivalence to the escape backslash in Python is obviously not identical, as in our case it is supposed to always escape exactly two characters at a time instead of one. But of course it should not escape any longer sequence than that. Pinging the implementer @david-fed to see if he has a good idea how to fix this.

@gmischler
Copy link
Collaborator

Or could we interest you in submitting a PR, @JoseMezaMendieta ?

@JoseMezaMendieta
Copy link
Author

I'd be interested in taking a crack at it! It'd be my first contribution if I can figure it out.

@Lucas-C
Copy link
Member

Lucas-C commented Aug 19, 2024

The equivalence to the escape backslash in Python is obviously not identical, as in our case it is supposed to always escape exactly two characters at a time instead of one. But of course it should not escape any longer sequence than that. Pinging the implementer @david-fed to see if he has a good idea how to fix this.

I just reported a similar problem in #1215 (comment) 😊

I did not see this issue from @JoseMezaMendieta beforehand (thank you for opening it 👍)

I think we should conform to the CommonMark standard regarding character escaping rules.

smilerightnow added a commit to smilerightnow/fpdf2 that referenced this issue Sep 4, 2024
@smilerightnow smilerightnow linked a pull request Sep 4, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants