Skip to content

Commit ad0b81f

Browse files
don't try to add a line to a closed block directive (#113)
rdar://105221177
1 parent 1c95659 commit ad0b81f

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

Sources/Markdown/Parser/BlockDirectiveParser.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,10 @@ struct ParseContainerStack {
10091009
// A pending block directive can accept this line if it is in the middle of
10101010
// parsing arguments text (to allow indentation to align arguments) or
10111011
// if the line isn't taking part in a code block.
1012-
let canAcceptLine = pendingBlockDirective.parseState == .argumentsText || !isCodeFenceOrIndentedCodeBlock(on: line)
1012+
let canAcceptLine =
1013+
pendingBlockDirective.parseState != .done &&
1014+
(pendingBlockDirective.parseState == .argumentsText ||
1015+
!isCodeFenceOrIndentedCodeBlock(on: line))
10131016
if canAcceptLine && pendingBlockDirective.accept(line) {
10141017
pop()
10151018
push(.blockDirective(pendingBlockDirective, children))

Tests/MarkdownTests/Parsing/BlockDirectiveParserTests.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ class BlockDirectiveArgumentParserTests: XCTestCase {
991991
}
992992
"""
993993
let document = Document(parsing: source, options: [.parseBlockDirectives])
994-
994+
995995
let expectedDump = #"""
996996
Document @1:1-4:2
997997
├─ BlockDirective @1:1-1:19 name: "blah"
@@ -1003,4 +1003,21 @@ class BlockDirectiveArgumentParserTests: XCTestCase {
10031003
"""#
10041004
XCTAssertEqual(document.debugDescription(options: .printSourceLocations), expectedDump)
10051005
}
1006+
1007+
func testSingleLineDirectiveWithTrailingContent() {
1008+
let source = """
1009+
@blah { content }
1010+
content
1011+
"""
1012+
let document = Document(parsing: source, options: [.parseBlockDirectives])
1013+
let expectedDump = #"""
1014+
Document @1:1-2:8
1015+
├─ BlockDirective @1:1-1:18 name: "blah"
1016+
│ └─ Paragraph @1:9-1:16
1017+
│ └─ Text @1:9-1:16 "content"
1018+
└─ Paragraph @2:1-2:8
1019+
└─ Text @2:1-2:8 "content"
1020+
"""#
1021+
XCTAssertEqual(document.debugDescription(options: .printSourceLocations), expectedDump)
1022+
}
10061023
}

0 commit comments

Comments
 (0)