mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-30 14:57:59 +01:00
add coalescer
This commit is contained in:
parent
9cfc426103
commit
43217607cd
2 changed files with 24 additions and 0 deletions
|
@ -5,6 +5,13 @@ defmodule Textile.MarkupLexer do
|
||||||
# Markup tags
|
# Markup tags
|
||||||
|
|
||||||
def markup_ending_in(ending_sequence) do
|
def markup_ending_in(ending_sequence) do
|
||||||
|
double_newline =
|
||||||
|
string("\n\n")
|
||||||
|
|> unwrap_and_tag(:double_newline)
|
||||||
|
|
||||||
|
newline =
|
||||||
|
string("\n")
|
||||||
|
|> unwrap_and_tag(:newline)
|
||||||
|
|
||||||
# The literal tag is special, because
|
# The literal tag is special, because
|
||||||
# 1. It needs to capture everything inside it as a distinct token.
|
# 1. It needs to capture everything inside it as a distinct token.
|
||||||
|
@ -147,6 +154,8 @@ defmodule Textile.MarkupLexer do
|
||||||
bracketed_markup_opening_tags |> lookahead_not(space()),
|
bracketed_markup_opening_tags |> lookahead_not(space()),
|
||||||
special_characters() |> concat(markup_opening_tags),
|
special_characters() |> concat(markup_opening_tags),
|
||||||
markup_closing_tags |> choice([special_characters(), ending_sequence]),
|
markup_closing_tags |> choice([special_characters(), ending_sequence]),
|
||||||
|
double_newline,
|
||||||
|
newline,
|
||||||
utf8_char([])
|
utf8_char([])
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
15
lib/textile/token_coalescer.ex
Normal file
15
lib/textile/token_coalescer.ex
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
defmodule Textile.TokenCoalescer do
|
||||||
|
# The lexer, as a practical concern, does not coalesce runs of
|
||||||
|
# character tokens. This fixes that.
|
||||||
|
def coalesce(tokens) do
|
||||||
|
tokens
|
||||||
|
|> Enum.chunk_by(&is_number(&1))
|
||||||
|
|> Enum.flat_map(fn
|
||||||
|
[t | _rest] = str when is_number(t) ->
|
||||||
|
[text: List.to_string(str)]
|
||||||
|
|
||||||
|
t ->
|
||||||
|
t
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue