Skip to content

Commit

Permalink
Apply mix formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotto committed Aug 9, 2023
1 parent 259a369 commit 4b589fd
Show file tree
Hide file tree
Showing 14 changed files with 639 additions and 537 deletions.
10 changes: 5 additions & 5 deletions lib/mix/tasks/pandoc/update_infos.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ defmodule Mix.Tasks.Pandoc.UpdateInfos do

@shortdoc "Updates the information about the supported features of Pandoc."
def run(_) do
Mix.Shell.IO.cmd "pandoc --list-extensions > #{Pandoc.extensions_file()}"
Mix.Shell.IO.cmd "pandoc --list-highlight-languages > #{Pandoc.highlight_languages_file()}"
Mix.Shell.IO.cmd "pandoc --list-highlight-styles > #{Pandoc.highlight_styles_file()}"
Mix.Shell.IO.cmd "pandoc --list-input-formats > #{Pandoc.input_formats_file()}"
Mix.Shell.IO.cmd "pandoc --list-output-formats > #{Pandoc.output_formats_file()}"
Mix.Shell.IO.cmd("pandoc --list-extensions > #{Pandoc.extensions_file()}")
Mix.Shell.IO.cmd("pandoc --list-highlight-languages > #{Pandoc.highlight_languages_file()}")
Mix.Shell.IO.cmd("pandoc --list-highlight-styles > #{Pandoc.highlight_styles_file()}")
Mix.Shell.IO.cmd("pandoc --list-input-formats > #{Pandoc.input_formats_file()}")
Mix.Shell.IO.cmd("pandoc --list-output-formats > #{Pandoc.output_formats_file()}")
end
end
19 changes: 9 additions & 10 deletions lib/panpipe.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ defmodule Panpipe do

alias Panpipe.Pandoc


defdelegate pandoc(input_or_opts, opts \\ nil), to: Pandoc, as: :call
defdelegate pandoc(input_or_opts, opts \\ nil), to: Pandoc, as: :call
defdelegate pandoc!(input_or_opts, opts \\ nil), to: Pandoc, as: :call!

defdelegate transform(node, fun), to: Panpipe.AST.Node


@doc """
Creates the Panpipe AST representation of some input.
Expand All @@ -42,7 +40,6 @@ defmodule Panpipe do
end
end


@doc """
Creates an `Panpipe.AST.Node` of some input without the surrounding `Document` structure.
"""
Expand All @@ -58,7 +55,8 @@ defmodule Panpipe do
%Panpipe.Document{children: children} when is_list(children) ->
{:ok, %Panpipe.AST.Plain{children: children}}

_ -> {:error, "unable to extract ast_fragment from #{inspect pandoc_ast}"}
_ ->
{:error, "unable to extract ast_fragment from #{inspect(pandoc_ast)}"}
end
end
end
Expand All @@ -74,8 +72,7 @@ defmodule Panpipe do
end
end


Enum.each Panpipe.Pandoc.output_formats, fn output_format ->
Enum.each(Panpipe.Pandoc.output_formats(), fn output_format ->
@doc """
Calls `pandoc/1` with the option `to: :#{to_string(output_format)}` automatically set.
Expand All @@ -93,8 +90,10 @@ defmodule Panpipe do
first manually or use `pandoc/1` directly.
"""
def unquote(String.to_atom("to_" <> to_string(output_format)))(input, opts \\ []) do
Panpipe.Pandoc.Conversion.convert(input,
Keyword.put(opts, :to, unquote(output_format)))
Panpipe.Pandoc.Conversion.convert(
input,
Keyword.put(opts, :to, unquote(output_format))
)
end
end
end)
end
37 changes: 14 additions & 23 deletions lib/panpipe/ast/node.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ defmodule Panpipe.AST.Node do
traversal.
"""


# TODO: This attempt to define a type for struct implementing this behaviour is copied from RDF.Graph & co. and won't work probably ...
@type t :: module

Expand Down Expand Up @@ -49,10 +48,8 @@ defmodule Panpipe.AST.Node do
"""
@callback transform(t, fun) :: t


@shared_fields parent: nil


@doc """
Produces the Pandoc AST data structure of the given Panpipe AST `node`.
Expand Down Expand Up @@ -122,7 +119,6 @@ defmodule Panpipe.AST.Node do
def child_type(node)
def child_type(%mod{}), do: mod.child_type()


@doc false
defmacro __using__(opts) do
node_type = Keyword.fetch!(opts, :type)
Expand Down Expand Up @@ -159,8 +155,7 @@ defmodule Panpipe.AST.Node do
|> Panpipe.Document.fragment()
|> Panpipe.Document.to_pandoc()
|> Jason.encode!()
|> Panpipe.Pandoc.call(Keyword.put(opts, :from, :json))
do
|> Panpipe.Pandoc.call(Keyword.put(opts, :from, :json)) do
if result do
Panpipe.Pandoc.Conversion.Utils.post_process(result, node, opts)
end
Expand All @@ -172,8 +167,8 @@ defmodule Panpipe.AST.Node do

defimpl Enumerable do
def member?(_node, _), do: {:error, __MODULE__}
def count(_node), do: {:error, __MODULE__}
def slice(_node), do: {:error, __MODULE__}
def count(_node), do: {:error, __MODULE__}
def slice(_node), do: {:error, __MODULE__}

def reduce(_, {:halt, acc}, _fun), do: {:halted, acc}

Expand All @@ -184,21 +179,20 @@ defmodule Panpipe.AST.Node do
def reduce(node, {:cont, acc}, fun) do
unquote(__CALLER__.module).children(node)
|> Enum.reduce(fun.(node, acc), fn child, result ->
Enumerable.reduce(%{child | parent: node}, result, fun)
end)
Enumerable.reduce(%{child | parent: node}, result, fun)
end)
end

end

defoverridable [children: 1, transform: 2]
defoverridable children: 1, transform: 2
end
end

@doc !"""
This is a general implementation of the `Panpipe.AST.Node.transform/2` function.
Do not use it directly, but instead call the `Panpipe.AST.Node.transform/2` implementation
of a node, which might have a different implementation.
"""
This is a general implementation of the `Panpipe.AST.Node.transform/2` function.
Do not use it directly, but instead call the `Panpipe.AST.Node.transform/2` implementation
of a node, which might have a different implementation.
"""
def do_transform(node, fun)

def do_transform(%{children: children} = node, fun) do
Expand Down Expand Up @@ -231,10 +225,7 @@ defmodule Panpipe.AST.Node do
end

defp fields(:block, fields) do
[
children: []
]
++ @shared_fields
([children: []] ++ @shared_fields)
|> Keyword.merge(to_keywords(fields))
end

Expand All @@ -247,10 +238,10 @@ defmodule Panpipe.AST.Node do
if Keyword.keyword?(list) do
list
else
Enum.map list, fn
Enum.map(list, fn
{_, _} = keyword -> keyword
field -> {field, nil}
end
field -> {field, nil}
end)
end
end
end
Loading

0 comments on commit 4b589fd

Please sign in to comment.