kovetskiy / mark

Sync your markdown files with Confluence pages.
https://samizdat.dev
Other
981 stars 144 forks source link

Table within macro is not rendered #324

Open mrueg opened 1 year ago

mrueg commented 1 year ago

What happened? Trying to render this to confluence

<ac:structured-macro ac:name="info">
<ac:parameter ac:name="icon">true</ac:parameter>
<ac:parameter ac:name="title">Attention</ac:parameter>
<ac:rich-text-body>| Header 1 | Header 2 |
|---|---|
| Cell A | Cell B |
</ac:rich-text-body>
</ac:structured-macro>

results in

                                <p><ac:structured-macro ac:name="info">
                                <ac:parameter ac:name="icon">true</ac:parameter>
                                <ac:parameter ac:name="title">Attention</ac:parameter>
                                <ac:rich-text-body></p>
                                <table>
                                <thead>
                                <tr>
                                <th>Header 1</th>
                                <th>Header 2</th>
                                </tr>
                                </thead>
                                <tbody>
                                <tr>
                                <td>Column A</td>
                                <td>Column B</td>
                                </tr>
                                </tbody>
                                </table>
                                <p></ac:rich-text-body>
                                </ac:structured-macro></p>

What did you expect to happen? Table gets rendered

<ac:structured-macro ac:name="info">
<ac:parameter ac:name="icon">true</ac:parameter>
<ac:parameter ac:name="title">Attention</ac:parameter>
<ac:rich-text-body><table>
<thead>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Cell A</td>
<td>Cell B</td>
</tr>
</tbody>
</table>
</ac:rich-text-body>
</ac:structured-macro>

How can we reproduce the behavior you experienced? Steps to reproduce the behavior:

  1. Use markdown above
  2. Render it with mark
  3. In case this is related to specific markdown, please provide a minimal markdown example here.

Information (please complete the following information):

Logs or other output Please provide logs, other kind of output or observed metrics here.

Additional context Add any other context about the problem here.

mrueg commented 1 year ago

I believe the problem is that we're treating </ac:foo> as an inline instead of a block item in https://github.com/kovetskiy/mark/blob/master/pkg/mark/parser/confluencetags.go

mrueg commented 1 year ago

@bernd (you might have some thoughts here as you added https://github.com/kovetskiy/mark/pull/270) @kovetskiy any thoughts on how to achieve this? I tried working with a block parser, unfortunately it will add new <p> paragraph tags all the time, which breaks rendering.

bernd commented 1 year ago

@mrueg Can you share your block parser code?

mrueg commented 1 year ago

@bernd https://github.com/mrueg/mark/commit/e409fb7351760237ebb00b6936ed7ba2f292b130 this was my attempt but it does not work, as the closing ones after the table will create a new paragraph. I'm not sure if I need to use a paragraph transformer for that.

nyarly commented 10 months ago

@mrueg I spent a little time looking at this - I'm not sure if the inline parser is the issue. It looks like the <ac:rich-text> and </ac:rich-text> tags are each parsed as ast.RawHTML nodes, and should be the preceding and following siblings of the table.

FWIW, I think that actually may be a legit rendering of that markdown - GFM tables, I think, need to start their line. If you put a \n before the | it seems to work.

e.g.

true Attention | Header 1 | Header 2 | |---|---| | Cell A | Cell B | **versus** true Attention | Header 1 | Header 2 | |---|---| | Cell A | Cell B | (the above being your original example verbatim in a Github comment)
mrueg commented 10 months ago

Thanks for taking a look, I made a mistake in the initial description, hope this makes it more clear:

The problem is that the RawHTML gets encapsulated in a paragraph

                                <p><ac:structured-macro ac:name="info">
                                <ac:parameter ac:name="icon">true</ac:parameter>
                                <ac:parameter ac:name="title">Attention</ac:parameter>
                                <ac:rich-text-body></p>

then the table follows and the closing tags are encapsulated in its own paragraph.


                                <p></ac:rich-text-body>
                                </ac:structured-macro></p>
stephenpaulger commented 4 months ago

A similar example which I think shows some inconsistency in how inline macros work. There are two pairs of macros, the first is the tblbox macro from the project's README and the second is my attempt to create an infobox macro.

<!-- Space: space -->
<!-- Parent: parent -->
<!-- Title: title -->

<!-- Macro: <tblbox\s+(.*?)\s*>
       Template: #inline
       title: ${1}
       inline: |
           <table>
           <thead><tr><th>{{ .title }}</th></tr></thead>
           <tbody><tr><td>
        -->
 <!-- Macro: </tblbox>
       Template: #also_inline
       also_inline: |
           </td></tr></tbody></table>
        -->

<!-- Macro: <infobox\s+(.*?)\s*>
       Template: #inline
       title: ${1}
       inline: |
           <ac:structured-macro ac:name="info" ac:schema-version="1">
           <ac:parameter ac:name="title">{{ .title }}</ac:parameter>
           <ac:rich-text-body>
       -->

<!-- Macro: </infobox>
      Template: #also_inline
      also_inline: |
          </ac:rich-text-body></ac:structured-macro>
       -->

<tblbox with a title>
and some
content
</tblbox>

<infobox info title>
and some
content
</infobox>

Which when rendered produces...

<table>
<thead><tr><th>with a title</th></tr></thead>
<tbody><tr><td>
<p>and some
content</p>
</td></tr></tbody></table>
<p><ac:structured-macro ac:name="info" ac:schema-version="1">
<ac:parameter ac:name="title">info title</ac:parameter>
<ac:rich-text-body></p>
<p>and some
content
</ac:rich-text-body></ac:structured-macro></p>

So tblbox is rendered as we'd expect but infobox which is not hugely different has each macro's output wrapped in <p>s.

jgrgt commented 3 weeks ago

I'm struggling with the same problem. Does anybody have a solution for using <ac:*> blocks (in templates)?