| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b51651c commit eb6ea85
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,25 +60,25 @@ function toHTML({ input, filename, nodeVersion, versions }) { | |||
| 60 | 60 | const testData = [ | |
| 61 | 61 | { | |
| 62 | 62 | file: fixtures.path('order_of_end_tags_5873.md'), | |
| 63 | - html: '<h3>Static method: Buffer.from(array) <span> ' + | ||
| 63 | + html: '<h4>Static method: Buffer.from(array) <span> ' + | ||
| 64 | 64 | '<a class="mark" href="#foo_static_method_buffer_from_array" ' + | |
| 65 | - 'id="foo_static_method_buffer_from_array">#</a> </span> </h3>' + | ||
| 65 | + 'id="foo_static_method_buffer_from_array">#</a> </span> </h4>' + | ||
| 66 | 66 | '<ul><li><code>array</code><a ' + | |
| 67 | 67 | 'href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/' + | |
| 68 | 68 | 'Reference/Global_Objects/Array" class="type"><Array></a></li></ul>' | |
| 69 | 69 | }, | |
| 70 | 70 | { | |
| 71 | 71 | file: fixtures.path('doc_with_yaml.md'), | |
| 72 | - html: '<h1>Sample Markdown with YAML info' + | ||
| 72 | + html: '<h2>Sample Markdown with YAML info' + | ||
| 73 | 73 | '<span><a class="mark" href="#foo_sample_markdown_with_yaml_info" ' + | |
| 74 | - ' id="foo_sample_markdown_with_yaml_info">#</a></span></h1>' + | ||
| 75 | - '<section><h2>Foobar<span><a class="mark" href="#foo_foobar" ' + | ||
| 76 | - 'id="foo_foobar">#</a></span></h2>' + | ||
| 74 | + ' id="foo_sample_markdown_with_yaml_info">#</a></span></h2>' + | ||
| 75 | + '<section><h3>Foobar<span><a class="mark" href="#foo_foobar" ' + | ||
| 76 | + 'id="foo_foobar">#</a></span></h3>' + | ||
| 77 | 77 | '<div class="api_metadata"><span>Added in: v1.0.0</span></div> ' + | |
| 78 | 78 | '<p>Describe <code>Foobar</code> in more detail here.</p>' + | |
| 79 | 79 | '</section><section>' + | |
| 80 | - '<h2>Foobar II<span><a class="mark" href="#foo_foobar_ii" ' + | ||
| 81 | - 'id="foo_foobar_ii">#</a></span></h2><div class="api_metadata">' + | ||
| 80 | + '<h3>Foobar II<span><a class="mark" href="#foo_foobar_ii" ' + | ||
| 81 | + 'id="foo_foobar_ii">#</a></span></h3><div class="api_metadata">' + | ||
| 82 | 82 | '<details class="changelog"><summary>History</summary>' + | |
| 83 | 83 | '<table><tbody><tr><th>Version</th><th>Changes</th></tr>' + | |
| 84 | 84 | '<tr><td>v5.3.0, v4.2.0</td>' + | |
@@ -88,15 +88,15 @@ const testData = [ | |||
| 88 | 88 | '<p>Describe <code>Foobar II</code> in more detail here.' + | |
| 89 | 89 | '<a href="http://man7.org/linux/man-pages/man1/fg.1.html"><code>fg(1)' + | |
| 90 | 90 | '</code></a></p></section><section>' + | |
| 91 | - '<h2>Deprecated thingy<span><a class="mark" ' + | ||
| 91 | + '<h3>Deprecated thingy<span><a class="mark" ' + | ||
| 92 | 92 | 'href="#foo_deprecated_thingy" id="foo_deprecated_thingy">#</a>' + | |
| 93 | - '</span></h2><div class="api_metadata"><span>Added in: v1.0.0</span>' + | ||
| 93 | + '</span></h3><div class="api_metadata"><span>Added in: v1.0.0</span>' + | ||
| 94 | 94 | '<span>Deprecated since: v2.0.0</span></div><p>Describe ' + | |
| 95 | 95 | '<code>Deprecated thingy</code> in more detail here.' + | |
| 96 | 96 | '<a href="http://man7.org/linux/man-pages/man1/fg.1p.html"><code>fg(1p)' + | |
| 97 | 97 | '</code></a></p></section><section>' + | |
| 98 | - '<h2>Something<span><a class="mark" href="#foo_something' + | ||
| 99 | - '" id="foo_something">#</a></span></h2> ' + | ||
| 98 | + '<h3>Something<span><a class="mark" href="#foo_something' + | ||
| 99 | + '" id="foo_something">#</a></span></h3> ' + | ||
| 100 | 100 | '<!-- This is not a metadata comment --> ' + | |
| 101 | 101 | '<p>Describe <code>Something</code> in more detail here. </p></section>' | |
| 102 | 102 | }, | |
@@ -111,19 +111,19 @@ const testData = [ | |||
| 111 | 111 | }, | |
| 112 | 112 | { | |
| 113 | 113 | file: fixtures.path('document_with_links.md'), | |
| 114 | - html: '<h1>Usage and Example<span><a class="mark"' + | ||
| 114 | + html: '<h2>Usage and Example<span><a class="mark"' + | ||
| 115 | 115 | 'href="#foo_usage_and_example" id="foo_usage_and_example">#</a>' + | |
| 116 | - '</span></h1><section><h2>Usage<span><a class="mark" href="#foo_usage"' + | ||
| 117 | - 'id="foo_usage">#</a></span></h2><p><code>node \\[options\\] index.js' + | ||
| 116 | + '</span></h2><section><h3>Usage<span><a class="mark" href="#foo_usage"' + | ||
| 117 | + 'id="foo_usage">#</a></span></h3><p><code>node \\[options\\] index.js' + | ||
| 118 | 118 | '</code></p><p>Please see the<a href="cli.html#cli-options">' + | |
| 119 | 119 | 'Command Line Options</a>document for more information.</p>' + | |
| 120 | - '</section><section><h2>' + | ||
| 120 | + '</section><section><h3>' + | ||
| 121 | 121 | 'Example<span><a class="mark" href="#foo_example" id="foo_example">' + | |
| 122 | - '#</a></span></h2><p>An example of a<a href="example.html">' + | ||
| 122 | + '#</a></span></h3><p>An example of a<a href="example.html">' + | ||
| 123 | 123 | 'webserver</a>written with Node.js which responds with<code>' + | |
| 124 | 124 | '\'Hello, World!\'</code>:</p></section><section>' + | |
| 125 | - '<h2>See also<span><a class="mark"' + | ||
| 126 | - 'href="#foo_see_also" id="foo_see_also">#</a></span></h2><p>Check' + | ||
| 125 | + '<h3>See also<span><a class="mark"' + | ||
| 126 | + 'href="#foo_see_also" id="foo_see_also">#</a></span></h3><p>Check' + | ||
| 127 | 127 | 'out also<a href="https://nodejs.org/">this guide</a></p></section>' | |
| 128 | 128 | }, | |
| 129 | 129 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -66,10 +66,19 @@ const gtocHTML = unified() | |||
| 66 | 66 | const templatePath = path.join(docPath, 'template.html'); | |
| 67 | 67 | const template = fs.readFileSync(templatePath, 'utf8'); | |
| 68 | 68 | ||
| 69 | - function wrapSections(content) { | ||
| 69 | + function processContent(content) { | ||
| 70 | + content = content.toString(); | ||
| 71 | + // Increment header tag levels to avoid multiple h1 tags in a doc. | ||
| 72 | + // This means we can't already have an <h6>. | ||
| 73 | + if (content.includes('<h6>')) { | ||
| 74 | + throw new Error('Cannot increment a level 6 header'); | ||
| 75 | + } | ||
| 76 | + // `++level` to convert the string to a number and increment it. | ||
| 77 | + content = content.replace(/(?<=<\/?h)[1-5](?=[^<>]*>)/g, (level) => ++level); | ||
| 78 | + // Wrap h3 tags in section tags. | ||
| 70 | 79 | let firstTime = true; | |
| 71 | - return content.toString() | ||
| 72 | - .replace(/<h2/g, (heading) => { | ||
| 80 | + return content | ||
| 81 | + .replace(/<h3/g, (heading) => { | ||
| 73 | 82 | if (firstTime) { | |
| 74 | 83 | firstTime = false; | |
| 75 | 84 | return '<section>' + heading; | |
@@ -91,7 +100,7 @@ function toHTML({ input, content, filename, nodeVersion, versions }) { | |||
| 91 | 100 | .replace('__GTOC__', gtocHTML.replace( | |
| 92 | 101 | `class="nav-${id}"`, `class="nav-${id} active"`)) | |
| 93 | 102 | .replace('__EDIT_ON_GITHUB__', editOnGitHub(filename)) | |
| 94 | - .replace('__CONTENT__', wrapSections(content)); | ||
| 103 | + .replace('__CONTENT__', processContent(content)); | ||
| 95 | 104 | ||
| 96 | 105 | const docCreated = input.match( | |
| 97 | 106 | /<!--\s*introduced_in\s*=\s*v([0-9]+)\.([0-9]+)\.[0-9]+\s*-->/); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments