尝试在使用highlight.js的节点脚本中运行JSDom以选择需要突出显示的块。
const dom = new JSDOM(html);
const document = dom.window.document;
document.querySelectorAll('.Test_markup > code').forEach((node)=> {
var markup = node.innerHTML;
console.log(markup);
highlight.highlightBlock(markup);
});
记录的标记如下所示:
<div class="Grid">
<!-- Use Nunjucks to keep markup DRY -->
<div class="Grid_cell">1/2</div>
<div class="Grid_cell">2/2</div>
</div>
当我在标记上运行代码时,结果为:
TypeError: Cannot read property 'replace' of undefined
思想?
答案 0 :(得分:0)
这将产生亮点:
const highlight = require('highlight.js');
console.log(highlight.highlight('html', markup).value);