Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.10] Fix multi line symbol link source range issue #156

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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