-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
450 lines (359 loc) · 18.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="The Python-Markdown Project">
<link rel="canonical" href="https://Python-Markdown.github.io/extensions/toc/">
<link rel="shortcut icon" href="../../favicon.ico">
<link rel="search" title="Search" href="../../search.html" />
<link rel="next" title="Tables" href="../tables/" />
<link rel="prev" title="SmartyPants" href="../smarty/" />
<title>Table of Contents — Python-Markdown 3.8 documentation</title>
<link rel="stylesheet" href="../../static/nature.css" type="text/css" />
<link rel="stylesheet" href="../../static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../assets/_mkdocstrings.css" type="text/css" />
<link rel="stylesheet" href="../../custom.css" type="text/css" />
<link rel="stylesheet" href="../../mkdocstrings.css" type="text/css" />
<script type="text/javascript" src="../../static/jquery.js"></script>
<script type="text/javascript" src="../../static/underscore.js"></script>
</head>
<body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="https://github.com/Python-Markdown/markdown" title="View this project on GitHub"><img src="../../static/github.png" width=16px style="vertical-align: middle; margin-top: -1px" /></a>
</li>
<li class="right" style="margin-right: 10px">
<a href="../../sitemap.html" title="Sitemap" accesskey="I">index</a>
</li>
<li class="right">
<a href="../tables/" title="Tables" accesskey="N">next</a> |
</li>
<li class="right">
<a href="../smarty/" title="SmartyPants" accesskey="P">previous</a> |
</li>
<li><img src="../../py.png"
alt="icon" style="vertical-align: middle; margin-top: -1px"/></li>
<li class="nav-item nav-item-0">
<a href="../..">Python-Markdown 3.8 documentation</a> »
</li>
<li class="nav-item">
Officially Supported Extensions
» </li>
<li class="nav-item">
<a href="./">Table of Contents</a>
» </li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main"><h1 id="table-of-contents">Table of Contents<a class="headerlink" href="#table-of-contents" title="Permanent link">¶</a></h1>
<h2 id="summary">Summary<a class="headerlink" href="#summary" title="Permanent link">¶</a></h2>
<p>The Table of Contents extension generates a Table of Contents from a Markdown
document and adds it into the resulting HTML document.</p>
<p>This extension is included in the standard Markdown library.</p>
<h2 id="syntax">Syntax<a class="headerlink" href="#syntax" title="Permanent link">¶</a></h2>
<p>By default, all headers will automatically have unique <code>id</code> attributes
generated based upon the text of the header. Note this example, in which all
three headers would have the same <code>id</code>:</p>
<pre class="codehilite"><code class="language-md">#Header
#Header
#Header
</code></pre>
<p>Results in:</p>
<pre class="codehilite"><code class="language-html"><h1 id="header">Header</h1>
<h1 id="header_1">Header</h1>
<h1 id="header_2">Header</h1>
</code></pre>
<p>Place a marker in the document where you would like the Table of Contents to
appear. Then, a nested list of all the headers in the document will replace the
marker. The marker defaults to <code>[TOC]</code> so the following document:</p>
<pre class="codehilite"><code class="language-md">[TOC]
# Header 1
## Header 2
</code></pre>
<p>would generate the following output:</p>
<pre class="codehilite"><code class="language-html"><div class="toc">
<ul>
<li>
<a href="#header-1">Header 1</a>
<ul>
<li><a href="#header-2">Header 2</a></li>
</ul>
</li>
</ul>
</div>
<h1 id="header-1">Header 1</h1>
<h2 id="header-2">Header 2</h2>
</code></pre>
<p>Regardless of whether a <code>marker</code> is found in the document (or disabled), the
Table of Contents is available as an attribute (<code>toc</code>) on the Markdown class.
This allows one to insert the Table of Contents elsewhere in their page
template. For example:</p>
<pre class="codehilite"><code class="language-pycon">>>> md = markdown.Markdown(extensions=['toc'])
>>> html = md.convert(text)
>>> page = render_some_template(context={'body': html, 'toc': md.toc})
</code></pre>
<p>The <code>toc_tokens</code> attribute is also available on the Markdown class and contains
a nested list of dict objects. For example, the above document would result in
the following object at <code>md.toc_tokens</code>:</p>
<pre class="codehilite"><code class="language-python">[
{
'level': 1,
'id': 'header-1',
'name': 'Header 1',
'html': 'Header 1',
'data-toc-label': '',
'children': [
{'level': 2, 'id': 'header-2', 'name': 'Header 2', 'children':[]}
]
}
]
</code></pre>
<p>Note that the <code>level</code> refers to the <code>hn</code> level. In other words, <code><h1></code> is level
<code>1</code> and <code><h2></code> is level <code>2</code>, etc. Be aware that improperly nested levels in the
input may result in odd nesting of the output.</p>
<p><code>name</code> is the sanitized value which would also be used as a label for the HTML
version of the Table of Contents. <code>html</code> contains the fully rendered HTML
content of the heading and has not been sanitized in any way. This may be used
with your own custom sanitation to create custom table of contents.</p>
<h3 id="custom-labels">Custom Labels<a class="headerlink" href="#custom-labels" title="Permanent link">¶</a></h3>
<p>In most cases, the text label in the Table of Contents should match the text of
the header. However, occasionally that is not desirable. In that case, if this
extension is used in conjunction with the <a href="../attr_list/">Attribute Lists Extension</a> and a
<code>data-toc-label</code> attribute is defined on the header, then the contents of that
attribute will be used as the text label for the item in the Table of Contents.
For example, the following Markdown:</p>
<pre class="codehilite"><code class="language-md">[TOC]
# Functions
## `markdown.markdown(text [, **kwargs])` { #markdown data-toc-label='markdown.markdown' }
</code></pre>
<p>would generate the following output:</p>
<pre class="codehilite"><code class="language-html"><div class="toc">
<ul>
<li>
<a href="#functions">Functions</a>
<ul>
<li><a href="#markdown">markdown.markdown</a></li>
</ul>
</li>
</ul>
</div>
<h1 id="functions">Functions</h1>
<h2 id="markdown"><code>markdown.markdown(text [, **kwargs])</code></h2>
</code></pre>
<p>Notice that the text in the Table of Contents is much cleaner and easier to read
in the context of a Table of Contents. The <code>data-toc-label</code> is not included in
the HTML header element. Also note that the ID was manually defined in the
attribute list to provide a cleaner URL when linking to the header. If the ID is
not manually defined, it is always derived from the text of the header, never
from the <code>data-toc-label</code> attribute.</p>
<p>The value of the <code>data-toc-label</code> attribute is sanitized and stripped of any HTML
tags. However, <code>toc_tokens</code> will contain the raw content under
<code>data-toc-label</code>.</p>
<h2 id="usage">Usage<a class="headerlink" href="#usage" title="Permanent link">¶</a></h2>
<p>See <a href="../">Extensions</a> for general extension usage. Use <code>toc</code> as the name
of the extension.</p>
<p>See the <a href="../../reference/#extensions">Library Reference</a> for information about
configuring extensions.</p>
<p>The following options are provided to configure the output:</p>
<ul>
<li>
<p><strong><code>marker</code></strong>:
Text to find and replace with the Table of Contents. Defaults to <code>[TOC]</code>.</p>
<p>Set to an empty string to disable searching for a marker, which may save
some time, especially on long documents.</p>
</li>
<li>
<p><strong><code>title</code></strong>:
Title to insert in the Table of Contents’ <code><div></code>. Defaults to <code>None</code>.</p>
</li>
<li>
<p><strong><code>title_class</code></strong>:
CSS class used for the title contained in the Table of Contents. Defaults to <code>toctitle</code>.</p>
</li>
<li>
<p><strong><code>toc_class</code></strong>:
CSS class(es) used for the <code><div></code> containing the Table of Contents. Defaults to <code>toc</code>.</p>
</li>
<li>
<p><strong><code>anchorlink</code></strong>:
Set to <code>True</code> to cause all headers to link to themselves. Default is <code>False</code>.</p>
</li>
<li>
<p><strong><code>anchorlink_class</code></strong>:
CSS class(es) used for the link. Defaults to <code>toclink</code>.</p>
</li>
<li>
<p><strong><code>permalink</code></strong>:
Set to <code>True</code> or a string to generate permanent links at the end of each header.
Useful with Sphinx style sheets.</p>
<p>When set to <code>True</code> the paragraph symbol (¶ or “<code>&para;</code>”) is used as
the link text. When set to a string, the provided string is used as the link
text.</p>
</li>
<li>
<p><strong><code>permalink_class</code></strong>:
CSS class(es) used for the link. Defaults to <code>headerlink</code>.</p>
</li>
<li>
<p><strong><code>permalink_title</code></strong>:
Title attribute of the permanent link. Defaults to <code>Permanent link</code>.</p>
</li>
<li>
<p><strong><code>permalink_leading</code></strong>:
Set to <code>True</code> if the extension should generate leading permanent links.
Default is <code>False</code>.</p>
<p>Leading permanent links are placed at the start of the header tag,
before any header content. The default <code>permalink</code> behavior (when
<code>permalink_leading</code> is unset or set to <code>False</code>) creates trailing
permanent links, which are placed at the end of the header content.</p>
</li>
<li>
<p><strong><code>baselevel</code></strong>:
Base level for headers. Defaults to <code>1</code>.</p>
<p>The <code>baselevel</code> setting allows the header levels to be automatically
adjusted to fit within the hierarchy of your HTML templates. For example,
suppose the Markdown text for a page should not contain any headers higher
than level 3 (<code><h3></code>). The following will accomplish that:</p>
<pre class="codehilite"><code class="language-pycon">>>> text = '''
... #Some Header
... ## Next Level'''
>>> from markdown.extensions.toc import TocExtension
>>> html = markdown.markdown(text, extensions=[TocExtension(baselevel=3)])
>>> print html
<h3 id="some_header">Some Header</h3>
<h4 id="next_level">Next Level</h4>'
</code></pre>
</li>
<li>
<p><strong><code>slugify</code></strong>:
Callable to generate anchors.</p>
<p>Default: <code>markdown.extensions.toc.slugify</code></p>
<p>In order to use a different algorithm to define the id attributes, define and
pass in a callable which takes the following two arguments:</p>
<ul>
<li><code>value</code>: The string to slugify.</li>
<li><code>separator</code>: The Word Separator.</li>
</ul>
<p>The callable must return a string appropriate for use in HTML <code>id</code> attributes.</p>
<p>An alternate version of the default callable supporting Unicode strings is also
provided as <code>markdown.extensions.toc.slugify_unicode</code>.</p>
</li>
<li>
<p><strong><code>separator</code></strong>:
Word separator. Character which replaces white space in id. Defaults to “<code>-</code>”.</p>
</li>
<li>
<p><strong><code>toc_depth</code></strong>
Define the range of section levels to include in the Table of Contents.
A single integer (<code>b</code>) defines the bottom section level (<code><h1>..<hb></code>) only.
A string consisting of two digits separated by a hyphen in between (<code>"2-5"</code>),
define the top (<code>t</code>) and the bottom (<code>b</code>) (<code><ht>..<hb></code>). Defaults to <code>6</code> (bottom).</p>
<p>When used with conjunction with <code>baselevel</code>, this parameter will not
take the fitted hierarchy from <code>baselevel</code> into account. That is, if
both <code>toc_depth</code> and <code>baselevel</code> are <code>3</code>, then only the highest level
will be present in the table. If you set <code>baselevel</code> to <code>3</code> and
<code>toc_depth</code> to <code>"2-6"</code>, the <em>first</em> headline will be <code><h3></code> and so still
included in the Table of Contents. To exclude this first level, you
have to set <code>toc_depth</code> to <code>"4-6"</code>.</p>
</li>
</ul>
<p>A trivial example:</p>
<pre class="codehilite"><code class="language-python">markdown.markdown(some_text, extensions=['toc'])
</code></pre>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li>
<a class="reference internal" href="#table-of-contents">Table of Contents</a>
<ul>
<li>
<a class="reference internal" href="#summary">Summary</a>
</li>
<li>
<a class="reference internal" href="#syntax">Syntax</a>
<ul>
<li>
<a class="reference internal" href="#custom-labels">Custom Labels</a>
</li>
</ul>
</li>
<li>
<a class="reference internal" href="#usage">Usage</a>
</li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless">
<a href="../smarty/" title="previous page">SmartyPants</a>
</p>
<h4>Next topic</h4>
<p class="topless">
<a href="../tables/" title="next page">Tables</a>
</p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="https://github.com/Python-Markdown/markdown/issues">Report a Bug</a></li>
<li><a href="https://github.com/Python-Markdown/markdown/edit/master/docs/extensions/toc.md">Edit on GitHub</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="../../search.html" method="get">
<div><input type="text" name="q" placeholder="Search docs" /></div>
<div><input type="submit" value="Go" /></div>
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="https://github.com/Python-Markdown/markdown" title="View this project on GitHub"><img src="../../static/github.png" width=16px style="vertical-align: middle; margin-top: -1px" /></a>
</li>
<li class="right" style="margin-right: 10px">
<a href="../../sitemap.html" title="Sitemap" accesskey="I">index</a>
</li>
<li class="right">
<a href="../tables/" title="Tables" accesskey="N">next</a> |
</li>
<li class="right">
<a href="../smarty/" title="SmartyPants" accesskey="P">previous</a> |
</li>
<li><img src="../../py.png"
alt="icon" style="vertical-align: middle; margin-top: -1px"/></li>
<li class="nav-item nav-item-0">
<a href="../..">Python-Markdown 3.8 documentation</a> »
</li>
<li class="nav-item">
Officially Supported Extensions
» </li>
<li class="nav-item">
<a href="./">Table of Contents</a>
» </li>
</ul>
</div>
<div class="footer" role="contentinfo">Copyright © 2010-2023, The Python-Markdown Project.
Created using <a href="https://www.mkdocs.org/">MkDocs</a> 1.6.1.
</div>
<script>var base_url = '../..';</script>
<script src="../../search/main.js"></script>
<!--
MkDocs version : 1.6.1
Docs Build Date UTC : 2025-04-09 17:38:32.505838+00:00
-->
</body>
</html>