Files
gatsby-remark-annotate-code…/replaceCommentsWithAnnotations.js
2017-10-09 11:37:15 -07:00

11 lines
472 B
JavaScript

'use strict';
function escapeHtml(text) {
return text.replace(/"/g, '"');
}
module.exports = function replaceCommentsWithAnnotations(value) {
return value.replace(/<span class="token comment" spellcheck="true">\/\* @info (.*?)\*\/<\/span>\s*/g, function (match, content) {
return '<span class="code-annotation" title="' + escapeHtml(content) + '">';
}).replace(/<span class="token comment" spellcheck="true">\/\* @end \*\/<\/span>(\n *)?/g, '</span>');
};