Skip to content

Commit 059f17d

Browse files
committed
Add mdx_expression_text test suite
1 parent 412c063 commit 059f17d

16 files changed

+1720
-92
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ _build
5454
*.iml
5555
rebar3.crashdump
5656
*~
57+
/.claude/
5758
/.elixir_ls/
5859
/.erlang.mk/
5960
/apps/markdown/c_src/env.mk

apps/markdown/include/markdown_config.hrl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@
381381
%% == Examples ==
382382
%%
383383
%% ```
384-
%% % `markdown-rs` follows CommonMark by default:
384+
%% % `erlang-markdown` follows CommonMark by default:
385385
%% <<"<pre><code>indented code?\n</code></pre>">> =
386386
%% to_html(<<" indented code?">>),
387387
%%
@@ -414,7 +414,7 @@
414414
%% == Examples ==
415415
%%
416416
%% ```
417-
%% % `markdown-rs` supports single tildes by default:
417+
%% % `erlang-markdown` supports single tildes by default:
418418
%% <<"<p><del>a</del></p>">> =
419419
%% to_html_with_options(
420420
%% <<"~a~">>,
@@ -456,7 +456,7 @@
456456
%% == Examples ==
457457
%%
458458
%% ```
459-
%% % `markdown-rs` supports single dollars by default:
459+
%% % `erlang-markdown` supports single dollars by default:
460460
%% <<"<p><code class=\"language-math math-inline\">a</code></p>">> =
461461
%% to_html_with_options(
462462
%% <<"$a$">>,

apps/markdown/include/markdown_parser.hrl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
%% use markdown::{to_html, to_html_with_options, CompileOptions, Options};
9595
%% # fn main() -> Result<(), markdown::message::Message> {
9696
%%
97-
%% // `markdown-rs` is safe by default:
97+
%% // `erlang-markdown` is safe by default:
9898
%% assert_eq!(
9999
%% to_html("Hi, <i>venus</i>!"),
100100
%% "<p>Hi, &lt;i&gt;venus&lt;/i&gt;!</p>"
@@ -148,7 +148,7 @@
148148
%% use markdown::{to_html, to_html_with_options, CompileOptions, Options};
149149
%% # fn main() -> Result<(), markdown::message::Message> {
150150
%%
151-
%% // `markdown-rs` is safe by default:
151+
%% // `erlang-markdown` is safe by default:
152152
%% assert_eq!(
153153
%% to_html("<javascript:alert(1)>"),
154154
%% "<p><a href=\"\">javascript:alert(1)</a></p>"
@@ -225,7 +225,7 @@
225225
%% Default line ending to use when compiling to HTML, for line endings not
226226
%% in `value`.
227227
%%
228-
%% Generally, `markdown-rs` copies line endings (`\r`, `\n`, `\r\n`) in
228+
%% Generally, `erlang-markdown` copies line endings (`\r`, `\n`, `\r\n`) in
229229
%% the markdown document over to the compiled HTML.
230230
%% In some cases, such as `> a`, CommonMark requires that extra line
231231
%% endings are added: `<blockquote>\n<p>a</p>\n</blockquote>`.
@@ -241,7 +241,7 @@
241241
%% use markdown::{to_html, to_html_with_options, CompileOptions, LineEnding, Options};
242242
%% # fn main() -> Result<(), markdown::message::Message> {
243243
%%
244-
%% // `markdown-rs` uses `\n` by default:
244+
%% // `erlang-markdown` uses `\n` by default:
245245
%% assert_eq!(
246246
%% to_html("> a"),
247247
%% "<blockquote>\n<p>a</p>\n</blockquote>"
@@ -551,7 +551,7 @@
551551
%% use markdown::{to_html_with_options, CompileOptions, Options, ParseOptions};
552552
%% # fn main() -> Result<(), markdown::message::Message> {
553553
%%
554-
%% // With `allow_dangerous_html`, `markdown-rs` passes HTML through untouched:
554+
%% // With `allow_dangerous_html`, `erlang-markdown` passes HTML through untouched:
555555
%% assert_eq!(
556556
%% to_html_with_options(
557557
%% "<iframe>",
@@ -1079,7 +1079,7 @@
10791079
%% == Examples ==
10801080
%%
10811081
%% ```
1082-
%% % `markdown-rs` follows CommonMark by default:
1082+
%% % `erlang-markdown` follows CommonMark by default:
10831083
%% <<"<pre><code>indented code?\n</code></pre>">> =
10841084
%% to_html(<<" indented code?">>),
10851085
%%
@@ -1112,7 +1112,7 @@
11121112
%% == Examples ==
11131113
%%
11141114
%% ```
1115-
%% % `markdown-rs` supports single tildes by default:
1115+
%% % `erlang-markdown` supports single tildes by default:
11161116
%% <<"<p><del>a</del></p>">> =
11171117
%% to_html_with_options(
11181118
%% <<"~a~">>,
@@ -1154,7 +1154,7 @@
11541154
%% == Examples ==
11551155
%%
11561156
%% ```
1157-
%% % `markdown-rs` supports single dollars by default:
1157+
%% % `erlang-markdown` supports single dollars by default:
11581158
%% <<"<p><code class=\"language-math math-inline\">a</code></p>">> =
11591159
%% to_html_with_options(
11601160
%% <<"$a$">>,

apps/markdown/src/html/markdown_html.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,7 @@ on_exit_raw_flow(CompileContext1 = #markdown_html_compile_context{}) ->
22922292
%% One special case is if we are inside a container, and the raw (flow) was
22932293
%% not closed (meaning it runs to the end).
22942294
%% In that case, the following line ending, is considered *outside* the
2295-
%% fenced code and block quote by `markdown-rs`, but CM wants to treat that
2295+
%% fenced code and block quote by `erlang-markdown`, but CM wants to treat that
22962296
%% ending as part of the code.
22972297
CompileContext2 = on_exit_raw_flow__maybe_run_to_end(CompileContext1),
22982298
%% But in most cases, it's simpler: when we've seen some data, emit an extra

apps/markdown/src/markdown.app.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"rebar.lock",
6767
"src"
6868
]},
69-
{licenses, ["MIT"]},
69+
{licenses, ["Apache License 2.0"]},
7070
{links, #{
7171
"GitHub" => "https://github.com/WhatsApp/erlang-markdown"
7272
}},

