我想在我正在编写的Elm应用程序中嵌入以下代码段:
<script src="https://gist.github.com/jpaugh/2988462.js"></script>
我尝试使用[markdown|..|]
准引号,
header = plainText "blah, blah."
gist = [markdown|
<script src='https://gist.github.com/jpaugh/2988462.js'></script>
|]
main = flow down [header, gist]
然后抛出一个错误,该错误显然表示Elm中的错误,并将我的所有内容都放在<noscript>
中。
<noscript>
<p>blah, blah</p>
<p><script src='https://gist.github.com/jpaugh/2988462.js'></script>
</p>
</noscript>
但是还有另一种方法吗?使用Markdown语法插入html代码片段对我来说似乎很不稳定。库功能之一涵盖了这一点吗?我应该如何将其与Elm自己的javascript隔离? (使用<iframe>
似乎无济于事。)
编辑:这是错误消息。这就是屏幕上显示的内容,而不是代码。
最好采取另一种方法:不要使用JS / CSS弄乱elm的“域”,而应将elm嵌入普通的HTML中:您可以在elm框外进行所需的操作并仍然运行您的外部JS:
http://elm-lang.org/blog/announce/version-0.8.elm#embedding-elm-in-html-and-js
但是我认为您可以在Elm中从该代码段中获得内容,而无需使用任何JavaScript,我不确定最终要实现的目标是什么。
我这样做是因为我很邪恶。
script' : List Attribute -> String -> Html
script' attrs s = node "script" attrs [ text s ]
分别基于Html
和Html.Attributes
。用法示例:
div [] [ script' [] "alert(tremble in fear elm);" ]
如此
script : List Attribute -> List Html -> Html
script attrs children = node "script" attrs children
scriptSrc : String -> Html
scriptSrc s = script [ type' "text/javascript", src s ] []
scriptRun : String -> Html
scriptRun s = script [ type' "text/javascript" ] [ text s ]