Skip to content

Commit 88433ce

Browse files
committed
🐛 Do not process email links additionally
1 parent 7570cc2 commit 88433ce

File tree

4 files changed

+2
-54
lines changed

4 files changed

+2
-54
lines changed

Mac/Business/Markdown.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func renderMarkdownHTML(markdown: String) -> String? {
88
defer { cmark_parser_free(parser) }
99

1010
// 附加常见的 GFM 扩展
11-
let extensions = ["table", "autolink", "emoji", "footnotes", "strikethrough", "tasklist"]
11+
let extensions = ["table", "emoji", "footnotes", "strikethrough", "tasklist"]
1212
for extName in extensions {
1313
if let ext = cmark_find_syntax_extension(extName) {
1414
cmark_parser_attach_syntax_extension(parser, ext)

Mac/Extensions/String+.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,7 @@ public extension String {
6464

6565
return self
6666
}
67-
68-
func isValidEmail() -> Bool {
69-
let pattern = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
70-
71-
if let regex = try? NSRegularExpression(pattern: pattern, options: .caseInsensitive) {
72-
return regex.firstMatch(in: self, options: [], range: NSRange(location: 0, length: count)) != nil
73-
}
74-
75-
return false
76-
}
77-
67+
7868
func isNumberList() -> Bool {
7969
let pattern = "^(( |\t)*[0-9]+\\. )"
8070
if let regex = try? NSRegularExpression(pattern: pattern) {

Mac/Helpers/NotesTextProcessor.swift

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -724,29 +724,6 @@ public class NotesTextProcessor {
724724
}
725725
}
726726

727-
// We detect and process inline mailto links not formatted
728-
NotesTextProcessor.autolinkEmailRegex.matches(string, range: paragraphRange) { result in
729-
guard let range = result?.range else { return }
730-
let substring = attributedString.mutableString.substring(with: range)
731-
guard substring.lengthOfBytes(using: .utf8) > 0 else { return }
732-
733-
attributedString.addAttribute(.foregroundColor, value: linkColor, range: range)
734-
735-
if substring.isValidEmail() {
736-
attributedString.addAttribute(.link, value: "mailto:\(substring)", range: range)
737-
} else {
738-
attributedString.addAttribute(.link, value: substring, range: range)
739-
}
740-
741-
if NotesTextProcessor.hideSyntax {
742-
NotesTextProcessor.mailtoRegex.matches(string, range: range) { innerResult in
743-
guard let innerRange = innerResult?.range else { return }
744-
attributedString.addAttribute(.font, value: hiddenFont, range: innerRange)
745-
attributedString.addAttribute(.foregroundColor, value: hiddenColor, range: innerRange)
746-
}
747-
}
748-
}
749-
750727
NotesTextProcessor.imageInlineRegex.matches(string, range: paragraphRange) { result in
751728
guard let range = result?.range else { return }
752729

@@ -1244,21 +1221,6 @@ public class NotesTextProcessor {
12441221

12451222
public static let autolinkPrefixRegex = MarklightRegex(pattern: autolinkPrefixPattern, options: [.allowCommentsAndWhitespace, .dotMatchesLineSeparators])
12461223

1247-
fileprivate static let autolinkEmailPattern = [
1248-
"(?:mailto:)?",
1249-
"(",
1250-
" [-.\\w]+",
1251-
" \\@",
1252-
" [-a-z0-9]+(\\.[-a-z0-9]+)*\\.[a-z]+",
1253-
")"
1254-
].joined(separator: "\n")
1255-
1256-
public static let autolinkEmailRegex = MarklightRegex(pattern: autolinkEmailPattern, options: [.allowCommentsAndWhitespace, .dotMatchesLineSeparators])
1257-
1258-
fileprivate static let mailtoPattern = "mailto:"
1259-
1260-
public static let mailtoRegex = MarklightRegex(pattern: mailtoPattern, options: [.allowCommentsAndWhitespace, .dotMatchesLineSeparators])
1261-
12621224
/// maximum nested depth of [] and () supported by the transform;
12631225
/// implementation detail
12641226
fileprivate static let _nestDepth = 6

Mac/View/EditTextView.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -937,10 +937,6 @@ class EditTextView: NSTextView, NSTextFinderClient {
937937
}
938938

939939
override func clicked(onLink link: Any, at charIndex: Int) {
940-
if let link = link as? String, link.isValidEmail(), let mail = URL(string: "mailto:\(link)") {
941-
NSWorkspace.shared.open(mail)
942-
return
943-
}
944940

945941
let range = NSRange(location: charIndex, length: 1)
946942

0 commit comments

Comments
 (0)