Skip to content

Commit 2ae4675

Browse files
committed
document headings
1 parent 3e1790f commit 2ae4675

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/format/frontmatter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ const make_slug = make_session_slug_processor({
1212
separator: "-",
1313
});
1414

15+
/**
16+
* Parse the frontmatter contained with markdown files. This frontmatter is available on the
17+
* `data.frontmatter` property of the returned `vFile`.
18+
*/
1519
export function parse_frontmatter(): Transformer {
1620
return function transformer(tree, vFile: custom_vfile) {
1721
visit(tree, "yaml", (node: YamlNode) => {

src/format/headings.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ const make_slug = make_session_slug_processor({
1717
separator: SLUG_SEPARATOR,
1818
});
1919

20+
/**
21+
* The documentation only allows heading level from 3 to 5 inclusive. This plugin
22+
* validates that rule is always followed.
23+
*/
2024
export function validate_headings(): Transformer {
2125
return function transformer(tree) {
2226
visit(tree, "heading", (node: Heading) => {
@@ -40,15 +44,20 @@ type Heading_with_hProps = Heading & {
4044
*
4145
* **linkify**: We must be able to link to headings. In order to this we need
4246
* to insert anchors with appropriate slugs. We also need to insert
43-
* link icons to allow people to copy paste links We do this by
47+
* link icons to allow people to copy paste links We do this by
4448
* inserting an `a` and `span` tag into every heading.
4549
*
4650
* **slugs**: slugs for heading anchors are generated based on previous headings.
4751
* This helps to prevent collisions and gives more descriptuve urls.
48-
* For example a h3 of 'hello' will have a slug of `hello` the next h4
49-
* of 'world' will have a slug of `hello-world`
50-
*
52+
* For example a `h3` of 'hello' will have a slug of `hello` the next
53+
* `h4` of 'world' will have a slug of `hello-world`
5154
*
55+
* **section data**: Sections of the docs are dictated by the document structure
56+
* `h3` -> `h4` -> `h5`, etc. This plugin keeps track of the
57+
* headings and creates a nested section structure that reflects
58+
* the hierarchy of those sections. This structure allows us to
59+
* create navigation structures with proper semantics, without
60+
* transforming the sections data structure.
5261
*
5362
*/
5463

@@ -140,6 +149,14 @@ const types = [
140149
"imageReference",
141150
];
142151

152+
/**
153+
* *Only applies to `README.md` files*.
154+
*
155+
* Svelte docs require documents to *not* contain a main title as this is provided by
156+
* other means. However, *readme* files should be easily readable exactly as
157+
* they are (in github or in an IDE). This plugin strips the leading `h1` from
158+
* `README.md` files facilitating this difference in formatting.
159+
*/
143160
export function strip_h1(): Transformer {
144161
return function transformer(tree: Root, vFile: custom_vfile) {
145162
//@ts-ignore
@@ -157,6 +174,16 @@ export function strip_h1(): Transformer {
157174
};
158175
}
159176

177+
/**
178+
* *Only applies to `README.md` files*.
179+
*
180+
* Svelte docs require headings to start at level 3 as level 1 and 2 headings are
181+
* already used for other purposes. However, *readme* files should be
182+
* easily readable exactly as they are (in github or in an IDE). This
183+
* plugin increments headings in `README.md` files facilitating this
184+
* difference in formatting.
185+
*/
186+
160187
export function increment_headings(): Transformer {
161188
return function transformer(tree, vFile) {
162189
//@ts-ignore

0 commit comments

Comments
 (0)