diff --git a/Sources/DocCHTML/MarkdownRenderer.swift b/Sources/DocCHTML/MarkdownRenderer.swift index 14d28f2e2..240412fb4 100644 --- a/Sources/DocCHTML/MarkdownRenderer.swift +++ b/Sources/DocCHTML/MarkdownRenderer.swift @@ -675,58 +675,69 @@ package struct MarkdownRenderer { // - An empty element like `
` or `
` that's complete on its own. // - An element with children like `Something` that needs to be created out of multiple markup elements. // - // FIXME: See if this can be extracted into 2 private functions to make the code easier to read. // Because it may take multiple markdown elements to create an HTML element, we pop elements rather than iterating - var elements = Array(container) - outer: while !elements.isEmpty { - let element = elements.removeFirst() - - guard let start = element as? InlineHTML else { + var remainder = Array(container)[...] + while let element = remainder.popFirst() { + guard let openingHTML = element as? InlineHTML else { // If the markup _isn't_ inline HTML we can simply visit it to transform it. children.append(visit(element)) continue } - // Otherwise, we need to determine how long this markdown element it. - var rawHTML = start.rawHTML + // Otherwise, we need to determine how long this markdown element is. + let rawHTML = openingHTML.rawHTML + // Simply skip any HTML/XML comments. guard !rawHTML.hasPrefix("formatted paragraph.", + matches: "

This is a formatted paragraph.

" + ) + + assert( + rendering: "This
is a formattedparagraph.", + matches: "

This
is a formatted paragraph.

" + ) + + assert( + rendering: "This is a custom formatted paragraph.", + matches: "

This is a custom formatted paragraph.

" + ) + + // This markup doesn't properly close the `` tag (it uses an `` tag. + // In this case we drop both tags but not their content in between. This matches what DocC does for inline HTML with regards to the Render JSON output. + assert( + rendering: "This is a custom formatted paragraph.", + matches: "

This is a custom formatted paragraph.

" + ) + + // Any content _within_ HTML tags in the markdown isn't parsed as markdown content. + assert( + rendering: "This is a custom **not** formatted paragraph.", + matches: "

This is a custom **not** formatted paragraph.

" + ) + + assert( + rendering: """ +
+ Some summary + +

Some longer description

+
+ + """, + matches: """ +
+ Some summary +

Some longer description

+
+ """ + ) + } + private func assert( rendering markdownContent: String, elementToReturn: LinkedElement? = nil,