Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
glushchenko committed Feb 3, 2021
1 parent c10c4b2 commit 3247988
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions FSNotes/Helpers/NotesTextProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -823,35 +823,35 @@ public class NotesTextProcessor {
}

// We detect and process italics
NotesTextProcessor.italicRegex.matches(string, range: paragraphRange) { (result) -> Void in
guard let range = result?.range else { return }
NotesTextProcessor.strictItalicRegex.matches(string, range: paragraphRange) { (result) -> Void in
guard let range = result?.range(at: 3) else { return }

if NotesTextProcessor.isLink(attributedString: attributedString, range: range) {
return
}

attributedString.addAttribute(.font, value: italicFont, range: range)

NotesTextProcessor.boldRegex.matches(string, range: range) { (result) -> Void in
NotesTextProcessor.strictBoldRegex.matches(string, range: range) { (result) -> Void in
guard let range = result?.range else { return }
let boldItalic = Font.addBold(font: italicFont)
attributedString.addAttribute(.font, value: boldItalic, range: range)
}

attributedString.fixAttributes(in: range)

let preRange = NSMakeRange(range.location, 1)
let preRange = NSMakeRange(range.location - 1, 1)
attributedString.addAttribute(.foregroundColor, value: NotesTextProcessor.syntaxColor, range: preRange)
hideSyntaxIfNecessary(range: preRange)

let postRange = NSMakeRange(range.location + range.length - 1, 1)
let postRange = NSMakeRange(range.location + range.length, 1)
attributedString.addAttribute(.foregroundColor, value: NotesTextProcessor.syntaxColor, range: postRange)
hideSyntaxIfNecessary(range: postRange)
}

// We detect and process bolds
NotesTextProcessor.boldRegex.matches(string, range: paragraphRange) { (result) -> Void in
guard let range = result?.range else { return }
NotesTextProcessor.strictBoldRegex.matches(string, range: paragraphRange) { (result) -> Void in
guard let range = result?.range(at: 3) else { return }

if NotesTextProcessor.isLink(attributedString: attributedString, range: range) {
return
Expand All @@ -870,11 +870,11 @@ public class NotesTextProcessor {

attributedString.fixAttributes(in: range)

let preRange = NSMakeRange(range.location, 2)
let preRange = NSMakeRange(range.location - 2, 2)
attributedString.addAttribute(.foregroundColor, value: NotesTextProcessor.syntaxColor, range: preRange)
hideSyntaxIfNecessary(range: preRange)

let postRange = NSMakeRange(range.location + range.length - 2, 2)
let postRange = NSMakeRange(range.location + range.length, 2)
attributedString.addAttribute(.foregroundColor, value: NotesTextProcessor.syntaxColor, range: postRange)
hideSyntaxIfNecessary(range: postRange)
}
Expand Down Expand Up @@ -1374,11 +1374,11 @@ public class NotesTextProcessor {
*/

fileprivate static let strictBoldPattern = "(^|[\\W_])(?:(?!\\1)|(?=^))(\\*|_)\\2(?=\\S)(.*?\\S)\\2\\2(?!\\2)(?=[\\W_]|$)"

public static let strictBoldRegex = MarklightRegex(pattern: strictBoldPattern, options: [.anchorsMatchLines])

fileprivate static let boldPattern = "(\\*\\*|__) (?=\\S) (.+?[*_]*) (?<=\\S) \\1"

public static let boldRegex = MarklightRegex(pattern: boldPattern, options: [.allowCommentsAndWhitespace, .anchorsMatchLines])

fileprivate static let strikePattern = "(\\~\\~) (?=\\S) (.+?[~]*) (?<=\\S) \\1"
Expand All @@ -1393,13 +1393,13 @@ public class NotesTextProcessor {
*/

fileprivate static let strictItalicPattern = "(^|[\\W_])(?:(?!\\1)|(?=^))(\\*|_)(?=\\S)((?:(?!\\2).)*?\\S)\\2(?!\\2)(?=[\\W_]|$)"

public static let strictItalicRegex = MarklightRegex(pattern: strictItalicPattern, options: [.anchorsMatchLines])

fileprivate static let italicPattern = "(\\_){1} (?=\\S) (.+?) (?<=\\S) \\1"

public static let italicRegex = MarklightRegex(pattern: italicPattern, options: [.allowCommentsAndWhitespace, .anchorsMatchLines])

fileprivate static let autolinkPattern = "((https?|ftp):[^\\)'\">\\s]+)"

public static let autolinkRegex = MarklightRegex(pattern: autolinkPattern, options: [.allowCommentsAndWhitespace, .dotMatchesLineSeparators])
Expand Down

0 comments on commit 3247988

Please sign in to comment.