3

I have the following Elm code, it is doing an Ajax call which will return some HTML which I want to embed directly into the dom. The problem is that the code here escapes the html so the user sees the markup, not the intended result. So I need to replace plainText with something else, but I am at a loss as to what that would be

load_comp_from_comp_set : String -> Signal Element
load_comp_from_comp_set compset_id =
  Signal.constant ("http://localhost:8000/finch/compset/" ++ compset_id)
  |> Http.sendGet
  |> Signal.map (result >> plainText)
4

1 回答 1

2

您可以使用elm-markdown 库中的Markdown.toElement我在elm-lang.org/try上尝试了以下代码,它按预期注入了 HTML。

import Markdown

main = Markdown.toElement """
<div>
  <h1 style="display: inline">Hello!</h1>
  <span></span> <sub>world</sub>
</div>
"""

您可以使用elm-package安装该库,以便 elm-make 自动获取它。它应该像elm-package install evancz/elm-markdown.

于 2015-02-17T13:53:55.377 回答