Ski*_*zit 3 html php syntax-highlighting
我正在使用http://softwaremaniacs.org/soft/highlight/en/来语法突出显示HTML.我有一个php循环从wordpress拉代码.我pre / code在我的代码和以下循环中使用标签从wordpress中提取代码.
<?php while (have_posts()) : the_post(); ?>
<p><i><?php the_date(); echo "<br />"; ?> </p></i>
<h2><?php the_title(); ?></h2>
<p><?php the_content(); ?></p>
<?php endwhile;?>
Run Code Online (Sandbox Code Playgroud)
在我的PHP页面的顶部,我有导入...
<script type="text/javascript" src="highlight.pack.js"></script>
<script type="text/javascript">
hljs.initHighlightingOnLoad();
</script>
Run Code Online (Sandbox Code Playgroud)
页面上的test.html工作正常,但我的网页似乎不在我的网络服务器上.这与我动态提取内容的方式有关吗?我怎么做这个工作?
从源代码
function initHighlightingOnLoad() {
var original_arguments = arguments;
var handler = function(){initHighlighting.apply(null, original_arguments)};
if (window.addEventListener) {
window.addEventListener('DOMContentLoaded', handler, false);
window.addEventListener('load', handler, false);
} else if (window.attachEvent)
window.attachEvent('onload', handler);
else
window.onload = handler;
}
Run Code Online (Sandbox Code Playgroud)
所以这只会工作一次,但是
您可以通过欺骗插件再次调用该方法
hljs.initHighlighting.called = false;
hljs.initHighlighting();
Run Code Online (Sandbox Code Playgroud)
我在演示页面上测试了它,似乎工作得很好.
因此,在页面上插入新元素后,可能需要调用这两行.