Skip to content

Commit 4312077

Browse files
authored
Fix multi line symbol link source range issue (swiftlang#151)
* Fix multi line symbol link source range issue * Add disableSourcePosOpts ParseOptions
1 parent 87773c4 commit 4312077

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

Sources/Markdown/Parser/CommonMarkConverter.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,9 @@ struct MarkupParser {
615615
if !options.contains(.disableSmartOpts) {
616616
cmarkOptions |= CMARK_OPT_SMART
617617
}
618+
if !options.contains(.disableSourcePosOpts) {
619+
cmarkOptions |= CMARK_OPT_SOURCEPOS
620+
}
618621

619622
let parser = cmark_parser_new(cmarkOptions)
620623

Sources/Markdown/Parser/ParseOptions.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ public struct ParseOptions: OptionSet {
2222
/// Enable interpretation of symbol links from inline code spans surrounded by two backticks.
2323
public static let parseSymbolLinks = ParseOptions(rawValue: 1 << 1)
2424

25-
/// Disable converting straight quotes to curly, --- to em dashes, -- to en dashes during parsing
25+
/// Disable converting straight quotes to curly, --- to em dashes, -- to en dashes during parsing.
2626
public static let disableSmartOpts = ParseOptions(rawValue: 1 << 2)
2727

2828
/// Parse a limited set of Doxygen commands. Requires ``parseBlockDirectives``.
2929
public static let parseMinimalDoxygen = ParseOptions(rawValue: 1 << 3)
30+
31+
/// Disable including a `data-sourcepos` attribute on all block elements during parsing.
32+
public static let disableSourcePosOpts = ParseOptions(rawValue: 1 << 4)
3033
}
3134

Tests/MarkdownTests/Inline Nodes/SymbolLinkTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,19 @@ class SymbolLinkTests: XCTestCase {
4646
XCTAssertEqual(expectedDump, document.debugDescription(options: .printSourceLocations))
4747
}
4848
}
49+
50+
func testMultilineSymbolLink() {
51+
let source = """
52+
Test of a ``multi
53+
line symbolink``
54+
"""
55+
let document = Document(parsing: source, options: .parseSymbolLinks)
56+
let expectedDump = """
57+
Document @1:1-2:17
58+
└─ Paragraph @1:1-2:17
59+
├─ Text @1:1-1:11 "Test of a "
60+
└─ SymbolLink @1:11-2:17 destination: multi line symbolink
61+
"""
62+
XCTAssertEqual(expectedDump, document.debugDescription(options: .printSourceLocations))
63+
}
4964
}

Tests/MarkdownTests/Parsing/BacktickTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class BacktickTests: XCTestCase {
3636
XCTAssertEqual(expectedDump, document.debugDescription(options: .printSourceLocations))
3737
}
3838

39-
func testOpenBackticks(){
39+
func testOpenBackticks() {
4040
let double = "``"
4141
let document = Document(parsing: double)
4242
let expectedDump = """

0 commit comments

Comments
 (0)