From 3012de58b67d2888506957a2e793dc6f7837f91a Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Mon, 16 Dec 2019 00:59:25 -0500 Subject: [PATCH] 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 --- lib/textile/helpers.ex | 2 +- lib/textile/lexer.ex | 21 ++++++++++++++++----- lib/textile/markup_lexer.ex | 4 ++-- lib/textile/parser.ex | 13 +++---------- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/textile/helpers.ex b/lib/textile/helpers.ex index ecf54950..e874e4c3 100644 --- a/lib/textile/helpers.ex +++ b/lib/textile/helpers.ex @@ -38,4 +38,4 @@ defmodule Textile.Helpers do end defp binary_head(<>), do: <> -end \ No newline at end of file +end diff --git a/lib/textile/lexer.ex b/lib/textile/lexer.ex index 7835b5ce..ab37a295 100644 --- a/lib/textile/lexer.ex +++ b/lib/textile/lexer.ex @@ -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, diff --git a/lib/textile/markup_lexer.ex b/lib/textile/markup_lexer.ex index b8012066..8c839011 100644 --- a/lib/textile/markup_lexer.ex +++ b/lib/textile/markup_lexer.ex @@ -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 \ No newline at end of file +end diff --git a/lib/textile/parser.ex b/lib/textile/parser.ex index 82316d48..1b1cfa69 100644 --- a/lib/textile/parser.ex +++ b/lib/textile/parser.ex @@ -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 \ No newline at end of file +end