99cbb42962
This basically just adds svg elements as void and nonvoid element aliases and it works, will test on a real proejct before releasing the next release. Also, fixed the weird behaviour problem by defining types for each of the ast nodes and then referencing those types when defining the ast type. Unclear why this works, but I imagine it has to do with the types not being a big part of the compilation process or something. This also uses the typed_struct library to do so. Seems pretty slick and does what it claims it does.
35 lines
668 B
Elixir
35 lines
668 B
Elixir
defmodule Temple.Parser.VoidElementsAliases do
|
|
@moduledoc false
|
|
@behaviour Temple.Parser
|
|
|
|
use TypedStruct
|
|
|
|
typedstruct do
|
|
field :name, atom()
|
|
field :attrs, list(), default: []
|
|
end
|
|
|
|
@impl true
|
|
def applicable?({name, _, _}) do
|
|
name in Temple.Parser.void_elements_aliases()
|
|
end
|
|
|
|
def applicable?(_), do: false
|
|
|
|
@impl true
|
|
def run({name, _, args}) do
|
|
args =
|
|
case Temple.Parser.Utils.split_args(args) do
|
|
{_, [args]} when is_list(args) ->
|
|
args
|
|
|
|
{_, args} ->
|
|
args
|
|
end
|
|
|
|
name = Temple.Parser.void_elements_lookup()[name]
|
|
|
|
Temple.Ast.new(__MODULE__, name: name, attrs: args)
|
|
end
|
|
end
|