in Sources/Markdown/Parser/CommonMarkConverter.swift [145:170]
func range(_ node: UnsafeMutablePointer<cmark_node>?) -> SourceRange? {
let startLine = Int(cmark_node_get_start_line(node))
let startColumn = Int(cmark_node_get_start_column(node))
guard startLine > 0 && startColumn > 0 else {
// cmark doesn't track the positions for this node.
return nil
}
let endLine = Int(cmark_node_get_end_line(node))
let endColumn = Int(cmark_node_get_end_column(node)) + 1
guard endLine > 0 && endColumn > 0 else {
// cmark doesn't track the positions for this node.
return nil
}
// If this is a symbol link / code span, set the locations to include the ticks.
let backtickCount = Int(cmark_node_get_backtick_count(node))
let start = SourceLocation(line: startLine, column: startColumn - backtickCount, source: source)
let end = SourceLocation(line: endLine, column: endColumn + backtickCount, source: source)
// Sometimes the cmark range is invalid (rdar://73376719)
guard start <= end else { return nil }
return start..<end
}