Add missing annotation to Erlang snippets in Markdown cells on export

This commit is contained in:
Jonatan Kłosko 2025-01-30 01:09:40 +07:00
parent ccb7c8fe0c
commit f3ec12d3d9
3 changed files with 22 additions and 23 deletions

View file

@ -321,7 +321,8 @@ defmodule Livebook.LiveMarkdown.Export do
defp add_markdown_annotation_before_elixir_block(ast) do
Enum.flat_map(ast, fn
{"pre", _, [{"code", [{"class", "elixir"}], [_source], %{}}], %{}} = ast_node ->
{"pre", _, [{"code", [{"class", language}], [_source], %{}}], %{}} = ast_node
when language in ["elixir", "erlang"] ->
[{:comment, [], [~s/livebook:{"force_markdown":true}/], %{comment: true}}, ast_node]
ast_node ->

View file

@ -232,7 +232,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
assert expected_document == document
end
test "keeps non-elixir code snippets" do
test "keeps non-code cell snippets" do
notebook = %{
Notebook.new()
| name: "My Notebook",
@ -248,8 +248,8 @@ defmodule Livebook.LiveMarkdown.ExportTest do
mix deps.get
```
```erlang
spawn_link(fun() -> io:format("Hiya") end).
```json
{"x": 1, "y": 1}
```
"""
}
@ -267,8 +267,8 @@ defmodule Livebook.LiveMarkdown.ExportTest do
mix deps.get
```
```erlang
spawn_link(fun() -> io:format("Hiya") end).
```json
{"x": 1, "y": 1}
```
"""
@ -277,7 +277,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
assert expected_document == document
end
test "marks elixir snippets in markdown cells as such" do
test "marks code cell snippets in markdown cells as such" do
notebook = %{
Notebook.new()
| name: "My Notebook",
@ -305,8 +305,8 @@ defmodule Livebook.LiveMarkdown.ExportTest do
| source: """
Some markdown.
```elixir
[1, 2, 3]
```erlang
[1, 2, 3].
```\
"""
}
@ -332,8 +332,8 @@ defmodule Livebook.LiveMarkdown.ExportTest do
<!-- livebook:{"force_markdown":true} -->
```elixir
[1, 2, 3]
```erlang
[1, 2, 3].
```
"""

View file

@ -373,7 +373,7 @@ defmodule Livebook.LiveMarkdown.ImportTest do
assert ["line 3 - closing unclosed backquotes ` at end of input"] == messages
end
test "imports non-elixir code snippets as part of markdown cells" do
test "imports non-code cell snippets as part of markdown cells" do
markdown = """
# My Notebook
@ -387,10 +387,8 @@ defmodule Livebook.LiveMarkdown.ImportTest do
Enum.to_list(1..10)
```
<!-- livebook:{"force_markdown":true} -->
```erlang
spawn_link(fun() -> io:format("Hiya") end).
```json
{"x": 1, "y": 1}
```
"""
@ -416,8 +414,8 @@ defmodule Livebook.LiveMarkdown.ImportTest do
},
%Cell.Markdown{
source: """
```erlang
spawn_link(fun() -> io:format("Hiya") end).
```json
{"x": 1, "y": 1}
```\
"""
}
@ -427,7 +425,7 @@ defmodule Livebook.LiveMarkdown.ImportTest do
} = notebook
end
test "imports elixir snippets as part of markdown cells if marked as such" do
test "imports code cell snippets as part of markdown cells if marked as such" do
markdown = """
# My Notebook
@ -445,8 +443,8 @@ defmodule Livebook.LiveMarkdown.ImportTest do
<!-- livebook:{"force_markdown":true} -->
```elixir
[1, 2, 3]
```erlang
[1, 2, 3].
```
"""
@ -474,8 +472,8 @@ defmodule Livebook.LiveMarkdown.ImportTest do
source: """
Some markdown.
```elixir
[1, 2, 3]
```erlang
[1, 2, 3].
```\
"""
}