Repository: kovetskiy/mark
Pull request #484 (2024-08-12 12:15:30)

Fix paragraphs
This should fix the paragraph issue described in https://github.com/kovetskiy/mark/issues/480 reported by @trkas


Patch:
diff --git a/Dockerfile b/Dockerfile
index a5b0a3b..84490ac 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,4 @@
-FROM golang:1.22.5 as builder
+FROM golang:1.22.6 AS builder
 ENV GOPATH="/go"
 WORKDIR /go/src/github.com/kovetskiy/mark
 COPY / .
diff --git a/pkg/mark/renderer/paragraph.go b/pkg/mark/renderer/paragraph.go
index df9bc49..49c69a1 100644
--- a/pkg/mark/renderer/paragraph.go
+++ b/pkg/mark/renderer/paragraph.go
@@ -24,7 +24,20 @@ func (r *ConfluenceParagraphRenderer) RegisterFuncs(reg renderer.NodeRendererFun
 }
 
 func (r *ConfluenceParagraphRenderer) renderParagraph(w util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error) {
-	if !entering {
+	if entering {
+		if n.FirstChild().Kind() != ast.KindRawHTML {
+			if n.Attributes() != nil {
+				_, _ = w.WriteString("<p")
+				html.RenderAttributes(w, n, html.ParagraphAttributeFilter)
+				_ = w.WriteByte('>')
+			} else {
+				_, _ = w.WriteString("<p>")
+			}
+		}
+	} else {
+		if n.FirstChild().Kind() != ast.KindRawHTML {
+			_, _ = w.WriteString("</p>")
+		}
 		_, _ = w.WriteString("\n")
 	}
 	return ast.WalkContinue, nil


Test patch:
diff --git a/pkg/mark/testdata/codes-droph1.html b/pkg/mark/testdata/codes-droph1.html
index bcf5be7..733410b 100644
--- a/pkg/mark/testdata/codes-droph1.html
+++ b/pkg/mark/testdata/codes-droph1.html
@@ -1,7 +1,7 @@
-<code>inline</code>
+<p><code>inline</code></p>
 <ac:structured-macro ac:name="code"><ac:parameter ac:name="language"></ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[some code]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">bash</ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[code bash]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">bash</ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[with a newline
-]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">unknown</ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[unknown code]]></ac:plain-text-body></ac:structured-macro>text
-text 2
+]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">unknown</ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[unknown code]]></ac:plain-text-body></ac:structured-macro><p>text
+text 2</p>
 <ac:structured-macro ac:name="code"><ac:parameter ac:name="language">unknown</ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[unknown code 2]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">sh</ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:parameter ac:name="title">A b c</ac:parameter><ac:plain-text-body><![CDATA[no-collapse-title]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">bash</ac:parameter><ac:parameter ac:name="collapse">true</ac:parameter><ac:parameter ac:name="title">A b c</ac:parameter><ac:plain-text-body><![CDATA[collapse-and-title]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">c</ac:parameter><ac:parameter ac:name="collapse">true</ac:parameter><ac:plain-text-body><![CDATA[collapse-no-title]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">nested</ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[code
 ``` more code ```
 even more code]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language"></ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[indented code block
diff --git a/pkg/mark/testdata/codes-stripnewlines.html b/pkg/mark/testdata/codes-stripnewlines.html
index 35097f5..63eff28 100644
--- a/pkg/mark/testdata/codes-stripnewlines.html
+++ b/pkg/mark/testdata/codes-stripnewlines.html
@@ -1,6 +1,6 @@
-<code>inline</code>
+<p><code>inline</code></p>
 <ac:structured-macro ac:name="code"><ac:parameter ac:name="language"></ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[some code]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">bash</ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[code bash]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">bash</ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[with a newline
-]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">unknown</ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[unknown code]]></ac:plain-text-body></ac:structured-macro>text text 2
+]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">unknown</ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[unknown code]]></ac:plain-text-body></ac:structured-macro><p>text text 2</p>
 <ac:structured-macro ac:name="code"><ac:parameter ac:name="language">unknown</ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[unknown code 2]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">sh</ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:parameter ac:name="title">A b c</ac:parameter><ac:plain-text-body><![CDATA[no-collapse-title]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">bash</ac:parameter><ac:parameter ac:name="collapse">true</ac:parameter><ac:parameter ac:name="title">A b c</ac:parameter><ac:plain-text-body><![CDATA[collapse-and-title]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">c</ac:parameter><ac:parameter ac:name="collapse">true</ac:parameter><ac:plain-text-body><![CDATA[collapse-no-title]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">nested</ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[code
 ``` more code ```
 even more code]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language"></ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[indented code block
diff --git a/pkg/mark/testdata/codes.html b/pkg/mark/testdata/codes.html
index bcf5be7..733410b 100644
--- a/pkg/mark/testdata/codes.html
+++ b/pkg/mark/testdata/codes.html
@@ -1,7 +1,7 @@
-<code>inline</code>
+<p><code>inline</code></p>
 <ac:structured-macro ac:name="code"><ac:parameter ac:name="language"></ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[some code]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">bash</ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[code bash]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">bash</ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[with a newline
-]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">unknown</ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[unknown code]]></ac:plain-text-body></ac:structured-macro>text
-text 2
+]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">unknown</ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[unknown code]]></ac:plain-text-body></ac:structured-macro><p>text
+text 2</p>
 <ac:structured-macro ac:name="code"><ac:parameter ac:name="language">unknown</ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[unknown code 2]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">sh</ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:parameter ac:name="title">A b c</ac:parameter><ac:plain-text-body><![CDATA[no-collapse-title]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">bash</ac:parameter><ac:parameter ac:name="collapse">true</ac:parameter><ac:parameter ac:name="title">A b c</ac:parameter><ac:plain-text-body><![CDATA[collapse-and-title]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">c</ac:parameter><ac:parameter ac:name="collapse">true</ac:parameter><ac:plain-text-body><![CDATA[collapse-no-title]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language">nested</ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[code
 ``` more code ```
 even more code]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="code"><ac:parameter ac:name="language"></ac:parameter><ac:parameter ac:name="collapse">false</ac:parameter><ac:plain-text-body><![CDATA[indented code block
diff --git a/pkg/mark/testdata/issue-64-broken-link-droph1.html b/pkg/mark/testdata/issue-64-broken-link-droph1.html
index dca9603..0d39ce8 100644
--- a/pkg/mark/testdata/issue-64-broken-link-droph1.html
+++ b/pkg/mark/testdata/issue-64-broken-link-droph1.html
@@ -1,1 +1,1 @@
-<a href="Page2#Page2-Releasev71-22-Feb-2018(intern)">v71</a>
+<p><a href="Page2#Page2-Releasev71-22-Feb-2018(intern)">v71</a></p>
diff --git a/pkg/mark/testdata/issue-64-broken-link-stripnewlines.html b/pkg/mark/testdata/issue-64-broken-link-stripnewlines.html
index dca9603..0d39ce8 100644
--- a/pkg/mark/testdata/issue-64-broken-link-stripnewlines.html
+++ b/pkg/mark/testdata/issue-64-broken-link-stripnewlines.html
@@ -1,1 +1,1 @@
-<a href="Page2#Page2-Releasev71-22-Feb-2018(intern)">v71</a>
+<p><a href="Page2#Page2-Releasev71-22-Feb-2018(intern)">v71</a></p>
diff --git a/pkg/mark/testdata/issue-64-broken-link.html b/pkg/mark/testdata/issue-64-broken-link.html
index dca9603..0d39ce8 100644
--- a/pkg/mark/testdata/issue-64-broken-link.html
+++ b/pkg/mark/testdata/issue-64-broken-link.html
@@ -1,1 +1,1 @@
-<a href="Page2#Page2-Releasev71-22-Feb-2018(intern)">v71</a>
+<p><a href="Page2#Page2-Releasev71-22-Feb-2018(intern)">v71</a></p>
diff --git a/pkg/mark/testdata/links-droph1.html b/pkg/mark/testdata/links-droph1.html
index 6160135..d9ca603 100644
--- a/pkg/mark/testdata/links-droph1.html
+++ b/pkg/mark/testdata/links-droph1.html
@@ -1,21 +1,21 @@
-Use <a href="https://example.com">https://example.com</a>
-Use <ac:rich-text-body>aaa</ac:rich-text-body>
-Use <ac:link><ri:page ri:content-title="Page"/><ac:plain-text-link-body><![CDATA[page link]]></ac:plain-text-link-body></ac:link>
-Use <ac:link><ri:page ri:content-title="AnotherPage"/><ac:plain-text-link-body><![CDATA[AnotherPage]]></ac:plain-text-link-body></ac:link>
-Use <ac:link><ri:page ri:content-title="Another Page"/><ac:plain-text-link-body><![CDATA[Another Page]]></ac:plain-text-link-body></ac:link>
-Use <ac:link><ri:page ri:content-title="test_link"/><ac:plain-text-link-body><![CDATA[Another Page]]></ac:plain-text-link-body></ac:link>
-Use <ac:link><ri:page ri:content-title="Page With Space"/><ac:plain-text-link-body><![CDATA[page link with spaces]]></ac:plain-text-link-body></ac:link>
-<ac:image ac:alt="My Image"><ri:attachment ri:filename="test.png"/></ac:image>
-<ac:image ac:alt="My External Image"><ri:url ri:value="http://confluence.atlassian.com/images/logo/confluence_48_trans.png?key1=value1&amp;key2=value2"/></ac:image>
-<ac:link><ri:page ri:content-title="test_link"/><ac:plain-text-link-body><![CDATA[My test_link]]></ac:plain-text-link-body></ac:link>
-<ac:link><ri:page ri:content-title="test_link_link"/><ac:plain-text-link-body><![CDATA[Another [Link]]]></ac:plain-text-link-body></ac:link>
-Use footnotes link <sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup>
-Use <a href="foo">Link [Text]</a>
+<p>Use <a href="https://example.com">https://example.com</a></p>
+<p>Use <ac:rich-text-body>aaa</ac:rich-text-body></p>
+<p>Use <ac:link><ri:page ri:content-title="Page"/><ac:plain-text-link-body><![CDATA[page link]]></ac:plain-text-link-body></ac:link></p>
+<p>Use <ac:link><ri:page ri:content-title="AnotherPage"/><ac:plain-text-link-body><![CDATA[AnotherPage]]></ac:plain-text-link-body></ac:link></p>
+<p>Use <ac:link><ri:page ri:content-title="Another Page"/><ac:plain-text-link-body><![CDATA[Another Page]]></ac:plain-text-link-body></ac:link></p>
+<p>Use <ac:link><ri:page ri:content-title="test_link"/><ac:plain-text-link-body><![CDATA[Another Page]]></ac:plain-text-link-body></ac:link></p>
+<p>Use <ac:link><ri:page ri:content-title="Page With Space"/><ac:plain-text-link-body><![CDATA[page link with spaces]]></ac:plain-text-link-body></ac:link></p>
+<p><ac:image ac:alt="My Image"><ri:attachment ri:filename="test.png"/></ac:image></p>
+<p><ac:image ac:alt="My External Image"><ri:url ri:value="http://confluence.atlassian.com/images/logo/confluence_48_trans.png?key1=value1&amp;key2=value2"/></ac:image></p>
+<p><ac:link><ri:page ri:content-title="test_link"/><ac:plain-text-link-body><![CDATA[My test_link]]></ac:plain-text-link-body></ac:link></p>
+<p><ac:link><ri:page ri:content-title="test_link_link"/><ac:plain-text-link-body><![CDATA[Another [Link]]]></ac:plain-text-link-body></ac:link></p>
+<p>Use footnotes link <sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup></p>
+<p>Use <a href="foo">Link [Text]</a></p>
 <div class="footnotes" role="doc-endnotes">
 <hr />
 <ol>
 <li id="fn:1">
-a footnote link&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a>
+<p>a footnote link&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
 </li>
 </ol>
 </div>
diff --git a/pkg/mark/testdata/links-stripnewlines.html b/pkg/mark/testdata/links-stripnewlines.html
index 6160135..d9ca603 100644
--- a/pkg/mark/testdata/links-stripnewlines.html
+++ b/pkg/mark/testdata/links-stripnewlines.html
@@ -1,21 +1,21 @@
-Use <a href="https://example.com">https://example.com</a>
-Use <ac:rich-text-body>aaa</ac:rich-text-body>
-Use <ac:link><ri:page ri:content-title="Page"/><ac:plain-text-link-body><![CDATA[page link]]></ac:plain-text-link-body></ac:link>
-Use <ac:link><ri:page ri:content-title="AnotherPage"/><ac:plain-text-link-body><![CDATA[AnotherPage]]></ac:plain-text-link-body></ac:link>
-Use <ac:link><ri:page ri:content-title="Another Page"/><ac:plain-text-link-body><![CDATA[Another Page]]></ac:plain-text-link-body></ac:link>
-Use <ac:link><ri:page ri:content-title="test_link"/><ac:plain-text-link-body><![CDATA[Another Page]]></ac:plain-text-link-body></ac:link>
-Use <ac:link><ri:page ri:content-title="Page With Space"/><ac:plain-text-link-body><![CDATA[page link with spaces]]></ac:plain-text-link-body></ac:link>
-<ac:image ac:alt="My Image"><ri:attachment ri:filename="test.png"/></ac:image>
-<ac:image ac:alt="My External Image"><ri:url ri:value="http://confluence.atlassian.com/images/logo/confluence_48_trans.png?key1=value1&amp;key2=value2"/></ac:image>
-<ac:link><ri:page ri:content-title="test_link"/><ac:plain-text-link-body><![CDATA[My test_link]]></ac:plain-text-link-body></ac:link>
-<ac:link><ri:page ri:content-title="test_link_link"/><ac:plain-text-link-body><![CDATA[Another [Link]]]></ac:plain-text-link-body></ac:link>
-Use footnotes link <sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup>
-Use <a href="foo">Link [Text]</a>
+<p>Use <a href="https://example.com">https://example.com</a></p>
+<p>Use <ac:rich-text-body>aaa</ac:rich-text-body></p>
+<p>Use <ac:link><ri:page ri:content-title="Page"/><ac:plain-text-link-body><![CDATA[page link]]></ac:plain-text-link-body></ac:link></p>
+<p>Use <ac:link><ri:page ri:content-title="AnotherPage"/><ac:plain-text-link-body><![CDATA[AnotherPage]]></ac:plain-text-link-body></ac:link></p>
+<p>Use <ac:link><ri:page ri:content-title="Another Page"/><ac:plain-text-link-body><![CDATA[Another Page]]></ac:plain-text-link-body></ac:link></p>
+<p>Use <ac:link><ri:page ri:content-title="test_link"/><ac:plain-text-link-body><![CDATA[Another Page]]></ac:plain-text-link-body></ac:link></p>
+<p>Use <ac:link><ri:page ri:content-title="Page With Space"/><ac:plain-text-link-body><![CDATA[page link with spaces]]></ac:plain-text-link-body></ac:link></p>
+<p><ac:image ac:alt="My Image"><ri:attachment ri:filename="test.png"/></ac:image></p>
+<p><ac:image ac:alt="My External Image"><ri:url ri:value="http://confluence.atlassian.com/images/logo/confluence_48_trans.png?key1=value1&amp;key2=value2"/></ac:image></p>
+<p><ac:link><ri:page ri:content-title="test_link"/><ac:plain-text-link-body><![CDATA[My test_link]]></ac:plain-text-link-body></ac:link></p>
+<p><ac:link><ri:page ri:content-title="test_link_link"/><ac:plain-text-link-body><![CDATA[Another [Link]]]></ac:plain-text-link-body></ac:link></p>
+<p>Use footnotes link <sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup></p>
+<p>Use <a href="foo">Link [Text]</a></p>
 <div class="footnotes" role="doc-endnotes">
 <hr />
 <ol>
 <li id="fn:1">
-a footnote link&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a>
+<p>a footnote link&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
 </li>
 </ol>
 </div>
diff --git a/pkg/mark/testdata/links.html b/pkg/mark/testdata/links.html
index 6160135..d9ca603 100644
--- a/pkg/mark/testdata/links.html
+++ b/pkg/mark/testdata/links.html
@@ -1,21 +1,21 @@
-Use <a href="https://example.com">https://example.com</a>
-Use <ac:rich-text-body>aaa</ac:rich-text-body>
-Use <ac:link><ri:page ri:content-title="Page"/><ac:plain-text-link-body><![CDATA[page link]]></ac:plain-text-link-body></ac:link>
-Use <ac:link><ri:page ri:content-title="AnotherPage"/><ac:plain-text-link-body><![CDATA[AnotherPage]]></ac:plain-text-link-body></ac:link>
-Use <ac:link><ri:page ri:content-title="Another Page"/><ac:plain-text-link-body><![CDATA[Another Page]]></ac:plain-text-link-body></ac:link>
-Use <ac:link><ri:page ri:content-title="test_link"/><ac:plain-text-link-body><![CDATA[Another Page]]></ac:plain-text-link-body></ac:link>
-Use <ac:link><ri:page ri:content-title="Page With Space"/><ac:plain-text-link-body><![CDATA[page link with spaces]]></ac:plain-text-link-body></ac:link>
-<ac:image ac:alt="My Image"><ri:attachment ri:filename="test.png"/></ac:image>
-<ac:image ac:alt="My External Image"><ri:url ri:value="http://confluence.atlassian.com/images/logo/confluence_48_trans.png?key1=value1&amp;key2=value2"/></ac:image>
-<ac:link><ri:page ri:content-title="test_link"/><ac:plain-text-link-body><![CDATA[My test_link]]></ac:plain-text-link-body></ac:link>
-<ac:link><ri:page ri:content-title="test_link_link"/><ac:plain-text-link-body><![CDATA[Another [Link]]]></ac:plain-text-link-body></ac:link>
-Use footnotes link <sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup>
-Use <a href="foo">Link [Text]</a>
+<p>Use <a href="https://example.com">https://example.com</a></p>
+<p>Use <ac:rich-text-body>aaa</ac:rich-text-body></p>
+<p>Use <ac:link><ri:page ri:content-title="Page"/><ac:plain-text-link-body><![CDATA[page link]]></ac:plain-text-link-body></ac:link></p>
+<p>Use <ac:link><ri:page ri:content-title="AnotherPage"/><ac:plain-text-link-body><![CDATA[AnotherPage]]></ac:plain-text-link-body></ac:link></p>
+<p>Use <ac:link><ri:page ri:content-title="Another Page"/><ac:plain-text-link-body><![CDATA[Another Page]]></ac:plain-text-link-body></ac:link></p>
+<p>Use <ac:link><ri:page ri:content-title="test_link"/><ac:plain-text-link-body><![CDATA[Another Page]]></ac:plain-text-link-body></ac:link></p>
+<p>Use <ac:link><ri:page ri:content-title="Page With Space"/><ac:plain-text-link-body><![CDATA[page link with spaces]]></ac:plain-text-link-body></ac:link></p>
+<p><ac:image ac:alt="My Image"><ri:attachment ri:filename="test.png"/></ac:image></p>
+<p><ac:image ac:alt="My External Image"><ri:url ri:value="http://confluence.atlassian.com/images/logo/confluence_48_trans.png?key1=value1&amp;key2=value2"/></ac:image></p>
+<p><ac:link><ri:page ri:content-title="test_link"/><ac:plain-text-link-body><![CDATA[My test_link]]></ac:plain-text-link-body></ac:link></p>
+<p><ac:link><ri:page ri:content-title="test_link_link"/><ac:plain-text-link-body><![CDATA[Another [Link]]]></ac:plain-text-link-body></ac:link></p>
+<p>Use footnotes link <sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup></p>
+<p>Use <a href="foo">Link [Text]</a></p>
 <div class="footnotes" role="doc-endnotes">
 <hr />
 <ol>
 <li id="fn:1">
-a footnote link&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a>
+<p>a footnote link&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
 </li>
 </ol>
 </div>
diff --git a/pkg/mark/testdata/lists-droph1.html b/pkg/mark/testdata/lists-droph1.html
index 11aa2ca..af27c54 100644
--- a/pkg/mark/testdata/lists-droph1.html
+++ b/pkg/mark/testdata/lists-droph1.html
@@ -13,7 +13,7 @@
 </ul>
 </li>
 </ul>
-text
+<p>text</p>
 <ul>
 <li>a</li>
 <li>b</li>
diff --git a/pkg/mark/testdata/lists-stripnewlines.html b/pkg/mark/testdata/lists-stripnewlines.html
index 11aa2ca..af27c54 100644
--- a/pkg/mark/testdata/lists-stripnewlines.html
+++ b/pkg/mark/testdata/lists-stripnewlines.html
@@ -13,7 +13,7 @@
 </ul>
 </li>
 </ul>
-text
+<p>text</p>
 <ul>
 <li>a</li>
 <li>b</li>
diff --git a/pkg/mark/testdata/lists.html b/pkg/mark/testdata/lists.html
index 11aa2ca..af27c54 100644
--- a/pkg/mark/testdata/lists.html
+++ b/pkg/mark/testdata/lists.html
@@ -13,7 +13,7 @@
 </ul>
 </li>
 </ul>
-text
+<p>text</p>
 <ul>
 <li>a</li>
 <li>b</li>
diff --git a/pkg/mark/testdata/newlines-droph1.html b/pkg/mark/testdata/newlines-droph1.html
index 272fe20..b97e510 100644
--- a/pkg/mark/testdata/newlines-droph1.html
+++ b/pkg/mark/testdata/newlines-droph1.html
@@ -1,10 +1,10 @@
-one-1
-one-2
-two-1
-two-2
-three-1
-three-2
-space-1
-space-2
-2space-1<br />
-2space-2
+<p>one-1
+one-2</p>
+<p>two-1</p>
+<p>two-2</p>
+<p>three-1</p>
+<p>three-2</p>
+<p>space-1
+space-2</p>
+<p>2space-1<br />
+2space-2</p>
diff --git a/pkg/mark/testdata/newlines-stripnewlines.html b/pkg/mark/testdata/newlines-stripnewlines.html
index cca4996..2fd4dc0 100644
--- a/pkg/mark/testdata/newlines-stripnewlines.html
+++ b/pkg/mark/testdata/newlines-stripnewlines.html
@@ -1,8 +1,8 @@
-one-1 one-2
-two-1
-two-2
-three-1
-three-2
-space-1 space-2
-2space-1<br />
-2space-2
+<p>one-1 one-2</p>
+<p>two-1</p>
+<p>two-2</p>
+<p>three-1</p>
+<p>three-2</p>
+<p>space-1 space-2</p>
+<p>2space-1<br />
+2space-2</p>
diff --git a/pkg/mark/testdata/newlines.html b/pkg/mark/testdata/newlines.html
index 272fe20..b97e510 100644
--- a/pkg/mark/testdata/newlines.html
+++ b/pkg/mark/testdata/newlines.html
@@ -1,10 +1,10 @@
-one-1
-one-2
-two-1
-two-2
-three-1
-three-2
-space-1
-space-2
-2space-1<br />
-2space-2
+<p>one-1
+one-2</p>
+<p>two-1</p>
+<p>two-2</p>
+<p>three-1</p>
+<p>three-2</p>
+<p>space-1
+space-2</p>
+<p>2space-1<br />
+2space-2</p>
diff --git a/pkg/mark/testdata/pagelayout-droph1.html b/pkg/mark/testdata/pagelayout-droph1.html
index 23f17d5..a244202 100644
--- a/pkg/mark/testdata/pagelayout-droph1.html
+++ b/pkg/mark/testdata/pagelayout-droph1.html
@@ -1,18 +1,18 @@
 <ac:layout>
 <ac:layout-section ac:type="three_with_sidebars">
 <ac:layout-cell>
-More Content
+<p>More Content</p>
 </ac:layout-cell>
 <ac:layout-cell>
-More Content
+<p>More Content</p>
 </ac:layout-cell>
 <ac:layout-cell>
-Even More Content
+<p>Even More Content</p>
 </ac:layout-cell>
 </ac:layout-section>
 <ac:layout-section ac:type="single">
 <ac:layout-cell>
-Still More Content
+<p>Still More Content</p>
 </ac:layout-cell>
 </ac:layout-section>
 </ac:layout>
diff --git a/pkg/mark/testdata/pagelayout-stripnewlines.html b/pkg/mark/testdata/pagelayout-stripnewlines.html
index 23f17d5..a244202 100644
--- a/pkg/mark/testdata/pagelayout-stripnewlines.html
+++ b/pkg/mark/testdata/pagelayout-stripnewlines.html
@@ -1,18 +1,18 @@
 <ac:layout>
 <ac:layout-section ac:type="three_with_sidebars">
 <ac:layout-cell>
-More Content
+<p>More Content</p>
 </ac:layout-cell>
 <ac:layout-cell>
-More Content
+<p>More Content</p>
 </ac:layout-cell>
 <ac:layout-cell>
-Even More Content
+<p>Even More Content</p>
 </ac:layout-cell>
 </ac:layout-section>
 <ac:layout-section ac:type="single">
 <ac:layout-cell>
-Still More Content
+<p>Still More Content</p>
 </ac:layout-cell>
 </ac:layout-section>
 </ac:layout>
diff --git a/pkg/mark/testdata/pagelayout.html b/pkg/mark/testdata/pagelayout.html
index 23f17d5..a244202 100644
--- a/pkg/mark/testdata/pagelayout.html
+++ b/pkg/mark/testdata/pagelayout.html
@@ -1,18 +1,18 @@
 <ac:layout>
 <ac:layout-section ac:type="three_with_sidebars">
 <ac:layout-cell>
-More Content
+<p>More Content</p>
 </ac:layout-cell>
 <ac:layout-cell>
-More Content
+<p>More Content</p>
 </ac:layout-cell>
 <ac:layout-cell>
-Even More Content
+<p>Even More Content</p>
 </ac:layout-cell>
 </ac:layout-section>
 <ac:layout-section ac:type="single">
 <ac:layout-cell>
-Still More Content
+<p>Still More Content</p>
 </ac:layout-cell>
 </ac:layout-section>
 </ac:layout>
diff --git a/pkg/mark/testdata/quotes-droph1.html b/pkg/mark/testdata/quotes-droph1.html
index e90782a..d8fdcdf 100644
--- a/pkg/mark/testdata/quotes-droph1.html
+++ b/pkg/mark/testdata/quotes-droph1.html
@@ -1,19 +1,19 @@
 <h2 id="first-heading">First Heading</h2>
 <ac:structured-macro ac:name="note"><ac:parameter ac:name="icon">true</ac:parameter><ac:rich-text-body>
-<strong>NOTES:</strong>
+<p><strong>NOTES:</strong></p>
 <ol>
 <li>Note number one</li>
 <li>Note number two</li>
 </ol>
 <blockquote>
-a
-b
+<p>a
+b</p>
 </blockquote>
-<strong>Warn (Should not be picked as blockquote type)</strong>
+<p><strong>Warn (Should not be picked as blockquote type)</strong></p>
 </ac:rich-text-body></ac:structured-macro>
 <h2 id="second-heading">Second Heading</h2>
 <ac:structured-macro ac:name="warn"><ac:parameter ac:name="icon">true</ac:parameter><ac:rich-text-body>
-<strong>Warn</strong>
+<p><strong>Warn</strong></p>
 <ul>
 <li>Warn bullet 1</li>
 <li>Warn bullet 2</li>
@@ -26,9 +26,9 @@ that runs long</li>
 <h2 id="third-heading">Third Heading</h2>
 <ac:structured-macro ac:name="info"><ac:parameter ac:name="icon">true</ac:parameter><ac:rich-text-body>
 <!-- Info -->
-Test
+<p>Test</p>
 </ac:rich-text-body></ac:structured-macro>
 <h2 id="simple-blockquote">Simple Blockquote</h2>
 <blockquote>
-This paragraph is a simple blockquote
+<p>This paragraph is a simple blockquote</p>
 </blockquote>
diff --git a/pkg/mark/testdata/quotes-stripnewlines.html b/pkg/mark/testdata/quotes-stripnewlines.html
index d0520a9..7a43019 100644
--- a/pkg/mark/testdata/quotes-stripnewlines.html
+++ b/pkg/mark/testdata/quotes-stripnewlines.html
@@ -1,19 +1,19 @@
 <h1 id="main-heading">Main Heading</h1>
 <h2 id="first-heading">First Heading</h2>
 <ac:structured-macro ac:name="note"><ac:parameter ac:name="icon">true</ac:parameter><ac:rich-text-body>
-<strong>NOTES:</strong>
+<p><strong>NOTES:</strong></p>
 <ol>
 <li>Note number one</li>
 <li>Note number two</li>
 </ol>
 <blockquote>
-a b
+<p>a b</p>
 </blockquote>
-<strong>Warn (Should not be picked as blockquote type)</strong>
+<p><strong>Warn (Should not be picked as blockquote type)</strong></p>
 </ac:rich-text-body></ac:structured-macro>
 <h2 id="second-heading">Second Heading</h2>
 <ac:structured-macro ac:name="warn"><ac:parameter ac:name="icon">true</ac:parameter><ac:rich-text-body>
-<strong>Warn</strong>
+<p><strong>Warn</strong></p>
 <ul>
 <li>Warn bullet 1</li>
 <li>Warn bullet 2</li>
@@ -25,9 +25,9 @@ a b
 <h2 id="third-heading">Third Heading</h2>
 <ac:structured-macro ac:name="info"><ac:parameter ac:name="icon">true</ac:parameter><ac:rich-text-body>
 <!-- Info -->
-Test
+<p>Test</p>
 </ac:rich-text-body></ac:structured-macro>
 <h2 id="simple-blockquote">Simple Blockquote</h2>
 <blockquote>
-This paragraph is a simple blockquote
+<p>This paragraph is a simple blockquote</p>
 </blockquote>
diff --git a/pkg/mark/testdata/quotes.html b/pkg/mark/testdata/quotes.html
index 957e7eb..c1519c7 100644
--- a/pkg/mark/testdata/quotes.html
+++ b/pkg/mark/testdata/quotes.html
@@ -1,20 +1,20 @@
 <h1 id="main-heading">Main Heading</h1>
 <h2 id="first-heading">First Heading</h2>
 <ac:structured-macro ac:name="note"><ac:parameter ac:name="icon">true</ac:parameter><ac:rich-text-body>
-<strong>NOTES:</strong>
+<p><strong>NOTES:</strong></p>
 <ol>
 <li>Note number one</li>
 <li>Note number two</li>
 </ol>
 <blockquote>
-a
-b
+<p>a
+b</p>
 </blockquote>
-<strong>Warn (Should not be picked as blockquote type)</strong>
+<p><strong>Warn (Should not be picked as blockquote type)</strong></p>
 </ac:rich-text-body></ac:structured-macro>
 <h2 id="second-heading">Second Heading</h2>
 <ac:structured-macro ac:name="warn"><ac:parameter ac:name="icon">true</ac:parameter><ac:rich-text-body>
-<strong>Warn</strong>
+<p><strong>Warn</strong></p>
 <ul>
 <li>Warn bullet 1</li>
 <li>Warn bullet 2</li>
@@ -27,9 +27,9 @@ that runs long</li>
 <h2 id="third-heading">Third Heading</h2>
 <ac:structured-macro ac:name="info"><ac:parameter ac:name="icon">true</ac:parameter><ac:rich-text-body>
 <!-- Info -->
-Test
+<p>Test</p>
 </ac:rich-text-body></ac:structured-macro>
 <h2 id="simple-blockquote">Simple Blockquote</h2>
 <blockquote>
-This paragraph is a simple blockquote
+<p>This paragraph is a simple blockquote</p>
 </blockquote>
diff --git a/pkg/mark/testdata/tags-droph1.html b/pkg/mark/testdata/tags-droph1.html
index 5c3f317..7fd51c0 100644
--- a/pkg/mark/testdata/tags-droph1.html
+++ b/pkg/mark/testdata/tags-droph1.html
@@ -1,6 +1,6 @@
 <b>bold</b>
-<strong>bold</strong>
+<p><strong>bold</strong></p>
 <i>vitalik</i>
-<em>vitalik</em>
+<p><em>vitalik</em></p>
 
strikethrough

-<del>strikethrough</del>
+<p><del>strikethrough</del></p>
diff --git a/pkg/mark/testdata/tags-stripnewlines.html b/pkg/mark/testdata/tags-stripnewlines.html
index 85c1878..7fd51c0 100644
--- a/pkg/mark/testdata/tags-stripnewlines.html
+++ b/pkg/mark/testdata/tags-stripnewlines.html
@@ -1,3 +1,6 @@
-<b>bold</b> <strong>bold</strong>
-<i>vitalik</i> <em>vitalik</em>
-
strikethrough
 <del>strikethrough</del>
+<b>bold</b>
+<p><strong>bold</strong></p>
+<i>vitalik</i>
+<p><em>vitalik</em></p>
+
strikethrough

+<p><del>strikethrough</del></p>
diff --git a/pkg/mark/testdata/tags.html b/pkg/mark/testdata/tags.html
index 5c3f317..7fd51c0 100644
--- a/pkg/mark/testdata/tags.html
+++ b/pkg/mark/testdata/tags.html
@@ -1,6 +1,6 @@
 <b>bold</b>
-<strong>bold</strong>
+<p><strong>bold</strong></p>
 <i>vitalik</i>
-<em>vitalik</em>
+<p><em>vitalik</em></p>
 
strikethrough

-<del>strikethrough</del>
+<p><del>strikethrough</del></p>
diff --git a/pkg/mark/testdata/tags.md b/pkg/mark/testdata/tags.md
index 502c6d6..1d247d6 100644
--- a/pkg/mark/testdata/tags.md
+++ b/pkg/mark/testdata/tags.md
@@ -1,8 +1,11 @@
 <b>bold</b>
+
 **bold**
 
 <i>vitalik</i>
+
 *vitalik*
 
 
strikethrough

+
 ~~strikethrough~~