Skip to content

Commit

Permalink
Rel 1.4.42
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertDober committed Sep 20, 2023
1 parent 330369a commit 0500c23
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 1 deletion.
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [Earmark](https://hex.pm/packages/earmark) 1.4.41 2023-09-20

Added missing erlang sources

## [Earmark](https://hex.pm/packages/earmark) 1.4.41 2023-09-19

Isolate from `EarmarkParser` in order to prevent conflicts with indirect dependencies
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Earmark.Mixfile do
use Mix.Project

@version "1.4.41"
@version "1.4.42"

@url "https://github.com/pragdave/earmark"

Expand Down
31 changes: 31 additions & 0 deletions src/link_text_lexer.xrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Definitions.

ESCAPED = \\.
ESCAPE = \\
EXCLAMATION_MARK = [!]
OPEN_PAREN = \(
CLOSE_PAREN = \)
OPEN_BRACKET = \[
CLOSE_BRACKET = \]
OPEN_TITLE = \s+['"]
ANY_QUOTE = ['"]
WS = \s+
ANY = [^]\\"'()[\s]+
Rules.
{ESCAPED} : {token, {escaped, TokenLine, dismiss_backslash(TokenChars)}}.
{EXCLAMATION_MARK} : {token, {exclamation_mark, TokenLine, TokenChars}}.
{OPEN_PAREN} : {token, {open_paren, TokenLine, TokenChars}}.
{CLOSE_PAREN} : {token, {close_paren, TokenLine, TokenChars}}.
{OPEN_BRACKET} : {token, {open_bracket, TokenLine, TokenChars}}.
{CLOSE_BRACKET} : {token, {close_bracket, TokenLine, TokenChars}}.
{OPEN_TITLE} : {token, {open_title, TokenLine, TokenChars}}.
{ANY_QUOTE} : {token, {any_quote, TokenLine, TokenChars}}.
{ESCAPE} : {token, {verbatim, TokenLine, TokenChars}}.
{WS} : {token, {ws, TokenLine, TokenChars}}.
{ANY} : {token, {verbatim, TokenLine, TokenChars}}.
Erlang code.
dismiss_backslash([$\\|Chars]) -> Chars.
59 changes: 59 additions & 0 deletions src/link_text_parser.yrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Nonterminals link_or_image
link rest
inside_brackets inside_brackets_part anything.

Terminals any_quote open_bracket open_title close_bracket open_paren close_paren verbatim escaped exclamation_mark ws.

Rootsymbol link_or_image.

link_or_image -> exclamation_mark link : make_image_tuple('$2').
link_or_image -> link : '$1'.

link -> open_bracket close_bracket : {link, "", "[]"}.
link -> open_bracket close_bracket rest : {link, "", "[]"}.
link -> open_bracket inside_brackets close_bracket : title_tuple('$2').
link -> open_bracket inside_brackets close_bracket rest : title_tuple('$2').

inside_brackets -> inside_brackets_part : '$1'.
inside_brackets -> inside_brackets_part inside_brackets : concat_tuple('$1', '$2').

inside_brackets_part -> exclamation_mark : extract_token('$1').
inside_brackets_part -> verbatim : extract_token('$1').
inside_brackets_part -> ws : extract_token('$1').
inside_brackets_part -> open_title : extract_token('$1').
inside_brackets_part -> open_paren : {"(", "("}.
inside_brackets_part -> close_paren : {")", ")"}.
inside_brackets_part -> any_quote : extract_token('$1').
inside_brackets_part -> escaped : escaped_token('$1').
inside_brackets_part -> open_bracket close_bracket : {"[]", "[]"}.
inside_brackets_part -> open_bracket inside_brackets close_bracket : concat_3t("[", '$2', "]").

rest -> anything.
rest -> anything rest.

anything -> exclamation_mark.
anything -> ws.
anything -> verbatim.
anything -> open_paren.
anything -> close_paren.
anything -> open_bracket.
anything -> close_bracket.
anything -> any_quote.
anything -> escaped.
anything -> open_title.

Erlang code.

concat_tuple({LT, LP}, {RT, RP}) -> {string:concat(LT, RT), string:concat(LP, RP)}.

concat_3t(L, {MT, MP}, R) -> {string:join([L, MT, R], ""), string:join([ L, MP, R ], "")}.

escaped_token({_Token, _Line, Value}) -> {string:concat("\\", Value), string:concat("\\", Value)}.

extract_token({_Token, _Line, Value}) -> {Value, Value}.

make_image_tuple({_Link, L, R}) -> {image, L, string:concat("!", R)}.

title_tuple({Title, Parsed}) -> {link, Title, string:join(["[", Parsed, "]"], "")}.

%% SPDX-License-Identifier: Apache-2.0
13 changes: 13 additions & 0 deletions src/string_lexer.xrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Definitions.

OTHER = [^`\\]+
ESCAPE = \\
BACKTIX = `+

Rules.

{OTHER} : {token, {other, TokenLine, TokenChars}}.
{ESCAPE} : {token, {escape, TokenLine, TokenChars}}.
{BACKTIX} : {token, {backtix, TokenLine, TokenChars}}.

Erlang code.

0 comments on commit 0500c23

Please sign in to comment.