There is 1 comment.
 
 
Markdown Syntax / cid:jira-generated-image-avatar-fb5595c4-cfbf-44b1-b9dc-7ee356841e11 MARKDOWN-56 In Progress

Add support for Group syntax

 
View issue   ยท   Add comment
 

1 comment

 
cid:jira-generated-image-avatar-0cdd9a13-eee2-4d0a-b889-0c1ed8e0ed2b Vincent Massol on 27/Sep/26 10:47
 

Implemented in https://github.com/xwiki-contrib/syntax-markdown/pull/7 (for both markdown/1.2 and markdown+github/1.0).

Syntax

A Group is written in Markdown as a <div> carrying the data-xwiki-group marker attribute, with the Group parameters as HTML attributes. The opening and closing tags must each be alone on their line and separated from the content by blank lines, so that the content stays Markdown:

<div data-xwiki-group class="box infomessage">

This is an **info** box with:

* a list
* and a [link](https://www.xwiki.org)

</div>

This is equivalent to the following XWiki Syntax 2.1:

(% class="box infomessage" %)
(((
This is an **info** box with:

* a list
* and a [[link>>https://www.xwiki.org]]
)))

The Markdown renderer now produces this syntax for any Group (e.g. an info box inserted with the WYSIWYG editor's Styles dropdown, which was lost before), and the parser converts it back into a Group, so that the Group and its parameters survive the WYSIWYG editor round trip. Groups can be nested, and inside a list item the Group is indented like the rest of the list item content:

* item

  <div data-xwiki-group class="box warningmessage">

  a warning inside the list item

  </div>

Caveats

  • Only marked divs are Groups: to not change the meaning of existing content, a <div> without the data-xwiki-group attribute (e.g. raw HTML written by hand) is still converted to HTML macros, exactly as before. The same goes for a marked div that is not alone in its HTML block (e.g. <div data-xwiki-group>text</div> on a single line, or no blank line after the opening tag) or that has no matching </div> at the same nesting level.
  • Groups without parameters are rendered too (as <div data-xwiki-group>), for an exact round trip. The only exception is the parameterless Group that the Markdown parser itself creates around an indented code block in a list item, which is not rendered, so that the output of existing content doesn't change.
  • A Group is always a block: as in XWiki Syntax 2.1, a Group located inside a paragraph is rendered on its own lines, which splits the paragraph.
  • Groups in table cells lose their div: Markdown tables can't contain blocks, so only the content of a Group located in a table cell is rendered (as before).
  • Parameter values are HTML-escaped (&, ", <, > and new lines), and parameters whose names aren't valid HTML attribute names can't be expressed and are dropped.