less special casing of literal, require del_open not be followed by a greater than sign to allow it to be replaced as an arrow

This commit is contained in:
byte[] 2019-12-16 00:59:25 -05:00
parent 2c2ad9ee82
commit 3012de58b6
4 changed files with 22 additions and 18 deletions

View file

@ -38,4 +38,4 @@ defmodule Textile.Helpers do
end
defp binary_head(<<c::utf8, _rest::binary>>), do: <<c::utf8>>
end
end

View file

@ -14,13 +14,24 @@ defmodule Textile.Lexer do
ignore(string("[=="))
|> repeat(lookahead_not(string("==]")) |> utf8_char([]))
|> ignore(string("==]"))
unbracketed_literal =
ignore(string("=="))
|> repeat(lookahead_not(string("==")) |> utf8_char([]))
|> ignore(string("=="))
literal =
choice([
bracketed_literal,
unbracketed_literal
])
|> reduce({List, :to_string, []})
|> unwrap_and_tag(:bracketed_literal)
|> unwrap_and_tag(:literal)
blockquote_cite =
lookahead_not(string("\""))
|> choice([
bracketed_literal |> reduce(:unwrap),
literal |> reduce(:unwrap),
utf8_char([])
])
|> repeat()
@ -146,7 +157,7 @@ defmodule Textile.Lexer do
blockquote_open,
blockquote_open_cite,
blockquote_close,
bracketed_literal,
literal,
link_markup_start
])
@ -158,7 +169,7 @@ defmodule Textile.Lexer do
blockquote_open,
blockquote_open_cite,
blockquote_close,
bracketed_literal,
literal,
link_markup_element
])
@ -215,7 +226,7 @@ defmodule Textile.Lexer do
textile_default =
choice([
bracketed_literal,
literal,
blockquote_open_cite |> optional(markup_start),
blockquote_open |> optional(markup_start),
blockquote_close,

View file

@ -117,7 +117,7 @@ defmodule Textile.MarkupLexer do
code_open,
ins_open,
sup_open,
del_open,
del_open |> lookahead_not(string(">")),
sub_open
])
@ -168,4 +168,4 @@ defmodule Textile.MarkupLexer do
{markup_at_start, markup_element}
end
end
end

View file

@ -102,13 +102,13 @@ defmodule Textile.Parser do
# markup =
# blockquote | spoiler | link | image | bold | italic | strong | emphasis |
# code | inserted | superscript | deleted | subscript | newline | literal |
# bracketed_literal | text;
# literal | text;
#
defp markup(parser, tokens) do
markups = [
&blockquote/2, &spoiler/2, &link/2, &image/2, &bold/2, &italic/2, &strong/2,
&emphasis/2, &code/2, &inserted/2, &superscript/2, &deleted/2, &subscript/2,
&newline/2, &literal/2, &bracketed_literal/2, &text/2
&newline/2, &literal/2, &literal/2, &text/2
]
value =
@ -305,16 +305,9 @@ defmodule Textile.Parser do
do: {:error, "Expected a line break"}
defp bracketed_literal(_parser, [{:bracketed_literal, text} | r_tokens]),
do: {:ok, [markup: escape_nl2br(text)], r_tokens}
defp bracketed_literal(_parser, _tokens),
do: {:error, "Expected a bracketed literal"}
defp text(_parser, [{:text, text} | r_tokens]),
do: {:ok, [text: escape_nl2br(text)], r_tokens}
defp text(_parser, _tokens),
do: {:error, "Expected text"}
end
end