在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):kristopherjohnson/Markingbird开源软件地址(OpenSource Url):https://github.com/kristopherjohnson/Markingbird开源编程语言(OpenSource Language):Swift 57.9%开源软件介绍(OpenSource Introduction):(Note: I am no longer actively working on or maintaining Markingbird. If anyone wants to take on the responsibility of ongoing maintenance, please fork this repo and let me know, and I'll direct people to your fork.) Markingbird: A Markdown Processor in SwiftThis library provides a Markdown processor written in Swift for OS X and iOS. It is a translation/port of the MarkdownSharp processor used by Stack Overflow. The port currently passes all of the test cases in MarkdownSharp's How To Use ItThe Xcode project packages the library as a Cocoa framework. However, as all the code is in the file Typically, an app obtains some Markdown-formatted text somehow (read from a file, entered by a user, etc.), creates a // If using Markingbird framework, import the module.
// (If Markdown.swift is in your target, this is unneeded.)
import Markingbird
let inputText: String = getMarkdownFormatTextSomehow()
// Note: must use `var` rather than `let` because the
// Markdown struct mutates itself during processing
var markdown = Markdown()
let outputHtml: String = markdown.transform(inputText)
// Use MarkdownOptions to enable non-default features
var options = MarkdownOptions()
options.autoHyperlink = true
options.autoNewlines = true
options.emptyElementSuffix = ">"
options.encodeProblemUrlCharacters = true
options.linkEmails = false
options.strictBoldItalic = true
var fancyMarkdown = Markdown(options: options)
let fancyOutput = fancyMarkdown.transform(inputText) A single To-Do
Implementation NotesFor the most part, the code is a straightforward line-by-line translation of the C# code into Swift. Nothing has been done to make the code more "Swift-like" (whatever that means) or to improve the design. The C# code is itself a translation of Perl and PHP code, and the result is a bit of a mess. It is not a good example of Swift code, nor a good example of how to process Markdown. (It's really not a good example of anything.) Aside from changes necessary for compatibility with Swift syntax and semantics, these are the only stylistic changes made during the translation:
When the Swift language and its standard library stabilize, it might make sense to reimplement this library to take advantage of advanced Swift features, but for now a simple translation of a mature implementation in a similar programming language is desirable as it is unlikely to break as Swift evolves. A To ease translation from C# to Swift, the private types The implementation uses many complex regular expressions. The C# version declares these using verbatim string literals that span multiple lines and eliminate the need to escape special characters. Unfortunately, Swift does not allow string literals to span multiple lines, and requires escaping of all special characters. To translate the multi-line regular expression strings to Swift in a faithful and readable way, the // Original C# source
string attr = @"
(?> # optional tag attributes
\s # starts with whitespace
(?>
[^>""/]+ # text outside quotes
|
/+(?!>) # slash not followed by >
|
""[^""]*"" # text inside double quotes (tolerate >)
|
'[^']*' # text inside single quotes (tolerate >)
)*
)?
"; // Translated to Swift
let attr = "\n".join([
"(?> # optional tag attributes",
" \\s # starts with whitespace",
" (?>",
" [^>\"/]+ # text outside quotes",
" |",
" /+(?!>) # slash not followed by >",
" |",
" \"[^\"]*\" # text inside double quotes (tolerate >)",
" |",
" '[^']*' # text inside single quotes (tolerate >)",
" )*",
")?"
]) The following transformations were made to the C# verbatim string literals to make them legal Swift literals and to conform to
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论