diff --git a/Sources/FireworkVideoUI/Utils/String+Markdown.swift b/Sources/FireworkVideoUI/Utils/String+Markdown.swift index 978dd8d..93158f6 100644 --- a/Sources/FireworkVideoUI/Utils/String+Markdown.swift +++ b/Sources/FireworkVideoUI/Utils/String+Markdown.swift @@ -9,69 +9,69 @@ import Foundation public extension String { func parseMarkdown() -> String { - var resultMarkdownText = self + var result = self // markdown unordered item - resultMarkdownText = resultMarkdownText.replacingOccurrences(of: "\n- ", with: "\n  • ") - resultMarkdownText = resultMarkdownText.replacingOccurrences(of: "\n* ", with: "\n  • ") + result = result.replacingOccurrences(of: "\n- ", with: "\n  • ") + result = result.replacingOccurrences(of: "\n* ", with: "\n  • ") // markdown ordered item - resultMarkdownText = parse( - resultMarkdownText, + result = parse( + result, pattern: "\n(\\d+?)\\. ", createReplaceContent: { content in "\n  \(content). " } ) // markdown strikethrough - resultMarkdownText = parse( - resultMarkdownText, + result = parse( + result, pattern: "~~(.+?)~~", createReplaceContent: { content in "\(content)" } ) // markdown strong - resultMarkdownText = parse( - resultMarkdownText, + result = parse( + result, pattern: "\\*\\*(.+?)\\*\\*", createReplaceContent: { content in "\(content)" } ) // markdown italic - resultMarkdownText = parse( - resultMarkdownText, + result = parse( + result, pattern: "\\*(.+)\\*", createReplaceContent: { content in "\(content)" } ) // markdown h1 - resultMarkdownText = parse( - resultMarkdownText, + result = parse( + result, pattern: "\n# (.+)(?=($|\n))", createReplaceContent: { content in "\n

\(content)

" } ) // markdown h2 - resultMarkdownText = parse( - resultMarkdownText, + result = parse( + result, pattern: "\n## (.+)(?=($|\n))", createReplaceContent: { content in "\n

\(content)

" } ) // markdown h3 - resultMarkdownText = parse( - resultMarkdownText, + result = parse( + result, pattern: "\n### (.+?)(?=($|\n))", createReplaceContent: { content in "\n

\(content)

" } ) - resultMarkdownText = parseMarkdownLink(resultMarkdownText) - resultMarkdownText = resultMarkdownText.replacingOccurrences(of: "\n", with: "
") - return resultMarkdownText + result = parseMarkdownLink(result) + result = result.replacingOccurrences(of: "\n", with: "
") + return result } private func parse(