Skip to content

Commit 7398f04

Browse files
authored
Documentation for plugins. (#94)
1 parent 77bf8c0 commit 7398f04

5 files changed

Lines changed: 177 additions & 3 deletions

File tree

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/27b53043bff34f07bfb79ee1672b7ba0)](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
77
[![PyPI - Downloads](https://img.shields.io/pypi/dm/markdown-pdf?label=pypi%20installs)](https://pypistats.org/packages/markdown-pdf)
88

9-
The free, open source Python module `markdown-pdf` will create a PDF file from your content in `markdown` format.
9+
The free, open source Python module `markdown-pdf` will create a PDF file from your `markdown` content.
1010

1111
When creating a PDF file you can:
1212

@@ -18,7 +18,7 @@ When creating a PDF file you can:
1818
- Use different page sizes within single pdf
1919
- Create tables in `markdown`
2020
- Use clickable hyperlinks. Thanks a lot [@thongtmtrust](https://github.com/thongtmtrust) for ideas and collaboration.
21-
- Use the plantuml content plugin
21+
- Render plantuml and mermaid code to pdf images with [plugins](plugins.md).
2222

2323
The module utilizes the functions of two great libraries.
2424

@@ -207,6 +207,8 @@ In the created file `plantuml.pdf`, you will see the following result:
207207

208208
![With plantuml.jpg](img/with_plantuml.jpg)
209209

210+
You can find a more detailed description of the plugins [here](plugins.md).
211+
210212
## Example
211213

212214
As an example, you can download the [pdf file](examples/markdown_pdf.pdf) created from this md file.

README_ru.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
- Использовать разные размеры страниц внутри одного pdf
1313
- Создавать таблицы в `markdown`
1414
- Использовать кликабельные гиперссылки. Спасибо [@thongtmtrust](https://github.com/thongtmtrust) за идеи и сотрудничество!
15-
- Использовать плагин для контента plantuml
15+
- Преобразоввывать plantuml и mermaid код в картинки pdf при помощи [плагинов](plugins_ru.md).
1616

1717
Модуль использует функции двух замечательных библиотек.
1818

@@ -200,6 +200,8 @@ pdf.save("plantuml.pdf")
200200

201201
![With plantuml.jpg](img/with_plantuml.jpg)
202202

203+
Вы можете ознакомиться с более подробным [описанием плагинов](plugins_ru.md).
204+
203205
## Пример
204206

205207
В качестве примера вы можете загрузить созданный из этого md файла [pdf файл](examples/markdown_pdf_ru.pdf).

history.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
+ Defaults for plantuml plugin.
55

6+
+ Documentation for plugins.
7+
68
01.02.2026 ver.1.11
79
-------------------
810

plugins.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Plugins
2+
3+
Markdown-pdf can process content marked with special code using plugins.
4+
A plugin can convert the code it's intended for into images or other content.
5+
6+
You can use the following plugins out of the box with `markdown-pdf`.
7+
8+
## plantuml
9+
10+
The `plantuml` plugin replaces given code with an image of the corresponding diagram, generated using an external server (by default, `http://www.plantuml.com`).
11+
12+
Your `markdown` document contains the following code snippet.
13+
14+
````markdown
15+
```plantuml
16+
@startuml
17+
Alice -> Bob: Hello Bob
18+
Bob --> Alice: Hi!
19+
@enduml
20+
```
21+
````
22+
23+
You can use a plugin to convert the diagram into an image.
24+
25+
```python
26+
from markdown_pdf import MarkdownPdf, Section
27+
from markdown_pdf.pligins import Plugin
28+
29+
plugins = {
30+
# use defaults
31+
Plugin.Plantuml: None
32+
# or specify your server address
33+
# Plugin.Plantuml: {'url': 'http://www.plantuml.com/plantuml/img/'}
34+
}
35+
36+
pdf = MarkdownPdf(plugins=plugins)
37+
pdf.add_section(Section(markdown_text_with_plantuml_code))
38+
pdf.save("plantuml.pdf")
39+
```
40+
41+
In the resulting PDF file, the code `plantuml` will be replaced with the following image.
42+
43+
![plantuml.png](fixture/plantuml.png)
44+
45+
## mermaid
46+
47+
The `mermaid` plugin replaces code with an image generated by an external server (`https://mermaid.ink` by default).
48+
49+
Your `markdown` document contains the following code snippet.
50+
51+
````markdown
52+
```mermaid
53+
stateDiagram-v2
54+
[*] --> Still
55+
Still --> [*]
56+
57+
Still --> Moving
58+
Moving --> Still
59+
Moving --> Crash
60+
Crash --> [*]
61+
```
62+
````
63+
64+
You can use a plugin to convert this code into an image.
65+
66+
```python
67+
from markdown_pdf import MarkdownPdf, Section
68+
from markdown_pdf.pligins import Plugin
69+
70+
plugins = {
71+
# use defaults
72+
Plugin.Mermaid: None
73+
# or specify your server address
74+
# Plugin.Mermaid: {'url': 'https://mermaid.ink/img/'}
75+
}
76+
77+
pdf = MarkdownPdf(plugins=plugins)
78+
pdf.add_section(Section(markdown_text_with_mermaid_code))
79+
pdf.save("mermaid.pdf")
80+
```
81+
82+
In the resulting PDF file, the code `mermaid` will be replaced with the following image.
83+
84+
![mermaid.png](fixture/mermaid.png)

plugins_ru.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Плагины
2+
3+
Markdown-pdf может обрабатывать помеченный специальным кодом контент при помощи плагинов.
4+
Плагин может преобразовывать предназначенный для него код в изображения или другой контент.
5+
6+
В `markdown-pdf` вы можете использовать следующие плагины "из коробки".
7+
8+
## plantuml
9+
10+
Плагин для кода `plantuml` заменяет код на картинку соответствующей схемы, создаваемую при помощи внешнего сервера (по умолчанию `http://www.plantuml.com`).
11+
12+
В вашем `markdown` документе имеется следующий фрагмент кода.
13+
14+
````markdown
15+
```plantuml
16+
@startuml
17+
Alice -> Bob: Hello Bob
18+
Bob --> Alice: Hi!
19+
@enduml
20+
```
21+
````
22+
23+
Вы можете использовать плагин для преобразования в картинку схемы.
24+
25+
```python
26+
from markdown_pdf import MarkdownPdf, Section
27+
from markdown_pdf.pligins import Plugin
28+
29+
plugins = {
30+
# использовать умолчания
31+
Plugin.Plantuml: None
32+
# или задать адрес вашего сервера
33+
# Plugin.Plantuml: {'url': 'http://www.plantuml.com/plantuml/img/'}
34+
}
35+
36+
pdf = MarkdownPdf(plugins=plugins)
37+
pdf.add_section(Section(markdown_text_with_plantuml_code))
38+
pdf.save("plantuml.pdf")
39+
```
40+
41+
В полученном pdf файле код `plantuml` будет заменен на следующую картинку.
42+
43+
![plantuml.png](fixture/plantuml.png)
44+
45+
## mermaid
46+
47+
Плагин для кода `mermaid` заменяет код на картинку, создаваемую при помощи внешнего сервера (по умолчанию `https://mermaid.ink`).
48+
49+
В вашем `markdown` документе имеется следующий фрагмент кода.
50+
51+
````markdown
52+
```mermaid
53+
stateDiagram-v2
54+
[*] --> Still
55+
Still --> [*]
56+
57+
Still --> Moving
58+
Moving --> Still
59+
Moving --> Crash
60+
Crash --> [*]
61+
```
62+
````
63+
64+
Вы можете использовать плагин для преобразования этого кода в картинку.
65+
66+
```python
67+
from markdown_pdf import MarkdownPdf, Section
68+
from markdown_pdf.pligins import Plugin
69+
70+
plugins = {
71+
# использовать умолчания
72+
Plugin.Mermaid: None
73+
# или задать адрес вашего сервера
74+
# Plugin.Mermaid: {'url': 'https://mermaid.ink/img/'}
75+
}
76+
77+
pdf = MarkdownPdf(plugins=plugins)
78+
pdf.add_section(Section(markdown_text_with_mermaid_code))
79+
pdf.save("mermaid.pdf")
80+
```
81+
82+
В полученном pdf файле код `mermaid` будет заменен на следующую картинку.
83+
84+
![mermaid.png](fixture/mermaid.png)

0 commit comments

Comments
 (0)