mirror of
https://github.com/expo/gatsby-remark-annotate-codeblock.git
synced 2026-11-15 17:34:13 -10:00
11 lines
472 B
JavaScript
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>');
|
|
}; |