Skip to content

Commit

Permalink
Fix multi line symbol link source range issue (#151) (#156)
Browse files Browse the repository at this point in the history
* Fix multi line symbol link source range issue

* Add disableSourcePosOpts ParseOptions
  • Loading branch information
Kyle-Ye committed Nov 14, 2023
1 parent 4ca8a13 commit d91b618
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Sources/Markdown/Parser/CommonMarkConverter.swift
Expand Up @@ -615,6 +615,9 @@ struct MarkupParser {
if !options.contains(.disableSmartOpts) {
cmarkOptions |= CMARK_OPT_SMART
}
if !options.contains(.disableSourcePosOpts) {
cmarkOptions |= CMARK_OPT_SOURCEPOS
}

let parser = cmark_parser_new(cmarkOptions)

Expand Down
5 changes: 4 additions & 1 deletion Sources/Markdown/Parser/ParseOptions.swift
Expand Up @@ -22,10 +22,13 @@ public struct ParseOptions: OptionSet {
/// Enable interpretation of symbol links from inline code spans surrounded by two backticks.
public static let parseSymbolLinks = ParseOptions(rawValue: 1 << 1)

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

/// Parse a limited set of Doxygen commands. Requires ``parseBlockDirectives``.
public static let parseMinimalDoxygen = ParseOptions(rawValue: 1 << 3)

/// Disable including a `data-sourcepos` attribute on all block elements during parsing.
public static let disableSourcePosOpts = ParseOptions(rawValue: 1 << 4)
}

15 changes: 15 additions & 0 deletions Tests/MarkdownTests/Inline Nodes/SymbolLinkTests.swift
Expand Up @@ -46,4 +46,19 @@ class SymbolLinkTests: XCTestCase {
XCTAssertEqual(expectedDump, document.debugDescription(options: .printSourceLocations))
}
}

func testMultilineSymbolLink() {
let source = """
Test of a ``multi
line symbolink``
"""
let document = Document(parsing: source, options: .parseSymbolLinks)
let expectedDump = """
Document @1:1-2:17
└─ Paragraph @1:1-2:17
├─ Text @1:1-1:11 "Test of a "
└─ SymbolLink @1:11-2:17 destination: multi line symbolink
"""
XCTAssertEqual(expectedDump, document.debugDescription(options: .printSourceLocations))
}
}
2 changes: 1 addition & 1 deletion Tests/MarkdownTests/Parsing/BacktickTests.swift
Expand Up @@ -36,7 +36,7 @@ class BacktickTests: XCTestCase {
XCTAssertEqual(expectedDump, document.debugDescription(options: .printSourceLocations))
}

func testOpenBackticks(){
func testOpenBackticks() {
let double = "``"
let document = Document(parsing: double)
let expectedDump = """
Expand Down

0 comments on commit d91b618

Please sign in to comment.