0
我创建了一个迷你CMS来存储代码片段。 它从mongodb数据库中提取文章。 我使用highlgiht.js来显示代码并允许用户复制代码片段。使用把手输出原始javascript
随着HTML,一切正常:
{{#article}}
<h1>Demo</h1>
{{{markup}}} <!-- prints raw HTML in the screen, yay! -->
<h1>HTML</h1>
<pre class="pre-scrollable"><code class="html">{{markup}}</code></pre>
<!-- prints escaped HTML in the screen, and highlight.js highlights it perfectly! YAY -->
{{/article}}
现在,用javascript:
{{#article}}
<h1>Demo</h1>
{{{js}}} <!-- prints empty script tag: <script></script> -->
<h1>JS</h1>
<pre class="pre-scrollable"><code class="html">{{js}}</code></pre>
<!-- prints <script></script> -->
{{/article}}
在数据库中的字段 “JS” 的内容是 “执行console.log(” 测试“);”
为什么它不输出保存在数据库中的内容,而是它自己组成一个新的脚本标记?
谢谢!
把手不会改变'console.log'脚本,所以'js'值实际上是''或其他的东西正在改变那个值。显示如何编译句柄并在将句柄传递给handlebars时放置一个'console.log',并向我们显示输出。 –
@MarcosCasagrande:当我从我的文章控制器做一个console.log时,我得到原始的javascript作为文档字段的实际内容。 下面是我发现的其他东西: - 它不是浏览器,它发生在所有的浏览器中; - 它不是highlight.js,因为它按预期工作: '''
''' 这是带把手的东西。 – rsilva另外,我在我的应用程序中使用了这个handlebars包装:https://github.com/ericf/express-handlebars – rsilva