philomena/lib/textile/token_coalescer.ex

15 lines
359 B
Elixir
Raw Normal View History

2019-11-04 01:35:04 +01:00
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
2019-11-09 02:43:38 +01:00
end)
2019-11-04 01:35:04 +01:00
end
end