Packages
earmark
1.2.3
1.5.0-pre1
retired
1.5.0-pre
retired
1.4.49
retired
1.4.48
retired
1.4.47
retired
1.4.46
retired
1.4.45
retired
1.4.44
retired
1.4.43
retired
1.4.42
retired
1.4.41
retired
1.4.40
retired
1.4.39
retired
1.4.38
retired
1.4.37
retired
1.4.36
retired
1.4.35
retired
1.4.34
retired
1.4.33
retired
1.4.32
retired
1.4.31
retired
1.4.30
retired
1.4.29
retired
1.4.28
retired
1.4.27
retired
1.4.26
retired
1.4.25
retired
1.4.24
retired
1.4.23
retired
1.4.22
retired
1.4.21
retired
1.4.20
retired
1.4.19
retired
1.4.18
retired
1.4.17
retired
1.4.16
retired
1.4.16-pre2
retired
1.4.16-pre1
retired
1.4.16-pre
retired
1.4.15
retired
1.4.14
retired
1.4.13
retired
1.4.12
retired
1.4.10
retired
1.4.9
retired
1.4.8
retired
1.4.7
retired
1.4.6
retired
1.4.5
retired
1.4.4
retired
1.4.3
retired
1.4.2
retired
1.4.1
retired
1.4.0
retired
1.3.6
retired
1.3.5
retired
1.3.4
retired
1.3.3
retired
1.3.2
retired
1.3.1
retired
1.3.0
retired
1.2.6
retired
1.2.5
retired
1.2.4
retired
1.2.3
retired
1.2.2
retired
1.2.1
retired
1.2.0
retired
1.1.1
retired
1.1.0
retired
1.0.3
retired
1.0.2
retired
1.0.1
retired
1.0.0
retired
0.2.1
retired
0.2.0
retired
0.1.19
retired
0.1.18
retired
0.1.17
retired
0.1.16
retired
0.1.15
retired
0.1.14
retired
0.1.13
retired
0.1.12
retired
0.1.10
retired
0.1.9
retired
0.1.8
retired
0.1.7
retired
0.1.6
retired
0.1.5
retired
0.1.4
retired
0.1.3
retired
0.1.2
retired
0.1.1
retired
0.1.0
retired
Earmark is a pure-Elixir Markdown converter. It is intended to be used as a library (just call Earmark.as_html), but can also be used as a command-line tool (run mix escript.build first). Output generation is pluggable.
Retired package: Deprecated - Earmark is no longer maintained. Migrate to a replacement, for example MDEx (https://hex.pm/packages/mdex).
Current section
Files
Jump to
Current section
Files
lib/earmark/helpers/attr_parser.ex
defmodule Earmark.Helpers.AttrParser do
import Earmark.Helpers.StringHelpers, only: [ behead: 2 ]
import Earmark.Message, only: [add_message: 2]
alias Earmark.Context
@type errorlist :: list(String.t)
@spec parse_attrs(Context.t, String.t, number()) :: {Map.t, errorlist}
def parse_attrs(context, attrs, lnb) do
{ attrs, errors } = _parse_attrs(%{}, attrs, [], lnb)
{ add_errors(context, errors, lnb), attrs }
end
defp _parse_attrs(dict, attrs, errors, lnb) do
cond do
Regex.match?(~r{^\s*$}, attrs) -> {dict, errors}
match = Regex.run(~r{^\.(\S+)\s*}, attrs) ->
[ leader, class ] = match
Map.update(dict, "class", [ class ], &[ class | &1])
|> _parse_attrs(behead(attrs, leader), errors, lnb)
match = Regex.run(~r{^\#(\S+)\s*}, attrs) ->
[ leader, id ] = match
Map.update(dict, "id", [ id ], &[ id | &1])
|> _parse_attrs(behead(attrs, leader), errors, lnb)
# Might we being running into escape issues here too?
match = Regex.run(~r{^(\S+)=\'([^\']*)'\s*}, attrs) -> #'
[ leader, name, value ] = match
Map.update(dict, name, [ value ], &[ value | &1])
|> _parse_attrs(behead(attrs, leader), errors, lnb)
# Might we being running into escape issues here too?
match = Regex.run(~r{^(\S+)=\"([^\"]*)"\s*}, attrs) -> #"
[ leader, name, value ] = match
Map.update(dict, name, [ value ], &[ value | &1])
|> _parse_attrs(behead(attrs, leader), errors, lnb)
match = Regex.run(~r{^(\S+)=(\S+)\s*}, attrs) ->
[ leader, name, value ] = match
Map.update(dict, name, [ value ], &[ value | &1])
|> _parse_attrs(behead(attrs, leader), errors, lnb)
match = Regex.run(~r{^(\S+)\s*(.*)}, attrs) ->
[ _, incorrect, rest ] = match
_parse_attrs(dict, rest, [ incorrect | errors ], lnb)
:otherwise ->
{dict, [attrs | errors ]}
end
end
defp add_errors(context, [], _lnb), do: context
defp add_errors(context, errors, lnb), do: add_message(context, {:warning, lnb, "Illegal attributes #{inspect errors} ignored in IAL"})
end