Skip to content

Instantly share code, notes, and snippets.

@vzvu3k6k
Created December 18, 2018 18:02
Show Gist options
  • Save vzvu3k6k/f420b8c4a26a12604c376433e4c2822f to your computer and use it in GitHub Desktop.
Save vzvu3k6k/f420b8c4a26a12604c376433e4c2822f to your computer and use it in GitHub Desktop.
Lists line numbers of code blocks without info string in markdown files
// 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