-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add id attributes to heading elements
This changes the generated HTML to include `id` attributes on any heading (e.g. `h3`) elements. Currently, `bit-docs-html-toc` will add `id` attributes when it parses the content and creates the TOC links. This means that JS has to be downloaded, parsed, and run before `bit-docs-html-toc` runs its code, and _then_ there has to be more JS to scroll down to the right fragment. This takes JS completely out of the equation by including the `id` attributes in the source HTML, so JS doesn’t need to load and `bit-docs-html-toc` isn’t required to make fragment URLs work either. Part of https://bitovi.atlassian.net/browse/LD-203
- Loading branch information
1 parent
3fa4d7c
commit a8c428c
Showing
3 changed files
with
28 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var assert = require('assert'); | ||
|
||
var stmd = require("./stmd"); | ||
|
||
describe("bit-docs-generate-html/stmd", function () { | ||
it("adds id attributes to heading elements", function () { | ||
var parser = new stmd.DocParser(); | ||
var renderer = new stmd.HtmlRenderer(); | ||
var markdown = "# Hello world" | ||
var rendered = renderer.render(parser.parse(markdown)); | ||
var expected = '<h1 id="hello-world">Hello world</h1>'; | ||
assert.equal(rendered.trim(), expected, "id attributes are present"); | ||
}); | ||
}); |