Mix tasks, by default, don’t start the application. But FastSanitize.basic_html
is meant to be called inside a running app. You can tell the task to start your app like this:
defmodule Mix.Tasks.HelloTask do
use Mix.Task
@impl Mix.Task
def run(_) do
Mix.Task.run("app.start")
html = """
<p>blah</p>
"""
{:ok, res} = FastSanitize.basic_html(html)
IO.puts(res)
end
end
and then it should work OK:
$ mix hello_task
Compiling 1 file (.ex)
<p>blah</p>