Skip to content

Instantly share code, notes, and snippets.

@mikeal
Last active June 14, 2022 12:36
Show Gist options
  • Save mikeal/e87fae29728fea1761b7 to your computer and use it in GitHub Desktop.
Save mikeal/e87fae29728fea1761b7 to your computer and use it in GitHub Desktop.

Revisions

  1. mikeal revised this gist Feb 27, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion get-comments.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    var highlight = require('highlight.js')
    var cheerio = require('cheerio')

    var strip = ['/', '#', ' ', '*', "<", ">", '-', '\']
    var strip = ['/', '#', ' ', '*', "<", ">", '-', '\\']

    function getComments (str) {
    var html = highlight.highlightAuto(str).value
  2. mikeal created this gist Feb 27, 2016.
    18 changes: 18 additions & 0 deletions get-comments.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    var highlight = require('highlight.js')
    var cheerio = require('cheerio')

    var strip = ['/', '#', ' ', '*', "<", ">", '-', '\']

    function getComments (str) {
    var html = highlight.highlightAuto(str).value
    var $ = cheerio.load(html)
    var lines = $('span.hljs-comment').map(function(i, el) {return $(this).text();}).get()
    return lines.map(function (l) {
    while (l.length && strip.indexOf(l[0]) !== -1) {
    l = l.slice(1)
    }
    return l
    })
    }

    module.exports = getComments