popdoc: parse iex-popcorn blocks in markdown (3/5) - #697
Open
mmietla wants to merge 1 commit into
Open
Conversation
mmietla
force-pushed
the
popdoc-markdown-iex
branch
2 times, most recently
from
July 23, 2026 14:02
67b70a0 to
1aaac47
Compare
mmietla
force-pushed
the
popdoc-markdown-iex
branch
from
July 27, 2026 14:05
1aaac47 to
415aade
Compare
jgonet
reviewed
Jul 28, 2026
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 |
Member
There was a problem hiding this comment.
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]) |
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 |
Member
There was a problem hiding this comment.
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)} |
Member
There was a problem hiding this comment.
This feels like it mixes a lot of abstraction. What about:
type(code_attrs) -> :iex | :code_block | :otheradd_data(attrs, key, value)- call
normalize_code_attrsafter the cond/case block (maybe with rename todedup())
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.