File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
Sources/SwiftParser/Languages Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -126,7 +126,17 @@ public struct MarkdownLanguage: CodeLanguage {
126126 func add( _ t: Token ) { tokens. append ( t) }
127127 while index < input. endIndex {
128128 let ch = input [ index]
129- if ch == " # " {
129+ if ch == " \\ " {
130+ let start = index
131+ advance ( )
132+ if index < input. endIndex {
133+ let escaped = input [ index]
134+ advance ( )
135+ add ( . text( String ( escaped) , start..< index) )
136+ } else {
137+ add ( . text( " \\ " , start..< index) )
138+ }
139+ } else if ch == " # " {
130140 let start = index
131141 advance ( )
132142 add ( . hash( start..< index) )
@@ -215,7 +225,7 @@ public struct MarkdownLanguage: CodeLanguage {
215225 let start = index
216226 while index < input. endIndex &&
217227 input [ index] != " \n " &&
218- !" #-*+_`[].()<>!~|;&= " . contains ( input [ index] ) &&
228+ !" #-*+_`[].()<>!~|;&= \\ " . contains ( input [ index] ) &&
219229 !input[ index] . isNumber {
220230 advance ( )
221231 }
Original file line number Diff line number Diff line change @@ -92,6 +92,15 @@ final class SwiftParserTests: XCTestCase {
9292 XCTAssertEqual ( result. root. children. first? . type as? MarkdownLanguage . Element , . image)
9393 }
9494
95+ func testMarkdownEscapedCharacters( ) {
96+ let parser = SwiftParser ( )
97+ let source = " \\ *not italic \\ * "
98+ let result = parser. parse ( source, language: MarkdownLanguage ( ) )
99+ XCTAssertEqual ( result. errors. count, 0 )
100+ XCTAssertEqual ( result. root. children. count, 1 )
101+ XCTAssertEqual ( result. root. children. first? . value, " *not italic* " )
102+ }
103+
95104 func testPrattExpression( ) {
96105 let parser = SwiftParser ( )
97106 let source = " x = 1 + 2 * 3 "
You can’t perform that action at this time.
0 commit comments