File tree Expand file tree Collapse file tree 4 files changed +39
-0
lines changed
Sources/MarkdownUI/Parser
__Snapshots__/MarkdownTests Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,11 @@ extension BlockNode {
6060 case . codeBlock:
6161 self = . codeBlock( fenceInfo: unsafeNode. fenceInfo, content: unsafeNode. literal ?? " " )
6262 case . htmlBlock:
63+ // Don't render comments
64+ let trimmedLiteral = unsafeNode. literal? . trimmingCharacters ( in: . whitespacesAndNewlines)
65+ if let trimmedLiteral, trimmedLiteral. hasPrefix ( " <!-- " ) && trimmedLiteral. hasSuffix ( " --> " ) {
66+ return nil
67+ }
6368 self = . htmlBlock( content: unsafeNode. literal ?? " " )
6469 case . paragraph:
6570 self = . paragraph( content: unsafeNode. children. compactMap ( InlineNode . init ( unsafeNode: ) ) )
Original file line number Diff line number Diff line change @@ -423,4 +423,22 @@ final class MarkdownContentTests: XCTestCase {
423423 )
424424 XCTAssertEqual ( markdown, content. renderMarkdown ( ) )
425425 }
426+
427+ func testComment( ) {
428+ // given
429+ let markdown = """
430+ <!--This is a comment-->
431+ <!--
432+ This is a
433+ multiline comment
434+ -->
435+ """
436+
437+ // when
438+ let content = MarkdownContent ( markdown)
439+
440+ // then
441+ XCTAssertEqual ( MarkdownContent { } , content)
442+ XCTAssertEqual ( " " , content. renderMarkdown ( ) )
443+ }
426444}
Original file line number Diff line number Diff line change 342342
343343 assertSnapshot ( of: view, as: . image( layout: layout) )
344344 }
345+
346+ func testComment( ) {
347+ let view = Markdown {
348+ #"""
349+ This is rendered
350+ <!--This is a comment-->
351+ <!--
352+ This is a multiline
353+ comment
354+ -->
355+ So is this
356+ """#
357+ } . markdownSoftBreakMode ( . lineBreak)
358+
359+ assertSnapshot ( of: view, as: . image( layout: layout) )
360+ }
345361 }
346362#endif
You can’t perform that action at this time.
0 commit comments