Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- [pull #519] Add support for custom extras
- [pull #519] Drop Python 3.5 support
- [pull #568] Add `prepend` arg to toc extra (#397)


## python-markdown2 2.4.13
Expand Down
2 changes: 1 addition & 1 deletion lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def toc_sort(entry):
self._toc_html = calculate_toc_html(self._toc)

# Prepend toc html to output
if self.cli:
if self.cli or (self.extras['toc'] is not None and self.extras['toc'].get('prepend', False)):
text = '{}\n{}'.format(self._toc_html, text)

text += "\n"
Expand Down
40 changes: 40 additions & 0 deletions test/tm-cases/toc_prepend.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<ul>
<li><a href="#readme-for-blah">README for Blah</a>
<ul>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#the-meat">The Meat</a>
<ul>
<li><a href="#beef">Beef</a>
<ul>
<li><a href="#steak">Steak</a></li>
<li><a href="#burgers">Burgers</a></li>
</ul></li>
<li><a href="#chicken">Chicken</a></li>
<li><a href="#pork">Pork</a>
<ul>
<li><a href="#mmmmmmmm-bacon">Mmmmmmmm, bacon</a></li>
</ul></li>
</ul></li>
</ul></li>
<li><a href="#at-the-top-level-again">At the <em>top</em> level again!?</a></li>
</ul>

<h1 id="readme-for-blah">README for Blah</h1>

<h2 id="introduction">Introduction</h2>

<h2 id="the-meat">The Meat</h2>

<h3 id="beef">Beef</h3>

<h5 id="steak">Steak</h5>

<h5 id="burgers">Burgers</h5>

<h3 id="chicken">Chicken</h3>

<h3 id="pork">Pork</h3>

<h4 id="mmmmmmmm-bacon">Mmmmmmmm, bacon</h4>

<h1 id="at-the-top-level-again">At the <em>top</em> level again!?</h1>
1 change: 1 addition & 0 deletions test/tm-cases/toc_prepend.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"extras": {"toc": {"prepend": True}}}
1 change: 1 addition & 0 deletions test/tm-cases/toc_prepend.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
toc extra
20 changes: 20 additions & 0 deletions test/tm-cases/toc_prepend.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# README for Blah

## Introduction

## The Meat

### Beef

##### Steak

##### Burgers

### Chicken

### Pork

#### Mmmmmmmm, bacon

# At the *top* level again!?

20 changes: 20 additions & 0 deletions test/tm-cases/toc_prepend.toc_html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<ul>
<li><a href="#readme-for-blah">README for Blah</a>
<ul>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#the-meat">The Meat</a>
<ul>
<li><a href="#beef">Beef</a>
<ul>
<li><a href="#steak">Steak</a></li>
<li><a href="#burgers">Burgers</a></li>
</ul></li>
<li><a href="#chicken">Chicken</a></li>
<li><a href="#pork">Pork</a>
<ul>
<li><a href="#mmmmmmmm-bacon">Mmmmmmmm, bacon</a></li>
</ul></li>
</ul></li>
</ul></li>
<li><a href="#at-the-top-level-again">At the <em>top</em> level again!?</a></li>
</ul>