Skip to content

Commit 508f39d

Browse files
committed
New optional markdown=True parameter for to the cell, multi_cell & write methods ( close #108 )
that enable basic Markdown-like styling: `**bold**, __italics__, --underlined--`
1 parent 208ac1a commit 508f39d

11 files changed

+292
-98
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ and [PEP 440](https://www.python.org/dev/peps/pep-0440/).
1212
- now `fpdf2` uses the newly supported `DCTDecode` image filter for JPEG images,
1313
instead of `FlateDecode` before, in order to improve the compression ratio without any image quality loss.
1414
On test images, this reduced the size of embeded JPEG images by 90%.
15-
- `FPDF.cell`: the `w` parameter becomes optional, with a default value of `None`, meaning to generate a cell with the size of the text content provided, and the `h` default value changes, becoming `None`, meaning to get its value from the current font size
15+
- `FPDF.cell`: the `w` (width) parameter becomes optional, with a default value of `None`, meaning to generate a cell with the size of the text content provided
16+
- the `h` (height) parameter of the `cell`, `multi_cell` & `write` methods gets a default value change, `None`, meaning to use the current font size
1617
### Added
18+
- a new optional `markdown=True` parameter can be passed to the `cell`, `multi_cell` & `write` methods
19+
in order to enable basic Markdown-like styling: `**bold**, __italics__, --underlined--`
1720
- `FPDF.cell`: new optional `center` parameter to position the cell horizontally
1821
- `HTMLMixin` / `HTML2FPDF`: now support `align="justify"`
1922
- new method `FPDF.image_filter` to control the image filters used for images

docs/TextStyling.md

+16
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,19 @@ pdf.write_html("""<B>bold</B>
4141
<B><I><U>all at once!</U></I></B>"""
4242
)
4343
```
44+
45+
46+
## markdown=True ##
47+
48+
An optional `markdown=True` parameter can be passed to the `cell`, `multi_cell` & `write` methods
49+
in order to enable basic Markdown-like styling: `**bold**, __italics__, --underlined--`
50+
51+
```python
52+
from fpdf import FPDF
53+
54+
pdf = fpdf.FPDF()
55+
pdf.add_page()
56+
pdf.set_font("Times", size=60)
57+
pdf.cell(txt="**Lorem** __Ipsum__ --dolor--", markdown=True)
58+
pdf.output("markdown-styled.pdf")
59+
```

docs/reference/write.md

+5-42
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,6 @@
1-
## write ##
1+
cf. https://pyfpdf.github.io/fpdf2/fpdf/#fpdf.FPDF.write
22

3-
```python
4-
write(h: float, txt: str, link)
5-
```
6-
7-
### Description ###
8-
9-
This method prints text from the current position. When the right margin is
10-
reached (or the \n character is met), a line break occurs and text continues
11-
from the left margin. Upon method exit, the current position is left just at
12-
the end of the text.
13-
14-
It is possible to put a link on the text.
15-
16-
### Parameters ###
17-
18-
h:
19-
> Line height.
20-
21-
txt:
22-
> String to print.
23-
24-
link:
25-
> URL or identifier returned by [add_link](add_link.md).
26-
27-
### Example ###
28-
```python
29-
# Begin with regular font
30-
pdf.set_font('helvetica', '', 14)
31-
pdf.write(5, 'Visit ')
32-
# Then put a blue underlined link
33-
pdf.set_text_color(0, 0, 255)
34-
pdf.set_font('', 'U')
35-
pdf.write(5, 'pyfpdf.github.io/fpdf2/', 'https://pyfpdf.github.io/fpdf2/')
36-
```
37-
38-
### See also ###
39-
40-
[set_doc_option](set_doc_option.md), [set_font](set_font.md),
41-
[set_text_color](set_text_color.md), [add_link](add_link.md),
42-
[multi_cell](multi_cell.md), [set_auto_page_break](set_auto_page_break.md),
43-
[write_html](write_html.md)
3+
<script>
4+
// Migrating Markdown doc to docstrings - cf. https://github.com/PyFPDF/fpdf2/issues/31
5+
window.location = 'https://pyfpdf.github.io/fpdf2/fpdf/#fpdf.FPDF.write'
6+
</script>

0 commit comments

Comments
 (0)