From 2dbae733f17ca7f1f73eeac3998479cc021eea88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Thu, 25 Jul 2024 22:24:36 +0200 Subject: [PATCH] Do not render paragraph tags --- pkg/mark/markdown.go | 1 + pkg/mark/renderer/paragraph.go | 31 +++++++++++++++++++ pkg/mark/testdata/codes-droph1.html | 6 ++-- pkg/mark/testdata/codes-stripnewlines.html | 4 +-- pkg/mark/testdata/codes.html | 6 ++-- .../testdata/issue-64-broken-link-droph1.html | 2 +- .../issue-64-broken-link-stripnewlines.html | 2 +- pkg/mark/testdata/issue-64-broken-link.html | 2 +- pkg/mark/testdata/links-droph1.html | 20 ++++++------ pkg/mark/testdata/links-stripnewlines.html | 20 ++++++------ pkg/mark/testdata/links.html | 20 ++++++------ pkg/mark/testdata/lists-droph1.html | 2 +- pkg/mark/testdata/lists-stripnewlines.html | 2 +- pkg/mark/testdata/lists.html | 2 +- pkg/mark/testdata/macro-include-droph1.html | 26 ++++++++++++++-- .../testdata/macro-include-stripnewlines.html | 20 ++++++++++-- pkg/mark/testdata/macro-include.html | 26 ++++++++++++++-- pkg/mark/testdata/macro-include.md | 13 +++++++- pkg/mark/testdata/newlines-droph1.html | 20 ++++++------ pkg/mark/testdata/newlines-stripnewlines.html | 16 +++++----- pkg/mark/testdata/newlines.html | 20 ++++++------ pkg/mark/testdata/pagelayout-droph1.html | 8 ++--- .../testdata/pagelayout-stripnewlines.html | 8 ++--- pkg/mark/testdata/pagelayout.html | 8 ++--- pkg/mark/testdata/quotes-droph1.html | 14 ++++----- pkg/mark/testdata/quotes-stripnewlines.html | 12 +++---- pkg/mark/testdata/quotes.html | 14 ++++----- pkg/mark/testdata/tags-droph1.html | 12 +++---- pkg/mark/testdata/tags-stripnewlines.html | 6 ++-- pkg/mark/testdata/tags.html | 12 +++---- 30 files changed, 227 insertions(+), 128 deletions(-) create mode 100644 pkg/mark/renderer/paragraph.go diff --git a/pkg/mark/markdown.go b/pkg/mark/markdown.go index 2f057d3..b1c58cd 100644 --- a/pkg/mark/markdown.go +++ b/pkg/mark/markdown.go @@ -58,6 +58,7 @@ func (c *ConfluenceExtension) Extend(m goldmark.Markdown) { util.Prioritized(crenderer.NewConfluenceHTMLBlockRenderer(c.Stdlib), 100), util.Prioritized(crenderer.NewConfluenceHeadingRenderer(c.DropFirstH1), 100), util.Prioritized(crenderer.NewConfluenceImageRenderer(c.Stdlib, c, c.Path), 100), + util.Prioritized(crenderer.NewConfluenceParagraphRenderer(), 100), util.Prioritized(crenderer.NewConfluenceLinkRenderer(), 100), )) diff --git a/pkg/mark/renderer/paragraph.go b/pkg/mark/renderer/paragraph.go new file mode 100644 index 0000000..df9bc49 --- /dev/null +++ b/pkg/mark/renderer/paragraph.go @@ -0,0 +1,31 @@ +package renderer + +import ( + "github.com/yuin/goldmark/ast" + "github.com/yuin/goldmark/renderer" + "github.com/yuin/goldmark/renderer/html" + "github.com/yuin/goldmark/util" +) + +type ConfluenceParagraphRenderer struct { + html.Config +} + +// NewConfluenceRenderer creates a new instance of the ConfluenceRenderer +func NewConfluenceParagraphRenderer(opts ...html.Option) renderer.NodeRenderer { + return &ConfluenceParagraphRenderer{ + Config: html.NewConfig(), + } +} + +// RegisterFuncs implements NodeRenderer.RegisterFuncs . +func (r *ConfluenceParagraphRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer) { + reg.Register(ast.KindParagraph, r.renderParagraph) +} + +func (r *ConfluenceParagraphRenderer) renderParagraph(w util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error) { + if !entering { + _, _ = w.WriteString("\n") + } + return ast.WalkContinue, nil +} diff --git a/pkg/mark/testdata/codes-droph1.html b/pkg/mark/testdata/codes-droph1.html index 733410b..bcf5be7 100644 --- a/pkg/mark/testdata/codes-droph1.html +++ b/pkg/mark/testdata/codes-droph1.html @@ -1,7 +1,7 @@ -

inline

+inline falsebashfalsebashfalseunknownfalse

text -text 2

+]]>unknownfalsetext +text 2 unknownfalseshfalseA b cbashtrueA b cctruenestedfalsefalseinline

+inline falsebashfalsebashfalseunknownfalse

text text 2

+]]>
unknownfalsetext text 2 unknownfalseshfalseA b cbashtrueA b cctruenestedfalsefalseinline

+inline falsebashfalsebashfalseunknownfalse

text -text 2

+]]>
unknownfalsetext +text 2 unknownfalseshfalseA b cbashtrueA b cctruenestedfalsefalsev71

+v71 diff --git a/pkg/mark/testdata/issue-64-broken-link-stripnewlines.html b/pkg/mark/testdata/issue-64-broken-link-stripnewlines.html index 0d39ce8..dca9603 100644 --- a/pkg/mark/testdata/issue-64-broken-link-stripnewlines.html +++ b/pkg/mark/testdata/issue-64-broken-link-stripnewlines.html @@ -1 +1 @@ -

v71

+v71 diff --git a/pkg/mark/testdata/issue-64-broken-link.html b/pkg/mark/testdata/issue-64-broken-link.html index 0d39ce8..dca9603 100644 --- a/pkg/mark/testdata/issue-64-broken-link.html +++ b/pkg/mark/testdata/issue-64-broken-link.html @@ -1 +1 @@ -

v71

+v71 diff --git a/pkg/mark/testdata/links-droph1.html b/pkg/mark/testdata/links-droph1.html index 82fd040..b002880 100644 --- a/pkg/mark/testdata/links-droph1.html +++ b/pkg/mark/testdata/links-droph1.html @@ -1,17 +1,17 @@ -

Use https://example.com

-

Use aaa

-

Use

-

Use

-

Use

-

Use

-

-

-

Use footnotes link 1

+Use https://example.com +Use aaa +Use +Use +Use +Use + + +Use footnotes link 1

  1. -

    a footnote link ↩︎

    +a footnote link ↩︎
diff --git a/pkg/mark/testdata/links-stripnewlines.html b/pkg/mark/testdata/links-stripnewlines.html index 82fd040..b002880 100644 --- a/pkg/mark/testdata/links-stripnewlines.html +++ b/pkg/mark/testdata/links-stripnewlines.html @@ -1,17 +1,17 @@ -

Use https://example.com

-

Use aaa

-

Use

-

Use

-

Use

-

Use

-

-

-

Use footnotes link 1

+Use https://example.com +Use aaa +Use +Use +Use +Use + + +Use footnotes link 1

  1. -

    a footnote link ↩︎

    +a footnote link ↩︎
diff --git a/pkg/mark/testdata/links.html b/pkg/mark/testdata/links.html index 82fd040..b002880 100644 --- a/pkg/mark/testdata/links.html +++ b/pkg/mark/testdata/links.html @@ -1,17 +1,17 @@ -

Use https://example.com

-

Use aaa

-

Use

-

Use

-

Use

-

Use

-

-

-

Use footnotes link 1

+Use https://example.com +Use aaa +Use +Use +Use +Use + + +Use footnotes link 1

  1. -

    a footnote link ↩︎

    +a footnote link ↩︎
diff --git a/pkg/mark/testdata/lists-droph1.html b/pkg/mark/testdata/lists-droph1.html index af27c54..11aa2ca 100644 --- a/pkg/mark/testdata/lists-droph1.html +++ b/pkg/mark/testdata/lists-droph1.html @@ -13,7 +13,7 @@ -

text

+text
  • a
  • b
  • diff --git a/pkg/mark/testdata/lists-stripnewlines.html b/pkg/mark/testdata/lists-stripnewlines.html index af27c54..11aa2ca 100644 --- a/pkg/mark/testdata/lists-stripnewlines.html +++ b/pkg/mark/testdata/lists-stripnewlines.html @@ -13,7 +13,7 @@
-

text

+text
  • a
  • b
  • diff --git a/pkg/mark/testdata/lists.html b/pkg/mark/testdata/lists.html index af27c54..11aa2ca 100644 --- a/pkg/mark/testdata/lists.html +++ b/pkg/mark/testdata/lists.html @@ -13,7 +13,7 @@
-

text

+text
  • a
  • b
  • diff --git a/pkg/mark/testdata/macro-include-droph1.html b/pkg/mark/testdata/macro-include-droph1.html index 8d8ba05..ccf5127 100644 --- a/pkg/mark/testdata/macro-include-droph1.html +++ b/pkg/mark/testdata/macro-include-droph1.html @@ -1,6 +1,26 @@ -

    bar

    -

    +bar + true Attention This is an info! -

    + + +true +Attention + + + + + + + + + + + + + + +
    Header 1Header 2
    Cell ACell B
    +
    +
    diff --git a/pkg/mark/testdata/macro-include-stripnewlines.html b/pkg/mark/testdata/macro-include-stripnewlines.html index 52e4af7..5ad6298 100644 --- a/pkg/mark/testdata/macro-include-stripnewlines.html +++ b/pkg/mark/testdata/macro-include-stripnewlines.html @@ -1,2 +1,18 @@ -

    bar

    -

    true Attention This is an info!

    +bar + true Attention This is an info! + true Attention + + + + + + + + + + + + + +
    Header 1Header 2
    Cell ACell B
    +
    diff --git a/pkg/mark/testdata/macro-include.html b/pkg/mark/testdata/macro-include.html index 8d8ba05..ccf5127 100644 --- a/pkg/mark/testdata/macro-include.html +++ b/pkg/mark/testdata/macro-include.html @@ -1,6 +1,26 @@ -

    bar

    -

    +bar + true Attention This is an info! -

    + + +true +Attention + + + + + + + + + + + + + + +
    Header 1Header 2
    Cell ACell B
    +
    +
    diff --git a/pkg/mark/testdata/macro-include.md b/pkg/mark/testdata/macro-include.md index c8d3d89..84123d1 100644 --- a/pkg/mark/testdata/macro-include.md +++ b/pkg/mark/testdata/macro-include.md @@ -4,4 +4,15 @@ true Attention This is an info! - \ No newline at end of file + + + +true +Attention + +| Header 1 | Header 2 | +|---|---| +| Cell A | Cell B | + + + diff --git a/pkg/mark/testdata/newlines-droph1.html b/pkg/mark/testdata/newlines-droph1.html index b97e510..272fe20 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
    -2space-2

    +one-1 +one-2 +two-1 +two-2 +three-1 +three-2 +space-1 +space-2 +2space-1
    +2space-2 diff --git a/pkg/mark/testdata/newlines-stripnewlines.html b/pkg/mark/testdata/newlines-stripnewlines.html index 2fd4dc0..cca4996 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
    -2space-2

    +one-1 one-2 +two-1 +two-2 +three-1 +three-2 +space-1 space-2 +2space-1
    +2space-2 diff --git a/pkg/mark/testdata/newlines.html b/pkg/mark/testdata/newlines.html index b97e510..272fe20 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
    -2space-2

    +one-1 +one-2 +two-1 +two-2 +three-1 +three-2 +space-1 +space-2 +2space-1
    +2space-2 diff --git a/pkg/mark/testdata/pagelayout-droph1.html b/pkg/mark/testdata/pagelayout-droph1.html index a244202..23f17d5 100644 --- a/pkg/mark/testdata/pagelayout-droph1.html +++ b/pkg/mark/testdata/pagelayout-droph1.html @@ -1,18 +1,18 @@ -

    More Content

    +More Content
    -

    More Content

    +More Content
    -

    Even More Content

    +Even More Content
    -

    Still More Content

    +Still More Content
    diff --git a/pkg/mark/testdata/pagelayout-stripnewlines.html b/pkg/mark/testdata/pagelayout-stripnewlines.html index a244202..23f17d5 100644 --- a/pkg/mark/testdata/pagelayout-stripnewlines.html +++ b/pkg/mark/testdata/pagelayout-stripnewlines.html @@ -1,18 +1,18 @@ -

    More Content

    +More Content
    -

    More Content

    +More Content
    -

    Even More Content

    +Even More Content
    -

    Still More Content

    +Still More Content
    diff --git a/pkg/mark/testdata/pagelayout.html b/pkg/mark/testdata/pagelayout.html index a244202..23f17d5 100644 --- a/pkg/mark/testdata/pagelayout.html +++ b/pkg/mark/testdata/pagelayout.html @@ -1,18 +1,18 @@ -

    More Content

    +More Content
    -

    More Content

    +More Content
    -

    Even More Content

    +Even More Content
    -

    Still More Content

    +Still More Content
    diff --git a/pkg/mark/testdata/quotes-droph1.html b/pkg/mark/testdata/quotes-droph1.html index d8fdcdf..e90782a 100644 --- a/pkg/mark/testdata/quotes-droph1.html +++ b/pkg/mark/testdata/quotes-droph1.html @@ -1,19 +1,19 @@

    First Heading

    true -

    NOTES:

    +NOTES:
    1. Note number one
    2. Note number two
    -

    a -b

    +a +b
    -

    Warn (Should not be picked as blockquote type)

    +Warn (Should not be picked as blockquote type)

    Second Heading

    true -

    Warn

    +Warn
    • Warn bullet 1
    • Warn bullet 2
    • @@ -26,9 +26,9 @@ that runs long

      Third Heading

      true -

      Test

      +Test

      Simple Blockquote

      -

      This paragraph is a simple blockquote

      +This paragraph is a simple blockquote
      diff --git a/pkg/mark/testdata/quotes-stripnewlines.html b/pkg/mark/testdata/quotes-stripnewlines.html index 7a43019..d0520a9 100644 --- a/pkg/mark/testdata/quotes-stripnewlines.html +++ b/pkg/mark/testdata/quotes-stripnewlines.html @@ -1,19 +1,19 @@

      Main Heading

      First Heading

      true -

      NOTES:

      +NOTES:
      1. Note number one
      2. Note number two
      -

      a b

      +a b
      -

      Warn (Should not be picked as blockquote type)

      +Warn (Should not be picked as blockquote type)

      Second Heading

      true -

      Warn

      +Warn
      • Warn bullet 1
      • Warn bullet 2
      • @@ -25,9 +25,9 @@

        Third Heading

        true -

        Test

        +Test

        Simple Blockquote

        -

        This paragraph is a simple blockquote

        +This paragraph is a simple blockquote
        diff --git a/pkg/mark/testdata/quotes.html b/pkg/mark/testdata/quotes.html index c1519c7..957e7eb 100644 --- a/pkg/mark/testdata/quotes.html +++ b/pkg/mark/testdata/quotes.html @@ -1,20 +1,20 @@

        Main Heading

        First Heading

        true -

        NOTES:

        +NOTES:
        1. Note number one
        2. Note number two
        -

        a -b

        +a +b
        -

        Warn (Should not be picked as blockquote type)

        +Warn (Should not be picked as blockquote type)

        Second Heading

        true -

        Warn

        +Warn
        • Warn bullet 1
        • Warn bullet 2
        • @@ -27,9 +27,9 @@ that runs long

          Third Heading

          true -

          Test

          +Test

          Simple Blockquote

          -

          This paragraph is a simple blockquote

          +This paragraph is a simple blockquote
          diff --git a/pkg/mark/testdata/tags-droph1.html b/pkg/mark/testdata/tags-droph1.html index a5161db..5c3f317 100644 --- a/pkg/mark/testdata/tags-droph1.html +++ b/pkg/mark/testdata/tags-droph1.html @@ -1,6 +1,6 @@ -

          bold -bold

          -

          vitalik -vitalik

          -

          strikethrough -strikethrough

          +bold +bold +vitalik +vitalik +strikethrough +strikethrough diff --git a/pkg/mark/testdata/tags-stripnewlines.html b/pkg/mark/testdata/tags-stripnewlines.html index cc0698b..85c1878 100644 --- a/pkg/mark/testdata/tags-stripnewlines.html +++ b/pkg/mark/testdata/tags-stripnewlines.html @@ -1,3 +1,3 @@ -

          bold bold

          -

          vitalik vitalik

          -

          strikethrough strikethrough

          +bold bold +vitalik vitalik +strikethrough strikethrough diff --git a/pkg/mark/testdata/tags.html b/pkg/mark/testdata/tags.html index a5161db..5c3f317 100644 --- a/pkg/mark/testdata/tags.html +++ b/pkg/mark/testdata/tags.html @@ -1,6 +1,6 @@ -

          bold -bold

          -

          vitalik -vitalik

          -

          strikethrough -strikethrough

          +bold +bold +vitalik +vitalik +strikethrough +strikethrough