This returns an object representing the structure of the markdown document according to its headings.
- The object’s keys will be the document’s headings in order.
- The object’s values will be the text of those sections or, if the section has its own headings, a subobject for that portion of the document.
- For a given section that has subheadings, any text that appears before the first subheading is included in an initial
_textproperty for that section.
Example: Suppose the markdown document headings.md contains various headings:
# Section 1
Introduction for section 1
## Section 1.1
Text of section 1.1.
## Section 1.2
Text of section 1.2.
# Section 2
## Section 2.1
Introduction for section 2.1
### Section 2.1.1
Text of section 2.1.1.
The outline of this document looks like:
$ ori Origami.mdOutline headings.md
Section 1:
_text: Introduction for section 1
Section 1.1: Text of section 1.1.
Section 1.2: Text of section 1.2.
Section 2:
Section 2.1:
_text: Introduction for section 2.1
Section 2.1.1: Text of section 2.1.1.
A common use for an outline is to render the outline’s keys as navigation links. For example, the following template converts an outline to a list of links for all the headings:
// Given an outline, return navigation links. If a given heading has
// subheadings, this template calls itself recursively.
(outline) => Tree.indent`
<ul>
${ Tree.map(outline, (content, heading) =>
heading === "_text"
? ""
: Tree.indent`
<li>
<a href="#${ Origami.slug(heading) }">${ heading }</a>
</li>
${ Tree.isMaplike(content) ? headings.ori(content) : "" }
`
) }
</ul>
`
Applying this to the outline:
$ ori headings.ori Origami.mdOutline headings.md
<ul>
<li>
<a href="#section-1">Section 1</a>
</li>
<ul>
<li>
<a href="#section-1.1">Section 1.1</a>
</li>
<li>
<a href="#section-1.2">Section 1.2</a>
</li>
</ul>
<li>
<a href="#section-2">Section 2</a>
</li>
<ul>
<li>
<a href="#section-2.1">Section 2.1</a>
</li>
<ul>
<li>
<a href="#section-2.1.1">Section 2.1.1</a>
</li>
</ul>
</ul>
</ul>
See also Origami.mdHtml for translating a markdown document to HTML.