| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5b0c451 commit 36f8b82
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -184,9 +184,9 @@ function linkJsTypeDocs(text) { | |||
| 184 | 184 | return parts.join('`'); | |
| 185 | 185 | } | |
| 186 | 186 | ||
| 187 | - // Preprocess stability blockquotes and YAML blocks | ||
| 187 | + // Preprocess headers, stability blockquotes, and YAML blocks. | ||
| 188 | 188 | function preprocessElements({ filename }) { | |
| 189 | - return (tree) => { | ||
| 189 | + return (tree, file) => { | ||
| 190 | 190 | const STABILITY_RE = /(.*:)\s*(\d)([\s\S]*)/; | |
| 191 | 191 | let headingIndex = -1; | |
| 192 | 192 | let heading = null; | |
@@ -196,6 +196,22 @@ function preprocessElements({ filename }) { | |||
| 196 | 196 | headingIndex = index; | |
| 197 | 197 | heading = node; | |
| 198 | 198 | ||
| 199 | + // Ensure optional API parameters are not treated as links by | ||
| 200 | + // collapsing all of heading into a single text node. | ||
| 201 | + if (heading.children.length > 1) { | ||
| 202 | + const position = { | ||
| 203 | + start: heading.children[0].position.start, | ||
| 204 | + end: heading.position.end | ||
| 205 | + }; | ||
| 206 | + | ||
| 207 | + heading.children = [{ | ||
| 208 | + type: 'text', | ||
| 209 | + value: file.contents.slice( | ||
| 210 | + position.start.offset, position.end.offset), | ||
| 211 | + position | ||
| 212 | + }]; | ||
| 213 | + } | ||
| 214 | + | ||
| 199 | 215 | } else if (node.type === 'html' && common.isYAMLBlock(node.value)) { | |
| 200 | 216 | node.value = parseYAML(node.value); | |
| 201 | 217 | ||
@@ -340,10 +356,9 @@ function buildToc({ filename }) { | |||
| 340 | 356 | ||
| 341 | 357 | depth = node.depth; | |
| 342 | 358 | const realFilename = path.basename(realFilenames[0], '.md'); | |
| 343 | - const headingText = node.children.map((child) => | ||
| 344 | - file.contents.slice(child.position.start.offset, | ||
| 345 | - child.position.end.offset) | ||
| 346 | - ).join('').trim(); | ||
| 359 | + const headingText = file.contents.slice( | ||
| 360 | + node.children[0].position.start.offset, | ||
| 361 | + node.position.end.offset).trim(); | ||
| 347 | 362 | const id = getId(`${realFilename}_${headingText}`, idCounters); | |
| 348 | 363 | ||
| 349 | 364 | const hasStability = node.stability !== undefined; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments