Fix markdown line breaks rendering (#227)

This commit is contained in:
Jonatan Kłosko 2021-04-20 19:31:02 +02:00 committed by GitHub
parent 6b5de9eda5
commit 44eda43d02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View file

@ -99,6 +99,12 @@ defmodule Livebook.LiveMarkdown.MarkdownHelpers do
|> build_md(ast)
end
defp build_md(iodata, [{"br", _, [], %{}} | ast]) do
render_line_break()
|> append_inline(iodata)
|> build_md(ast)
end
defp build_md(iodata, [{"p", _, content, %{}} | ast]) do
render_paragraph(content)
|> append_block(iodata)
@ -225,6 +231,8 @@ defmodule Livebook.LiveMarkdown.MarkdownHelpers do
end
end
defp render_line_break(), do: "\\\n"
defp render_paragraph(content), do: markdown_from_ast(content)
defp render_heading(n, content) do

View file

@ -98,6 +98,9 @@ defmodule Livebook.LiveMarkdown.ImportTest do
## Section 1
Line 1.\s\s
Line 2.
|State|Abbrev|Capital|
| --: | :-: | --- |
| Texas | TX | Austin |
@ -117,6 +120,9 @@ defmodule Livebook.LiveMarkdown.ImportTest do
type: :markdown,
metadata: %{},
source: """
Line 1.\\
Line 2.
| State | Abbrev | Capital |
| ----: | :----: | ------- |
| Texas | TX | Austin |