Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table within macro is not rendered #324

Open
mrueg opened this issue May 24, 2023 · 8 comments
Open

Table within macro is not rendered #324

mrueg opened this issue May 24, 2023 · 8 comments
Labels

Comments

@mrueg
Copy link
Collaborator

mrueg commented May 24, 2023

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

In case this is related to specific markdown, please provide a minimal markdown example here.

** Information (please complete the following information):**

  • Mark Version (mark --version): [e.g. v9.1.4] 9.5.2
  • Mark Parameters: [e.g. --drop-h1 --title-from-h1]
  • Confluence Version: [e.g. v7.13]
  • Environment specific Information: [e.g. running in Github Actions, or on Mac OS X, etc.]

** 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 mrueg added the bug label May 24, 2023
@mrueg
Copy link
Collaborator Author

mrueg commented May 26, 2023

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

@mrueg
Copy link
Collaborator Author

mrueg commented Jun 5, 2023

@bernd (you might have some thoughts here as you added #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
Copy link
Contributor

bernd commented Jun 17, 2023

@mrueg Can you share your block parser code?

@mrueg
Copy link
Collaborator Author

mrueg commented Jun 21, 2023

@bernd mrueg@e409fb7 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
Copy link
Contributor

nyarly commented Sep 7, 2023

@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.
<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>

versus

<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>

(the above being your original example verbatim in a Github comment)

@mrueg
Copy link
Collaborator Author

mrueg commented Sep 8, 2023

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
Copy link
Contributor

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
Copy link

jgrgt commented Jul 2, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants