From b451ffce7bd9aa85772ab63a795fb79302221dcf Mon Sep 17 00:00:00 2001 From: starfall_9000 Date: Fri, 9 Apr 2021 05:41:26 +0700 Subject: [PATCH] process order list regex --- Sources/SwiftyMarkdown/SwiftyLineProcessor.swift | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftyMarkdown/SwiftyLineProcessor.swift b/Sources/SwiftyMarkdown/SwiftyLineProcessor.swift index b6acadd..9ee7b2f 100644 --- a/Sources/SwiftyMarkdown/SwiftyLineProcessor.swift +++ b/Sources/SwiftyMarkdown/SwiftyLineProcessor.swift @@ -125,7 +125,12 @@ public class SwiftyLineProcessor { return nil } - if !text.contains(element.token) { + if element.token == "1. " { + // replace all text format "2. ", "3. ", ..etc with format "1. " + output = processOrderListRegex(output) + } + + if !text.contains(element.token) && element.token != "1. " { continue } @@ -244,6 +249,14 @@ public class SwiftyLineProcessor { return foundAttributes } + func processOrderListRegex(_ text: String) -> String { + let regex = try? NSRegularExpression(pattern: "^[0-9]+. ", options: .caseInsensitive) + let range = NSMakeRange(0, text.count) + let result = regex?.stringByReplacingMatches(in: text, options: [], range: range, + withTemplate: "1. ") + return result ?? text + } + }