2017-01-06 6 views
0

이것은 ACE 편집기의 ext-static-highlight.js를 사용하는 예입니다. 인라인 옵션을 true로 설정하면 코드를 강조 표시 할 때 PHP 태그를 사용하지 않아도됩니까?PHP 태그를 사용하지 않고 ACE 정적 강조 표시

<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> 

답변

1

당신은 모드 {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> 
+0

정말 고마워요. :) – Walter