这是使用 ACE 编辑器的 ext-static-highlight.js 的示例。如何将内联选项设置为 true,以便在突出显示代码时避免使用 PHP 标签?
<script>
var highlight = ace.require("ace/ext/static_highlight")
var dom = ace.require("ace/lib/dom")
function qsa(sel) {
return Array.apply(null, document.querySelectorAll(sel));
}
qsa(".code").forEach(function (codeEl) {
highlight(codeEl, {
mode: codeEl.getAttribute("ace-mode"),
theme: codeEl.getAttribute("ace-theme"),
startLineNumber: 1,
showGutter: codeEl.getAttribute("ace-gutter"),
trim: true
}, function (highlighted) {
});
});
</script>
您需要
将一个对象作为模式{path: "ace/mode/php", inline: true}
传递给突出显示函数。所以使用这样的东西:
<script>
var highlight = ace.require("ace/ext/static_highlight")
var dom = ace.require("ace/lib/dom")
function qsa(sel) {
return Array.apply(null, document.querySelectorAll(sel));
}
qsa(".code").forEach(function (codeEl) {
var mode = codeEl.getAttribute("ace-mode");
if (mode == "php-inline")
mode = {path: "ace/mode/php", inline: true}
highlight(codeEl, {
mode: mode,
theme: codeEl.getAttribute("ace-theme"),
startLineNumber: 1,
showGutter: codeEl.getAttribute("ace-gutter"),
trim: true
}, function (highlighted) {
});
});
</script>