|
| 1 | +const { MarkdownTheme, MarkdownPageEvent } = require('typedoc-plugin-markdown') |
| 2 | + |
| 3 | +function load(app) { |
| 4 | + // Listen to the render event |
| 5 | + app.renderer.on(MarkdownPageEvent.END, (page) => { |
| 6 | + // Remove Markdown links from the document contents |
| 7 | + page.contents = removeMarkdownLinks( |
| 8 | + removeFirstNLines( |
| 9 | + convertH5toH3(removeLinesWithConditions(page.contents)), |
| 10 | + 6 |
| 11 | + ) |
| 12 | + ) |
| 13 | + }) |
| 14 | +} |
| 15 | + |
| 16 | +// this is a hacky way to make methods in the js-sdk sdk reference look more prominent |
| 17 | +function convertH5toH3(text) { |
| 18 | + return text.replace(/^##### (.*)$/gm, '### $1') |
| 19 | +} |
| 20 | + |
| 21 | +// Function to remove Markdown-style links |
| 22 | +function removeMarkdownLinks(text) { |
| 23 | + // Regular expression to match Markdown links [text](url) |
| 24 | + return text.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1') // Replace with just the link text |
| 25 | +} |
| 26 | + |
| 27 | +function removeFirstNLines(text, n, condition) { |
| 28 | + // Split the text into lines, then join back excluding the first four lines |
| 29 | + return text.split('\n').slice(n).join('\n') |
| 30 | +} |
| 31 | + |
| 32 | +// Function to remove lines based on conditions |
| 33 | +function removeLinesWithConditions(text) { |
| 34 | + const lines = text.split('\n') |
| 35 | + const filteredLines = [] |
| 36 | + |
| 37 | + for (let i = 0; i < lines.length; i++) { |
| 38 | + // Check if the current line starts with "#### Extends" or "###### Overrides" |
| 39 | + if ( |
| 40 | + lines[i].startsWith('#### Extends') || |
| 41 | + lines[i].startsWith('###### Overrides') || |
| 42 | + lines[i].startsWith('###### Inherited from') |
| 43 | + ) { |
| 44 | + // If it does, skip this line and the next three lines |
| 45 | + i += 3 // Skip this line and the next three |
| 46 | + continue |
| 47 | + } |
| 48 | + |
| 49 | + if (lines[i].startsWith('##### new')) { |
| 50 | + // avoid promoting constructors |
| 51 | + i += 1 |
| 52 | + continue |
| 53 | + } |
| 54 | + |
| 55 | + // If not removed, add the line to filteredLines |
| 56 | + filteredLines.push(convertH5toH3(lines[i])) |
| 57 | + } |
| 58 | + |
| 59 | + // Join the filtered lines back into a single string |
| 60 | + return filteredLines.join('\n') |
| 61 | +} |
| 62 | + |
| 63 | +// Export the load function |
| 64 | +module.exports = { load } |
0 commit comments