How can you create dynamic headings with code using Python? #11201
Answered
by
mcanouil
SamEdwardes
asked this question in
Q&A
-
DescriptionBackgroundI am trying to dynamically create markdown based on data that I am processing in Python. It is mostly working, except the headings that I generate do not show up in the table of contents. Is it possible to get them to appear in the TOC? A few things to consider:
ReprexTake the following document: ---
title: "Reprex"
format:
html:
toc: true
toc-depth: 6
---
```{python}
from IPython.display import Markdown
```
## heading 2.1
## heading 3.1
```{python}
headings = [
"### Heading 3.2",
"### Heading 3.3",
"## Heading 4.1",
"### Heading 4.2",
]
for i in headings:
display(Markdown(i))
```
`{python} Markdown("## Heading 5.1")`
`{python} Markdown("### Heading 5.2")`
`{python} Markdown("### Heading 5.3")` System info
|
Beta Was this translation helpful? Give feedback.
Answered by
mcanouil
Oct 26, 2024
Replies: 1 comment 2 replies
-
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
SamEdwardes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use
output: asis
when usingdisplay()
.