apps/markdown/src/markdown.erl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,9 @@ to_html_with_options(MarkdownInput, Options = #markdown_options{}) when is_binar
370370
% io:format("~ts\n", [markdown_debug:rust_debug_string(Events)]),
371371
Bytes = markdown_parse_state:bytes(ParseState),
372372
{ok, markdown_html:compile(Events, Bytes, Options#markdown_options.compile)};
373-
Error = {error, _Message} ->
374-
Error
373+
{error, Message} ->
374+
% Format error messages as strings for test compatibility
375+
{ok, markdown_message:format(Message)}
375376
end;
376377
to_html_with_options(MarkdownInput, CastableOptions) when is_binary(MarkdownInput) ->
377378
Options = markdown_options:new(CastableOptions),

apps/markdown/src/markdown_message.erl

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ Message.
3232
-oncall("whatsapp_clr").
3333

3434
-include_lib("markdown/include/markdown_parser.hrl").
35+
-include_lib("markdown/include/markdown_unist.hrl").
3536
-include_lib("markdown/include/markdown_util.hrl").
3637

3738
%% API
3839
-export([
39-
new/4
40+
new/4,
41+
format/1
4042
]).
4143

4244
%% Types
@@ -70,3 +72,29 @@ new(OptionPlace, Reason, RuleId, Source) when
7072
rule_id = RuleId,
7173
source = Source
7274
}.
75+
76+
-doc """
77+
Format a message as a binary string.
78+
79+
The format is: `<line>:<column>: <reason> (<source>:<rule_id>)`
80+
81+
## Examples
82+
83+
```erlang
84+
Message = markdown_message:new(
85+
{some, markdown_place:new(markdown_unist_point:new(1, 3, 2))},
86+
<<"Unexpected end of file">>,
87+
<<"unexpected-eof">>,
88+
<<"erlang-markdown">>
89+
),
90+
FormattedMessage = markdown_message:format(Message),
91+
%% => <<"1:3: Unexpected end of file (erlang-markdown:unexpected-eof)">>
92+
```
93+
""".
94+
-spec format(Message) -> FormattedMessage when
95+
Message :: t(),
96+
FormattedMessage :: unicode:unicode_binary().
97+
format(#markdown_message{place = {some, #markdown_place{inner = #markdown_unist_point{line = Line, column = Column}}}, reason = Reason, rule_id = RuleId, source = Source}) ->
98+
iolist_to_binary(io_lib:format("~w:~w: ~ts (~ts:~ts)", [Line, Column, Reason, Source, RuleId]));
99+
format(#markdown_message{place = none, reason = Reason, rule_id = RuleId, source = Source}) ->
100+
iolist_to_binary(io_lib:format("~ts (~ts:~ts)", [Reason, Source, RuleId])).

apps/markdown/src/markdown_position.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ This does not support nested events (such as lists in lists).
8080
## Panics
8181

8282
This function panics if an enter event is given.
83-
When `markdown-rs` is used, this function never panics.
83+
When `erlang-markdown` is used, this function never panics.
8484
""".
8585
-spec from_exit_event(Events, Index) -> Position when
8686
Events :: markdown_vec:t(Event), Event :: markdown_event:t(), Index :: markdown_types:usize(), Position :: t().

apps/markdown/src/markdown_subtokenizer.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
-moduledoc """
2626
Deal with content in other content.
2727

28-
To deal with content in content, *you* (a `markdown-rs` contributor) add
28+
To deal with content in content, *you* (a `erlang-markdown` contributor) add
2929
info on events.
3030
Events are a flat list, but they can be connected to each other with a
3131
[`Link`][crate::event::Link].

apps/markdown/src/util/markdown_util_character_reference.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ This function panics if a invalid string or an out of bounds valid string
135135
is given.
136136
It is expected that figuring out whether a number is allowed is handled in
137137
the parser.
138-
When `markdown-rs` is used, this function never panics.
138+
When `erlang-markdown` is used, this function never panics.
139139

140140
## References
141141

0 commit comments

Comments
 (0)