diff --git a/lib/earmark/options.ex b/lib/earmark/options.ex index 77e8d86e..be9b67eb 100644 --- a/lib/earmark/options.ex +++ b/lib/earmark/options.ex @@ -17,6 +17,35 @@ defmodule Earmark.Options do All other options are passed onto Earmark.Parser.as_ast/`2` """ + @type t :: %__MODULE__{ + annotations: String.t() | nil, + breaks: boolean(), + code_class_prefix: String.t() | nil, + compact_output: boolean(), + eex: boolean(), + escape: boolean(), + file: String.t() | nil, + footnote_offset: non_neg_integer(), + footnotes: boolean(), + gfm: boolean(), + gfm_tables: boolean(), + ignore_strings: boolean(), + inner_html: boolean(), + line: non_neg_integer(), + mapper: (list(any()), function() -> {:ok, list(any())} | {:error, any()}), + mapper_with_timeout: + (list(any()), function(), integer() -> {:ok, list(any())} | {:error, any()}), + messages: list(Earmark.Error.t()) | [], + pedantic: boolean(), + postprocessor: function() | nil, + pure_links: boolean(), + sub_sup: boolean(), + registered_processors: list(any()), + smartypants: boolean(), + template: boolean(), + timeout: integer() | nil, + wikilinks: boolean() + } defstruct annotations: nil, breaks: false, code_class_prefix: nil, diff --git a/lib/earmark/tag_specific_processors.ex b/lib/earmark/tag_specific_processors.ex index edf35442..24979a34 100644 --- a/lib/earmark/tag_specific_processors.ex +++ b/lib/earmark/tag_specific_processors.ex @@ -1,5 +1,4 @@ defmodule Earmark.TagSpecificProcessors do - @moduledoc """ This struct represents a list of tuples `{tag, function}` from which a postprocessing function can be constructed @@ -21,7 +20,7 @@ defmodule Earmark.TagSpecificProcessors do ...(2)> make_postprocessor(tsp).({"x", [], nil, nil}) {"x", [], nil, nil} """ - + @type t :: %__MODULE__{tag_functions: list()} defstruct tag_functions: [] @doc """ @@ -29,8 +28,10 @@ defmodule Earmark.TagSpecificProcessors do to the tag of the node, and apply the node to it if such a function was found. """ def make_postprocessor(%__MODULE__{tag_functions: tfs}) do - fn {_, _, _, _}=node -> _postprocess(node, tfs) - other -> other end + fn + {_, _, _, _} = node -> _postprocess(node, tfs) + other -> other + end end @doc """ @@ -41,22 +42,25 @@ defmodule Earmark.TagSpecificProcessors do """ def new, do: %__MODULE__{} - def new({_, _}=tf), do: %__MODULE__{tag_functions: [tf]} + def new({_, _} = tf), do: %__MODULE__{tag_functions: [tf]} def new(tfs), do: %__MODULE__{tag_functions: tfs} - @doc """ Prepends a tuple {tag, function} to the list of such tuples. """ def prepend_tag_function(tsp, tag, function), do: prepend_tag_function(tsp, {tag, function}) - def prepend_tag_function(%__MODULE__{tag_functions: tfs}=tsp, tf) do - %{tsp | tag_functions: [tf|tfs]} + + def prepend_tag_function(%__MODULE__{tag_functions: tfs} = tsp, tf) do + %{tsp | tag_functions: [tf | tfs]} end - defp _postprocess({t, _, _, _}=node, tfs) do - fun = tfs - |> Enum.find_value(fn {t_, f} -> if t == t_, do: f end) + defp _postprocess({t, _, _, _} = node, tfs) do + fun = + tfs + |> Enum.find_value(fn {t_, f} -> if t == t_, do: f end) + if fun, do: fun.(node), else: node end end + # SPDX-License-Identifier: Apache-2.0 diff --git a/lib/earmark_parser/line.ex b/lib/earmark_parser/line.ex index 5ff85540..eb643daf 100644 --- a/lib/earmark_parser/line.ex +++ b/lib/earmark_parser/line.ex @@ -1,67 +1,215 @@ defmodule Earmark.Parser.Line do - @moduledoc false + alias Earmark.Parser.Line + + @type annotation :: any() | nil + @type lnb :: integer() + @type line :: String.t() + @type indent :: integer() + @type content :: String.t() + @type ial :: any() | nil + @type type :: String.t() + @type level :: integer() + @type delimiter :: String.t() + @type language :: any() + @type tag :: String.t() + @type complete :: boolean() + @type id :: any() + @type url :: String.t() | URI.t() + @type title :: String.t() + @type bullet :: String.t() + @type initial_indent :: integer() + @type list_indent :: integer() -defmodule Blank do + defmodule Blank do @moduledoc false + + @type t :: %__MODULE__{ + annotation: Line.annotation(), + lnb: Line.lnb(), + line: Line.line(), + indent: Line.indent(), + content: Line.content() + } + defstruct(annotation: nil, lnb: 0, line: "", indent: -1, content: "") end -defmodule Ruler do + + defmodule Ruler do @moduledoc false + @type t :: %__MODULE__{ + annotation: Line.annotation(), + lnb: Line.lnb(), + line: Line.line(), + indent: Line.indent(), + type: Line.type() + } + defstruct(annotation: nil, lnb: 0, line: "", indent: -1, type: "- or * or _") end -defmodule Heading do + defmodule Heading do @moduledoc false - defstruct(annotation: nil, ial: nil, lnb: 0, line: "", indent: -1, level: 1, content: "inline text") + @type t :: %__MODULE__{ + annotation: Line.annotation(), + ial: Line.ial(), + lnb: Line.lnb(), + line: Line.line(), + indent: Line.indent(), + level: Line.level(), + content: Line.content() + } + + defstruct( + annotation: nil, + ial: nil, + lnb: 0, + line: "", + indent: -1, + level: 1, + content: "inline text" + ) end -defmodule BlockQuote do + defmodule BlockQuote do @moduledoc false + @type t :: %__MODULE__{ + annotation: Line.annotation(), + ial: Line.ial(), + lnb: Line.lnb(), + line: Line.line(), + indent: Line.indent(), + content: Line.content() + } defstruct(annotation: nil, ial: nil, lnb: 0, line: "", indent: -1, content: "text") end -defmodule Indent do + defmodule Indent do @moduledoc false + @type t :: %__MODULE__{ + annotation: Line.annotation(), + lnb: Line.lnb(), + line: Line.line(), + indent: Line.indent(), + level: Line.level(), + content: Line.content() + } + defstruct(annotation: nil, lnb: 0, line: "", indent: -1, level: 0, content: "text") end -defmodule Fence do + defmodule Fence do @moduledoc false + @type t :: %__MODULE__{ + annotation: Line.annotation(), + lnb: Line.lnb(), + line: Line.line(), + indent: Line.indent(), + delimiter: Line.delimiter(), + language: Line.language() + } + defstruct(annotation: nil, lnb: 0, line: "", indent: -1, delimiter: "~ or `", language: nil) end -defmodule HtmlOpenTag do + defmodule HtmlOpenTag do @moduledoc false + @type t :: %__MODULE__{ + annotation: Line.annotation(), + lnb: Line.lnb(), + line: Line.line(), + indent: Line.indent(), + tag: Line.tag(), + content: Line.content() + } + defstruct(annotation: nil, lnb: 0, line: "", indent: -1, tag: "", content: "") end -defmodule HtmlCloseTag do + defmodule HtmlCloseTag do @moduledoc false + @type t :: %__MODULE__{ + annotation: Line.annotation(), + lnb: Line.lnb(), + line: Line.line(), + indent: Line.indent(), + tag: Line.tag() + } + defstruct(annotation: nil, lnb: 0, line: "", indent: -1, tag: "<... to eol") end -defmodule HtmlComment do + + defmodule HtmlComment do @moduledoc false + @type t :: %__MODULE__{ + annotation: Line.annotation(), + lnb: Line.lnb(), + line: Line.line(), + indent: Line.indent(), + complete: Line.complete() + } + defstruct(annotation: nil, lnb: 0, line: "", indent: -1, complete: true) end -defmodule HtmlOneLine do + defmodule HtmlOneLine do @moduledoc false + @type t :: %__MODULE__{ + annotation: Line.annotation(), + lnb: Line.lnb(), + line: Line.line(), + indent: Line.indent(), + tag: Line.tag(), + content: Line.content() + } + defstruct(annotation: nil, lnb: 0, line: "", indent: -1, tag: "", content: "") end -defmodule IdDef do + defmodule IdDef do @moduledoc false + @type t :: %__MODULE__{ + annotation: Line.annotation(), + lnb: Line.lnb(), + line: Line.line(), + indent: Line.indent(), + id: Line.id(), + url: Line.url(), + title: Line.title() + } + defstruct(annotation: nil, lnb: 0, line: "", indent: -1, id: nil, url: nil, title: nil) end -defmodule FnDef do + defmodule FnDef do @moduledoc false + @type t :: %__MODULE__{ + annotation: Line.annotation(), + lnb: Line.lnb(), + line: Line.line(), + indent: Line.indent(), + id: Line.id(), + content: Line.content() + } + defstruct(annotation: nil, lnb: 0, line: "", indent: -1, id: nil, content: "text") end -defmodule ListItem do + defmodule ListItem do @moduledoc false + @type t :: %__MODULE__{ + annotation: Line.annotation(), + ial: Line.ial(), + lnb: Line.lnb(), + type: Line.type(), + line: Line.line(), + indent: Line.indent(), + bullet: Line.bullet(), + content: Line.content(), + initial_indent: Line.initial_indent(), + list_indent: Line.list_indent() + } + defstruct( annotation: nil, ial: nil, @@ -76,23 +224,71 @@ defmodule ListItem do ) end -defmodule SetextUnderlineHeading do + defmodule SetextUnderlineHeading do @moduledoc false + @type t :: %__MODULE__{ + annotation: Line.annotation(), + lnb: Line.lnb(), + line: Line.line(), + indent: Line.indent(), + level: Line.level() + } + defstruct(annotation: nil, lnb: 0, line: "", indent: -1, level: 1) end -defmodule TableLine do + defmodule TableLine do @moduledoc false - defstruct(annotation: nil, lnb: 0, line: "", indent: -1, content: "", columns: 0, is_header: false, needs_header: false) + @type t :: %__MODULE__{ + annotation: Line.annotation(), + lnb: Line.lnb(), + line: Line.line(), + indent: Line.indent(), + content: Line.content(), + columns: integer(), + is_header: boolean(), + needs_header: boolean() + } + + defstruct( + annotation: nil, + lnb: 0, + line: "", + indent: -1, + content: "", + columns: 0, + is_header: false, + needs_header: false + ) end -defmodule Ial do + defmodule Ial do @moduledoc false + @type t :: %__MODULE__{ + annotation: Line.annotation(), + ial: Line.ial(), + lnb: Line.lnb(), + line: Line.line(), + indent: Line.indent(), + attrs: String.t(), + verbatim: String.t() + } + defstruct(annotation: nil, ial: nil, lnb: 0, line: "", indent: -1, attrs: "", verbatim: "") end -defmodule Text do + + defmodule Text do @moduledoc false + @type t :: %__MODULE__{ + annotation: Line.annotation(), + lnb: Line.lnb(), + line: Line.line(), + indent: Line.indent(), + content: Line.content() + } + defstruct(annotation: nil, lnb: 0, line: "", indent: -1, content: "") end end + # SPDX-License-Identifier: Apache-2.0