Created
December 18, 2018 18:02
-
-
Save vzvu3k6k/f420b8c4a26a12604c376433e4c2822f to your computer and use it in GitHub Desktop.
Lists line numbers of code blocks without info string in markdown files
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
// Lists line numbers of code blocks without info string | |
// Usage: node checker.js */**/*.md | |
const fs = require('fs') | |
const commonmark = require('commonmark') | |
function* eachCodeBlocks(parsed) { | |
const walker = parsed.walker() | |
let event, node | |
while ((event = walker.next())) { | |
node = event.node | |
if (event.entering && node.type === 'code_block') { | |
yield node | |
} | |
} | |
} | |
process.argv.slice(2).forEach((path) => { | |
const reader = new commonmark.Parser() | |
const parsed = reader.parse(fs.readFileSync(path).toString()) | |
for (const node of eachCodeBlocks(parsed)) { | |
if (!node.info) { | |
console.log(`${path}:${node.sourcepos[0][0]}`) | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment