为了从Erlang运行js代码,我找到了这个库https://github.com/strange/erlang_v8,它运行得很好,但我无法弄清楚如何将任何js库添加到上下文中,例如marked。我该怎么办?
答案 0 :(得分:0)
我通过从标记的源代码下载marked.min.js并在erlang_v8:start_vm / 1函数中给出路径来解决我的问题:
> {ok, VM} = erlang_v8:start_vm([{file, "path-in-file-system/marked.min.js"}]).
然后我按照以下方式使用它:
> {ok, Context1} = erlang_v8:create_context(VM).
{ok,242}
> erlang_v8:call(VM, Context1, <<"marked">>, [<<"# Marked in the browser\n\nRendered by **marked**.">>]).
{ok,<<"<h1 id=\"marked-in-the-browser\">Marked in the browser</h1>\n<p>Rendered by <strong>marked</strong>.</p>\n">>}