Skip to content

Commit

Permalink
Some changes to markdown parser
Browse files Browse the repository at this point in the history
  • Loading branch information
ActuallyTaylor committed Aug 22, 2021
1 parent fca674d commit 3ee782b
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions Sources/Highlighter/Markdown.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public class Markdown {
}
}

let imageBulletRegex = try? NSRegularExpression(pattern: "(\\t)*(\\*)\\[.*?\\]\\((.*?)\\)", options: [])
let imageBulletRegex = try? NSRegularExpression(pattern: "\\t*\\*\\[.*?\\]\\((.*?)\\)", options: [])
if let matches = imageBulletRegex?.matches(in: attributedString.string, options: [], range: NSRange(location: 0, length: attributedString.length)) {

for aMatch in matches.reversed() {
Expand All @@ -108,7 +108,7 @@ public class Markdown {
text.insert("\t", at: text.startIndex)

let attachment = NSTextAttachment()
guard let gRange = Range(aMatch.range(at: 3), in: attributedString.string) else { break }
guard let gRange = Range(aMatch.range(at: 1), in: attributedString.string) else { break }
let glyphNumb = attributedString.string[gRange]

attachment.image = FireflyImage(named: "\(glyphNumb).png")
Expand All @@ -120,9 +120,7 @@ public class Markdown {
#endif

let image = NSAttributedString(attachment: attachment)
let replacement = NSMutableAttributedString(string: text)
replacement.replaceCharacters(in: replacement.string.nsRange(fromRange: replacement.string.range(of: "*")!), with: image)
attributedString.replaceCharacters(in: aMatch.range, with: replacement)
attributedString.replaceCharacters(in: aMatch.range(at: 0), with: image)
}
}

Expand Down

0 comments on commit 3ee782b

Please sign in to comment.