Hugo在部分中逃脱了Javascript,代码被破坏了

时间:2017-05-28 22:50:44

标签: javascript mathjax hugo

此代码段发布在Hugo的MathJax支持页面中。我接受它并插入部分(例如,head.html)。

<script type="text/x-mathjax-config">
  MathJax.Hub.Queue(function() {
    // Fix <code> tags after MathJax finishes running. This is a
    // hack to overcome a shortcoming of Markdown. Discussion at
    // https://github.com/mojombo/jekyll/issues/199
    var all = MathJax.Hub.getAllJax(), i;
    for(i = 0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += ' has-jax';
    }
});
</script>

当页面加载时,浏览器会尝试执行它,但会在Console中写一个例外:

VM14379:7 Uncaught SyntaxError: Unexpected token ;
at eval (<anonymous>)

我点击该行并看到:

enter image description here

我是对的,因为<被转义了吗?如何解决?

编辑>将其移至my-theme/layouts/index.html会使代码完全从呈现的页面中消失。在layouts/_default/single.html中,它仍会导致相同的错误。)

雨果版本是0.21。

1 个答案:

答案 0 :(得分:1)

找到解决方案:将length = 6 low = 0 highInclusive = 5, highExclusive = 6 midInclusive = 5/2 = 2, midExclusive = 6/2 = 3 更改为-1,一切正常。