Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit e11a155

Browse files
committed
Code exampeles in extension docs now show best practices.
This is in anticipation of Python-Markdown#335. The reference and extension api docs still need to be updated, but that will happen with change in the code.
1 parent 8aa89a3 commit e11a155

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

docs/extensions/header_id.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ The following options are provided to configure the output:
5555
>>> text = '''
5656
... #Some Header
5757
... ## Next Level'''
58-
>>> html = markdown.markdown(text, extensions=['headerid(level=3)'])
58+
>>> from markdown.extensions.headerid import HeaderIdExtension
59+
>>> html = markdown.markdown(text, extensions=[HeaderIdExtension(level=3)])
5960
>>> print html
6061
<h3 id="some_header">Some Header</h3>
6162
<h4 id="next_level">Next Level</h4>'
@@ -72,7 +73,7 @@ The following options are provided to configure the output:
7273
... # Some Header
7374
... # Header with ID # { #foo }'''
7475
>>> html = markdown.markdown(text,
75-
extensions=['attr_list', 'headerid(forceid=False)'])
76+
extensions=['attr_list', HeaderIdExtension(forceid=False)])
7677
>>> print html
7778
<h1>Some Header</h1>
7879
<h1 id="foo">Header with ID</h1>

docs/extensions/wikilinks.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ The following options are provided to change the default behavior:
7777
For an example, let us suppose links should always point to the subdirectory
7878
`/wiki/` and end with `.html`
7979

80-
>>> html = markdown.markdown(text,
81-
... ['markdown.extensions.wikilinks(base_url=/wiki/,end_url=.html)']
80+
>>> from markdown.extensions.wikilinks import WikiLinkExtension
81+
>>> html = markdown.markdown(text,
82+
... extensions=[WikiLinkExtension(base_url='/wiki/', end_url='.html')]
8283
... )
8384

8485
The above would result in the following link for `[[WikiLink]]`.
@@ -89,19 +90,18 @@ If you want to do more that just alter the base and/or end of the URL, you
8990
could also pass in a callable which must accept three arguments (``label``,
9091
``base``, and ``end``). The callable must return the URL in it's entirety.
9192

92-
def my_url_builder(label, base, end):
93-
# do stuff
94-
return url
95-
96-
md = markdown.Markdown(
97-
extensions=['markdown.extensions.wikilinks],
98-
extension_configs={'markdown.extensions.wikilinks' : [('build_url', my_url_builder)]}
99-
)
93+
>>> def my_url_builder(label, base, end):
94+
... # do stuff
95+
... return url
96+
...
97+
>>> html = markdown.markdown(text,
98+
... extensions=[WikiLinkExtension(build_url=my_url_builder)],
99+
... )
100100

101101
The option is also provided to change or remove the class attribute.
102102

103103
>>> html = markdown.markdown(text,
104-
... ['markdown.extensions.wikilinks(html_class=myclass)']
104+
... extensions=[WikiLinkExtension(html_class='myclass')]
105105
... )
106106

107107
Would cause all wikilinks to be assigned to the class `myclass`.

0 commit comments

Comments
 (0)