Skip to content

Add details/summary and HTML block support to accepted markdown.#177

Merged
pchuri merged 1 commit into
pchuri:mainfrom
evgeniysharapov:markdown-conversion-blocks-and-details
May 7, 2026
Merged

Add details/summary and HTML block support to accepted markdown.#177
pchuri merged 1 commit into
pchuri:mainfrom
evgeniysharapov:markdown-conversion-blocks-and-details

Conversation

@evgeniysharapov
Copy link
Copy Markdown
Contributor

Changed markdown conversion features from custom plugin to current visitor architecture:

  • convert <details>/<summary> HTML elements to Confluence expand macro
  • wrap <svg> and <div> blocks in Confluence HTML macros with CDATA

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Performance improvement (walker-based vs regex-based)

Implementation Details

changed HTML passthrough in macro-converter.js:

  • PASSTHROUGH_BLOCK_RE: Stashes complete <svg>/<div> blocks with all nested content preserved verbatim and not processed
  • PASSTHROUGH_TAG_RE: Extended to stash <details>/<summary> tags only, allowing markdown processing of content between tags

changes html-to-storage.js:

  • convertDetails() similar to convertBlockquote() pattern - detects structure, extracts parts, emits macro
  • convertHtmlBlock() wraps allowlisted tags in HTML macro with CDATA escaping and UUID generation via crypto.randomUUID()
  • allowlist HTML_MACRO_TAGS contains tags to wrap into HTML macro to avoid unintended wrapping in HTML macro (now only svg and div get wrapped )

Testing

  • Tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Test coverage:

  • Added 17 new tests across html-to-storage.test.js and macro-converter.test.js
  • All 669 existing tests pass (no regressions)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (inline comments)
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Example Usage

Input markdown:

<details>
<summary>View code</summary>

\`\`\`javascript
console.log("Hello");
\`\`\`

</details>

<svg width="100" height="100">
  <circle cx="50" cy="50" r="40"/>
</svg>

Output Confluence storage:

  <ac:structured-macro ac:name="expand">
    <ac:parameter ac:name="title">View code</ac:parameter>
    <ac:rich-text-body>
      <ac:structured-macro ac:name="code">
        <ac:parameter ac:name="language">javascript</ac:parameter>
        <ac:plain-text-body><![CDATA[console.log("Hello");]]></ac:plain-text-body>
      </ac:structured-macro>
    </ac:rich-text-body>
  </ac:structured-macro>

  <ac:structured-macro ac:name="html" ac:schema-version="1" ac:macro-id="...uuid...">
    <ac:plain-text-body><![CDATA[<svg width="100" height="100">
    <circle cx="50" cy="50" r="40"></circle>
  </svg>]]></ac:plain-text-body>
  </ac:structured-macro>

Changed markdown conversion features from custom plugin to current visitor architecture:
- convert <details>/<summary> HTML elements to Confluence expand macro
- wrap <svg> and <div> blocks in Confluence HTML macros with CDATA
- added necessary tests
@pchuri
Copy link
Copy Markdown
Owner

pchuri commented May 7, 2026

Thank you for the thoughtful follow-up and for taking the previous review feedback to heart — this is a much cleaner approach.

Highlights:

A few non-blocking nits for possible follow-up (no need to address in this PR):

  • convertHtmlBlock re-serializes attrs via renderAttrs, so self-closing slashes (<circle r="40"/><circle r="40">) are not preserved byte-identically. The tests assert this, so it's intentional — flagging in case strict-XML consumers ever care.
  • PASSTHROUGH_BLOCK_RE's lazy match assumes svg/div don't self-nest; rare in practice.
  • require('crypto') inside convertHtmlBlock could hoist to module scope.

Approving and merging. Thanks again for the contribution!

Copy link
Copy Markdown
Owner

@pchuri pchuri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great — clean walker-based approach with solid test coverage. Thanks!

@pchuri pchuri merged commit a4cc7a0 into pchuri:main May 7, 2026
6 checks passed
github-actions Bot pushed a commit that referenced this pull request May 7, 2026
# [2.6.0](v2.5.0...v2.6.0) (2026-05-07)

### Features

* **converter:** add details/summary and HTML block support to markdown conversion ([#177](#177)) ([a4cc7a0](a4cc7a0))
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

🎉 This PR is included in version 2.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants