mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-17 19:14:22 +01:00
15 lines
356 B
Elixir
15 lines
356 B
Elixir
|
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
|