From ddcb17f91fadf6006bcd74f292c5065162df8a83 Mon Sep 17 00:00:00 2001 From: Aleksei Matiushkin Date: Sat, 1 Jul 2023 09:48:04 +0200 Subject: [PATCH] Example of `Listener` changing state --- lib/md/listener.ex | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/md/listener.ex b/lib/md/listener.ex index 3e17ec3..b71ebba 100644 --- a/lib/md/listener.ex +++ b/lib/md/listener.ex @@ -118,3 +118,17 @@ defmodule Md.Listener.Debug do @moduledoc false use Md.Listener end + +defmodule Md.Listener.Beautifier do + @moduledoc false + use Md.Listener + + alias Md.Parser.State + + def handle_tag({:p, false}, %State{ast: [{:p, attrs, [title]}]} = state) + when byte_size(title) < 42 do + {:update, %State{state | ast: [{:h1, attrs, [title]}]}} + end + + def handle_tag(_, _), do: :ok +end