forked from reingart/pyfpdf
-
Notifications
You must be signed in to change notification settings - Fork 249
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
Added support for escape character in markdown text #1224
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b74f2e8
Added support for escape character in markdown text
david-fed 7b46a18
updated documentation
david-fed f0e59c5
Fixed escape character handling & added more tests
david-fed e386a16
rephrased docu
david-fed 56d0f2c
updated documentation
david-fed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -181,20 +181,25 @@ An optional `markdown=True` parameter can be passed to the [`cell()`](fpdf/fpdf. | |||||||||||||||||||||
& [`multi_cell()`](fpdf/fpdf.html#fpdf.fpdf.FPDF.multi_cell) methods | ||||||||||||||||||||||
in order to enable basic Markdown-like styling: `**bold**, __italics__, --underlined--`. | ||||||||||||||||||||||
|
||||||||||||||||||||||
If your text contains Markdown-like styling that you don't want to apply, you can escape it using `\`. The escape character works the same way it generally does in Python (see the example below). | ||||||||||||||||||||||
|
||||||||||||||||||||||
Bold & italics require using dedicated fonts for each style. | ||||||||||||||||||||||
|
||||||||||||||||||||||
For the standard fonts (Courier, Helvetica & Times), those dedicated fonts are configured by default: | ||||||||||||||||||||||
|
||||||||||||||||||||||
```python | ||||||||||||||||||||||
from fpdf import FPDF | ||||||||||||||||||||||
|
||||||||||||||||||||||
pdf = fpdf.FPDF() | ||||||||||||||||||||||
pdf = FPDF() | ||||||||||||||||||||||
pdf.add_page() | ||||||||||||||||||||||
pdf.set_font("Times", size=60) | ||||||||||||||||||||||
pdf.set_font("Times", size=30) | ||||||||||||||||||||||
pdf.cell(text="**Lorem** __Ipsum__ --dolor--", markdown=True) | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed it accordingly: Lines 190 to 199 in 56d0f2c
|
||||||||||||||||||||||
pdf.cell(text="\\**Lorem\\** \\\\__Ipsum\\\\__ --dolor--", markdown=True) | ||||||||||||||||||||||
pdf.output("markdown-styled.pdf") | ||||||||||||||||||||||
``` | ||||||||||||||||||||||
|
||||||||||||||||||||||
![](markdown-style.png) | ||||||||||||||||||||||
|
||||||||||||||||||||||
Using other fonts means that their variants (bold, italics) | ||||||||||||||||||||||
must be registered using `add_font` with `style="B"` and `style="I"`. | ||||||||||||||||||||||
Several unit tests in `test/text/` demonstrate that: | ||||||||||||||||||||||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This phrasing seems a bit confusing to me.
Maybe something like this: "If the printable text contains a character sequence that would be incorrectly interpreted as a formatting marker" ?
It's not really easy to describe, but we should be as precise as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rephrased it accordingly:
fpdf2/docs/TextStyling.md
Lines 183 to 185 in 56d0f2c