diff --git a/dist/index.js b/dist/index.js index 09b04baf28c18d8ee20e6d0644329a830915e893..f2b3e8df251c3f56074937dc0c6e658930d5303b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -558,14 +558,24 @@ var MarkdownManager = class { nextNode, this.markSetsEqual.bind(this) ); + + // Collect all closing marks with their markdown syntax + const closingMarks = []; marksToCloseAtEnd.forEach((markType) => { const mark = activeMarks.get(markType); const closeMarkdown = this.getMarkClosing(markType, mark); if (closeMarkdown) { - textContent += closeMarkdown; + closingMarks.push(closeMarkdown); } activeMarks.delete(markType); }); + + // Reverse the closing marks to match opening order (LIFO) + // For example: if we opened as *~~, we should close as ~~* + closingMarks.reverse().forEach((closeMarkdown) => { + textContent += closeMarkdown; + }); + result.push(textContent); } else { const marksToReopen = new Map(activeMarks);