trentm / trentm/python-markdown2
toc - Table Of Contents auto include option
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.8k
- Forks
- 459
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 4
Description
This may be related to https://github.com/trentm/python-markdown2/issues/49 which asks about usage.
I'm currently using the toc extension like this:
html_text = markdown2.markdown(plain_text, extras=['code-friendly', 'toc'])
table_of_contents_html = html_text.toc_html
html_text = str(html_text) # or maybe Unicode.... don't get hung up on this line.....
if table_of_contents_html:
# inject Table Of Contents into document
TOC_MARKER = '<!--TOC-->'
html_text = html_text.replace(TOC_MARKER, table_of_contents_html)
Basically I use <!--TOC--> as a marker in my document for where I want the table to appear, the trick is to use a marker that markdown2 won't alter (e.g. a regular word is likely to be wrapped in a p tag).
Is there any chance this sort of approach could be built into to the toc extension (or a new auto_toc extension)? Posting issue to get feedback (I can carry on using my approach above).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the toc extension and the markdown2.markdown path described in the example, tracing how toc_html and the marker are handled. Define the desired automatic insertion behavior and confirm that generated HTML places the table at the marker without requiring manual replacement.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- content
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100