Created
June 29, 2022 17:43
-
-
Save aparajita/9e48f40ae7feef828a8ca3dd74d47c78 to your computer and use it in GitHub Desktop.
Reformats output from @capacitor/docgen to suit my stylistic tastes
This file contains hidden or 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
import fs from 'fs' | |
function indexFixer(match, index) { | |
// 1. Remove bullets | |
// 2. Remove code format from method names | |
// 2. Add extra \n before Interfaces | |
const fixedIndex = index | |
.replace(/^\* /ugm, '') | |
.replace(/\[`(.+)`\](.+)/ug, '[$1]$2') | |
.replace(/\[Interfaces\]/u, '\n[Interfaces]') | |
return `<docgen-index>${fixedIndex}</docgen-index>` | |
} | |
function fixIndex(content) { | |
return content.replace(/^\s*<docgen-index>(.+)<\/docgen-index>/usm, indexFixer) | |
} | |
function tableHeaderFixer(match, dashes) { | |
// Left align headers | |
return `| :${dashes} ` | |
} | |
function fixTables(content) { | |
return content.replace(/\|\s(-+)\s/ug, tableHeaderFixer) | |
.replace(/\|\s*\*\*`(\w+)`\*\*\s*\|/ug, '|$1|') | |
.replace(/\|\s*<code>(.+?)<\/code>\s*\|/ug, '|$1|') | |
} | |
function fixReturnTypes(content) { | |
return content.replace(/(\*\*Returns:\*\* )<code>(.+?)<\/code>/ug, '$1$2') | |
} | |
function main() { | |
let content = fs.readFileSync('README.md', 'utf-8') | |
content = fixIndex(content) | |
content = fixTables(content) | |
content = fixReturnTypes(content) | |
fs.writeFileSync('README.md', content, 'utf-8') | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment