Skip to content

popdoc: parse iex-popcorn blocks in markdown (3/5) - #697

Open
mmietla wants to merge 1 commit into
popdoc-wasm-iexfrom
popdoc-markdown-iex
Open

popdoc: parse iex-popcorn blocks in markdown (3/5)#697
mmietla wants to merge 1 commit into
popdoc-wasm-iexfrom
popdoc-markdown-iex

Conversation

@mmietla

@mmietla mmietla commented Jul 23, 2026

Copy link
Copy Markdown
Member

Part 3/5 of the popdoc IEx integration. Part of #695

@mmietla
mmietla force-pushed the popdoc-markdown-iex branch 2 times, most recently from 67b70a0 to 1aaac47 Compare July 23, 2026 14:02
@mmietla mmietla changed the title popdoc: parse iex-popcorn blocks in markdown popdoc: parse iex-popcorn blocks in markdown (3/5) Jul 27, 2026
@mmietla
mmietla force-pushed the popdoc-markdown-iex branch from 1aaac47 to 415aade Compare July 27, 2026 14:05
Comment on lines +122 to +127
defp strip_prompt(line, prompt_re) do
case Regex.run(prompt_re, line) do
[prompt] -> String.replace_prefix(line, prompt, "")
nil -> nil
end
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like it could be Regex.replace if we change logic a bit and remove nil (which could improve rest of the code).

Comment on lines +134 to +135
Module.concat([ExDoc, Utils])
|> apply(:to_json, [commands])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we depend on ExDoc?

Comment on lines +105 to +115
cond do
code = strip_prompt(trimmed, @iex_prompt_re) ->
acc = if current != nil, do: [current | commands], else: commands
{acc, code}

(cont = strip_prompt(trimmed, @cont_prompt_re)) && current != nil ->
{commands, current <> "\n" <> cont}

true ->
{commands, current}
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to change, assignments in cond, we use &&, and a lot of nils everywhere. Most likely this can be rewritten by tagging strip_prompt with different atoms.

Comment on lines +41 to +49
commands_json =
code_children |> extract_text() |> parse_iex_commands() |> commands_to_json()

new_pre_attrs =
pre_attrs
|> add_class(@iex_class)
|> Keyword.put(:"data-popcorn-iex-commands", commands_json)

{new_pre_attrs, normalize_code_attrs(code_attrs)}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like it mixes a lot of abstraction. What about:

  • type(code_attrs) -> :iex | :code_block | :other
  • add_data(attrs, key, value)
  • call normalize_code_attrs after the cond/case block (maybe with rename to dedup())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants