如何在Elixir中对字符串进行HTML解码?

5

这是我正在尝试解码的字符串。

"Ren & Stimpy The Lost Episodes Disc.1 [MP4-AAC] 480p DVD"

I'd like to end up with a string like:

"Ren & Stimpy The Lost Episodes Disc.1 [MP4-AAC] 480p DVD"

我尝试使用URI.decode函数,但它并没有起作用,我仍然得到相同的&符号。

iex(1)> URI.decode "Ren & Stimpy The Lost Episodes Disc.1 [MP4-AAC] 480p DVD"
"Ren & Stimpy The Lost Episodes Disc.1 [MP4-AAC] 480p DVD"

https://github.com/martinsvalin/html_entities - Dogbert
1个回答

6

从 Hex.pm 添加 html_entities

defp deps do
  [{:html_entities, "~> 0.5.2"}]
end

然后只需将字符串传递给它:
iex> HtmlEntities.decode("Ren & Stimpy The Lost Episodes Disc.1 [MP4-AAC] 480p DVD")
"Ren & Stimpy The Lost Episodes Disc.1 [MP4-AAC] 480p DVD"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接