Skip to content

Commit

Permalink
render <br/> directly as hard-line-break
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesKaufmann committed Dec 25, 2024
1 parent 5493558 commit e40d875
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 18 deletions.
2 changes: 1 addition & 1 deletion plugin/commonmark/commonmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func TestOptionFunc(t *testing.T) {
commonmark.WithHeadingStyle("setext"),
},
input: `<h1>important<br/>heading</h1>`,
expected: "important\n\\\nheading\n=========",
expected: "important\nheading\n=========",
},

// - - - - - - - - - - Link - - - - - - - - - - //
Expand Down
8 changes: 5 additions & 3 deletions plugin/commonmark/render_break.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package commonmark

import (
"github.com/JohannesKaufmann/html-to-markdown/v2/converter"
"github.com/JohannesKaufmann/html-to-markdown/v2/marker"
"golang.org/x/net/html"
)

func (c *commonmark) renderBreak(_ converter.Context, w converter.Writer, _ *html.Node) converter.RenderStatus {
w.Write(marker.BytesMarkerLineBreak)
w.Write(marker.BytesMarkerLineBreak)
// w.Write(marker.BytesMarkerLineBreak)
// w.Write(marker.BytesMarkerLineBreak)
// w.WriteString("\n")

w.WriteString(" \n")
return converter.RenderSuccess
}
9 changes: 8 additions & 1 deletion plugin/commonmark/testdata/GoldenFiles/blockquote.out.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@
<!--with one break-->

> Line A
Line B
> Line B
<!--with multiple breaks-->

> Start Line
>
>
>
>
>
>
>
>
> End Line
<!--large blockquote-->
Expand Down
3 changes: 0 additions & 3 deletions plugin/commonmark/testdata/GoldenFiles/heading.out.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,14 @@ not title
* * *

> [**Heading 2**
> \
> **Heading 5**](/page.html)
* * *

> [**Heading 2**
> \
> Description Line 1
> \
> Description Line 2
> \
> Description Line 3
> \
> "Some quote"](/page.html)
Expand Down
2 changes: 1 addition & 1 deletion plugin/commonmark/testdata/GoldenFiles/image.out.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

<!--image inside a link-->

[![image alt text](/image.jpg "image title text")](/page.html "link title text")
[![image alt text](/image.jpg "image title text")](/page.html "link title text")

<!--image inside an empty link-->

Expand Down
27 changes: 25 additions & 2 deletions plugin/commonmark/testdata/GoldenFiles/link.out.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,39 @@ before [content](/) after

[Start Line
\
\
\
\
\
\
\
\
End Line](/)

<!--newlines inside link-->





[newlines around the link content](/)





<!--multiline link inside a list item-->

- [first text
\
\
\
\
\
\
\
\
\
\
second text](/)

Expand All @@ -170,8 +194,7 @@ second text](/page.html)
<!--link with headings-->

[**Heading A**
\
**Heading B**](/page.html)
**Heading B**](/page.html)

<!--link with an svg-->

Expand Down
17 changes: 12 additions & 5 deletions plugin/commonmark/testdata/GoldenFiles/list.out.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ A paragraph
- - 5.1

5 After
- 6 Before

- 6 Before
6 also Before

- 6A.1
Expand Down Expand Up @@ -56,9 +55,8 @@ List Item without Container

<!-- list with blockquote that contains break -->

1. > Line A
Line B
1. > Line A
> Line B
* * *

Expand Down Expand Up @@ -118,6 +116,8 @@ text between

<!--THE END-->



- List 7

* * *
Expand All @@ -136,6 +136,13 @@ text between

- Start Line








End Line

<!--------------------------------------
Expand Down
8 changes: 6 additions & 2 deletions plugin/commonmark/testdata/GoldenFiles/metadata.out.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ A &amp; B
\[foo]: /url "not a reference"
&amp;ouml; not a character entity

Start Line

Start Line





End Line

0 comments on commit e40d875

Please sign in to comment.