Visitar URL original
Add Markdown renderer as superfences formatter · Python-Markdown/markdown@0d6afd1 · GitHub
Skip to content

Commit 0d6afd1

Browse files
authored
Add Markdown renderer as superfences formatter
If a code block is demonstrating Markdown syntax, if can be assigned the md-render attribute, and both the Markdown source and HTML output will be rendered in a nested set of code blocks. The Documentation Style Guide was updated for this and various other changes related to the switch to Zensical.
1 parent 175fb5a commit 0d6afd1

21 files changed

Lines changed: 503 additions & 487 deletions

‎.github/pull_request_template.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
- [ ] This PR follows the [contribution guidelines](https://python-markdown.github.io/contributing/).
1111
- [ ] The code follows the [Code Style Guide](https://python-markdown.github.io/contributing/#code-style-guide).
1212
- [ ] The commit message follows the [Commit Message Style Guide](https://python-markdown.github.io/contributing/#commit-message-style-guide).
13-
- [ ] I have added or updated relevant docs, including release notes if applicable which follow the [Documentation Style Guide](Documentation Style Guide).
13+
- [ ] I have added or updated relevant docs, including release notes if applicable which follow the [Documentation Style Guide](https://python-markdown.github.io/contributing/#documentation-style-guide).
1414
- [ ] I have added or updated relevant tests.
1515
- [ ] I have not requested, and will not request, an automated AI review for this PR. <!-- You are welcome to do so in your own fork. -->

‎MANIFEST.in‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ include LICENSE.md
66
include README.md
77
include INSTALL.md
88
include MANIFEST
9-
include *-requirements.txt
109
include mkdocs.yml
1110
include tox.ini
12-
include scripts/*.py
11+
recursive-include .zensical *.jinja *.py *.ico *.png *.svg *.css *.html
12+
include tools/*.py

‎docs/contributing.md‎

Lines changed: 134 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,12 @@ want to use your editor's tools to automatically hard wrap lines of text.
214214
Don't use abbreviations such as 'e.g.' but instead use the long form, such as
215215
'For example'.
216216

217-
The documentation is built from the [Markdown] source files in the [`docs`
218-
directory][docs directory] by the [MkDocs] static site generator. In addition to
219-
the basic Markdown syntax, the following extensions are supported: [extra],
220-
[admonition], [smarty], [codehilite], and [toc].
217+
The documentation is built from the [Markdown] source files in the
218+
[`docs` directory][docs directory] by the [Zensical] static site generator.
219+
In addition to the basic Markdown syntax, the following extensions are
220+
supported: [abbr], [admonition], [attr_list], [def_list], [footnotes],
221+
[md_in_html], [smarty], [toc], [mdx_gh_links], [pymdownx.highlight], and
222+
[pymdownx.superfences].
221223

222224
There are a few conventions you should follow when working on the
223225
documentation.
@@ -226,13 +228,13 @@ documentation.
226228

227229
Headers should use the hash style. For example:
228230

229-
```md
231+
``` markdown
230232
## Some important topic
231233
```
232234

233235
The underline style should not be used. Don't do this:
234236

235-
```md
237+
``` markdown
236238
Some important topic
237239
====================
238240
```
@@ -242,12 +244,12 @@ Some important topic
242244
Links should always use the reference style, with the referenced hyperlinks kept
243245
at the end of the document.
244246

245-
```md
246-
Here is a link to [some other thing][other-thing].
247+
``` markdown
248+
Here is a link to [some other thing].
247249

248250
More text...
249251

250-
[other-thing]: http://example.com/other/thing
252+
[some other thing]: http://example.com/other/thing
251253
```
252254

253255
This style helps keep the documentation source consistent and readable.
@@ -257,26 +259,135 @@ you should use a relative link, and link to the `.md` suffix. If applicable, it
257259
is preferred that the link includes a hash fragment pointing to the specific
258260
section of the page. For example:
259261

260-
```md
261-
[authentication]: reference.md#Markdown
262+
``` markdown
263+
[authentication]: somepage.md#auth
262264
```
263265

264266
Linking in this style ensures that the links work when browsing the
265267
documentation on GitHub. If your Markdown editor makes links clickable, they
266268
will work there as well. When the documentation is built, these links will be
267269
converted into regular links which point to the built HTML pages.
268270

271+
When linking to the objects in the [API documentation], simply use a reference
272+
to the dot path of the Python object. There is no need to define the
273+
reference as it is already predefined in a collection of global link
274+
references.
275+
276+
``` markdown
277+
[`markdown.Markdown`][markdown.Markdown]
278+
```
279+
280+
Note that as the link label contains code, it should be wrapped in a code span
281+
and the reference needs to be defined immediately after. This also allows a
282+
long dot path to be truncated for simplicity in the text.
283+
284+
``` markdown
285+
[`someobject`][long.dot.path.to.someobject]
286+
```
287+
269288
#### Notes and Warnings
270289

271290
If you want to draw attention to a note or warning, use the syntax defined in
272291
Python-Markdown's [Admonition Extension]:
273292

274-
```md
293+
``` markdown
275294
!!! note
276295

277296
This is the content of the note.
278297
```
279298

299+
In addition to the [supported types] listed in Zensical's documentation, the
300+
`seealso` type is supported.
301+
302+
``` markdown
303+
!!! seealso "See Also"
304+
305+
This should link to some relevant content contained elsewhere.
306+
```
307+
308+
Unlike the other defined types, `seealso` needs the title to be manually
309+
defined as the default behavior will not split a generated title into two
310+
words.
311+
312+
!!! seealso "See Also"
313+
314+
See Zensical's documentation on [supported types] for more information.
315+
316+
#### Code Blocks
317+
318+
All code blocks should use the fenced code block style. If a code block is
319+
demonstrating Markdown syntax, if can be assigned the `md-render` attribute,
320+
and both the Markdown source and HTML output will be rendered in a nested set
321+
of code blocks.
322+
323+
```` markdown
324+
``` md-render
325+
Some *Markdown* text.
326+
```
327+
````
328+
329+
The above code block will be rendered at follows:
330+
331+
``` md-render
332+
Some *Markdown* text.
333+
```
334+
335+
The rendered output is generated by an isolated Markdown instance, which is
336+
separate from the body text of the document. Extensions and configuration
337+
options are not carried over. If extension(s) need to be enabled for the code
338+
block, then they can be defined as YAML front-matter within the code block.
339+
The `extensions` and `extension_configs` keywords are the only options which
340+
are passed on to the isolated Markdown instance.The YAML front-matter is
341+
stripped from the body of the code block before the code block is passing to
342+
the isolated Markdown instance.
343+
344+
```` markdown
345+
``` md-render
346+
---
347+
extensions: [toc]
348+
extension_configs:
349+
toc:
350+
permalinks: true
351+
---
352+
# A Markdown header
353+
```
354+
````
355+
356+
The above code block would be rendered with the `toc` extension and that
357+
extension's `permalinks` option enabled as follows:
358+
359+
``` md-render
360+
---
361+
extensions: [toc]
362+
extension_configs:
363+
toc:
364+
permalink: true
365+
---
366+
# A Markdown header
367+
```
368+
369+
Note that the YAML front-matter must be deliminated by a line of at least three
370+
hyphens (both before and after) and be valid YAML. Any invalid formatting or
371+
unknown keywords will cause the entire block to not be recognized as a code
372+
block. Therefore, be sure to confirm the formatting before submitting
373+
proposed changes which utilize rendered code blocks.
374+
375+
If a Markdown code block should not receive the special rendering described
376+
above, then simply assign it the `markdown` attribute. It will then be
377+
rendered as a normal Markdown code block.
378+
379+
```` markdown
380+
``` markdown
381+
Some *Markdown* text.
382+
```
383+
````
384+
385+
The above code block would render as follows:
386+
387+
``` markdown
388+
Some *Markdown* text.
389+
```
390+
280391
#### Changelog
281392

282393
Any commit/pull request which changes the behavior of the Markdown library in
@@ -622,13 +733,21 @@ for details.
622733
[Flake8]: http://flake8.pycqa.org/en/latest/index.html
623734
[Markdown]: https://daringfireball.net/projects/markdown/basics
624735
[docs directory]: https://github.com/Python-Markdown/markdown/tree/master/docs
625-
[MkDocs]: https://www.mkdocs.org/
626-
[extra]: extensions/extra.md
736+
[Zensical]: https://zensical.org/
737+
[abbr]: extensions/abbreviations.md
627738
[admonition]: extensions/admonition.md
739+
[attr_list]: extensions/attr_list.md
740+
[def_list]: extensions/definition_lists.md
741+
[footnotes]: extensions/footnotes.md
742+
[md_in_html]: extensions/md_in_html.md
628743
[smarty]: extensions/smarty.md
629-
[codehilite]: extensions/code_hilite.md
630744
[toc]: extensions/toc.md
745+
[mdx_gh_links]: https://github.com/Python-Markdown/github-links
746+
[pymdownx.highlight]: https://facelessuser.github.io/pymdown-extensions/extensions/highlight/
747+
[pymdownx.superfences]: https://facelessuser.github.io/pymdown-extensions/extensions/superfences/
748+
[API documentation]:reference/markdown.md
631749
[Admonition Extension]: extensions/admonition.md#syntax
750+
[supported types]: https://zensical.org/docs/authoring/admonitions/#supported-types
632751
[fork]: https://help.github.com/articles/about-forks
633752
[cloning your fork]: https://help.github.com/articles/cloning-a-repository/
634753
[configure a remote]: https://help.github.com/articles/configuring-a-remote-for-a-fork

‎docs/extensions/abbreviations.md‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,19 @@ Abbreviations are defined using the syntax established in
3434

3535
[php]: http://www.michelf.com/projects/php-markdown/extra/#abbr
3636

37-
Thus, the following text (taken from the above referenced PHP documentation):
37+
For example, consider the following text (taken from the above referenced PHP documentation).
3838

39-
```md
39+
``` md-render
40+
---
41+
extensions: [abbr]
42+
---
4043
The HTML specification
4144
is maintained by the W3C.
4245
4346
*[HTML]: Hyper Text Markup Language
4447
*[W3C]: World Wide Web Consortium
4548
```
4649

47-
will be rendered as:
48-
49-
```html
50-
<p>The <abbr title="Hyper Text Markup Language">HTML</abbr> specification
51-
is maintained by the <abbr title="World Wide Web Consortium">W3C</abbr>.</p>
52-
```
53-
5450
The backslash (`\`) is not permitted in an abbreviation. Any abbreviation
5551
definitions which include one or more backslashes between the square brackets
5652
will not be recognized as an abbreviation definition.
@@ -78,7 +74,14 @@ Disabling Abbreviations
7874
When using the `glossary` option, there may be times when you need to turn off
7975
a specific abbreviation. To do this, set the abbreviation to `''` or `""`.
8076

81-
```md
77+
``` md-render
78+
---
79+
extensions: [abbr]
80+
extension_configs:
81+
abbr:
82+
glossary:
83+
HTML: Hyper Text Markup Language
84+
---
8285
The HTML abbreviation is disabled on this page.
8386
8487
*[HTML]: ''

‎docs/extensions/admonition.md‎

Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -35,78 +35,58 @@ Syntax
3535

3636
Admonitions are created using the following syntax:
3737

38-
```md
38+
``` md-render
39+
---
40+
extensions: [admonition]
41+
---
3942
!!! type "optional explicit title within double quotes"
4043
Any number of other indented markdown elements.
4144
4245
This is the second paragraph.
4346
```
4447

4548
`type` will be used as the CSS class name and as default title. It must be a
46-
single word. So, for instance:
49+
single word.
4750

48-
```md
51+
``` md-render
52+
---
53+
extensions: [admonition]
54+
---
4955
!!! note
5056
You should note that the title will be automatically capitalized.
5157
```
5258

53-
will render:
54-
55-
```html
56-
<div class="admonition note">
57-
<p class="admonition-title">Note</p>
58-
<p>You should note that the title will be automatically capitalized.</p>
59-
</div>
60-
```
59+
Optionally, you can use custom titles.
6160

62-
Optionally, you can use custom titles. For instance:
63-
64-
```md
61+
``` md-render
62+
---
63+
extensions: [admonition]
64+
---
6565
!!! danger "Don't try this at home"
6666
...
6767
```
6868

69-
will render:
70-
71-
```html
72-
<div class="admonition danger">
73-
<p class="admonition-title">Don't try this at home</p>
74-
<p>...</p>
75-
</div>
76-
```
77-
78-
If you don't want a title, use a blank string `""`:
69+
If you don't want a title, use a blank string `""`.
7970

80-
```md
71+
``` md-render
72+
---
73+
extensions: [admonition]
74+
---
8175
!!! important ""
8276
This is an admonition box without a title.
8377
```
8478

85-
results in:
86-
87-
```html
88-
<div class="admonition important">
89-
<p>This is an admonition box without a title.</p>
90-
</div>
91-
```
92-
9379
You can also provide additional CSS class names separated by spaces. The first
94-
class should be the "type." For example:
80+
class should be the "type."
9581

96-
```md
82+
``` md-render
83+
---
84+
extensions: [admonition]
85+
---
9786
!!! danger highlight blink "Don't try this at home"
9887
...
9988
```
10089

101-
will render:
102-
103-
```html
104-
<div class="admonition danger highlight blink">
105-
<p class="admonition-title">Don't try this at home</p>
106-
<p>...</p>
107-
</div>
108-
```
109-
11090
rST suggests the following "types": `attention`, `caution`, `danger`, `error`,
11191
`hint`, `important`, `note`, `tip`, and `warning`; however, you're free to use
11292
whatever you want.

0 commit comments

Comments
 (0)