Down

授权协议 View license
开发语言 Swift
所属分类 开发工具、 程序文档工具
软件类型 开源软件
地区 不详
投 递 者 蔺霄
操作系统 OS X
开源组织
适用人群 未知
 软件概览

Down

Build StatusMIT licensedSwift 5macOSiOStvOSLinuxCode Coverage

Blazing fast Markdown (CommonMark) rendering in Swift, built upon cmark v0.29.0.

Is your app using it? Let us know!

If you're looking for iwasrobbed/Down, you found it! Rob Phillips, the originator of this repository,has transferred it to me as I will be the primary maintainer from now on. Thanks to Rob for bringing Down as far as it has come and forentrusting me with its care.

All existing references to iwasrobbed/Down should redirect to this repository. However, It is recommended to update those urls to pointto this repository.

Maintainers

Installation

Note: Swift support is summarized in the table below.

Swift Version Tag
Swift 5.1 >= 0.9.0
Swift 5.0 >= 0.8.1
Swift 4 >= 0.4.x
Swift 3 0.3.x

now on the master branch and any tag >= 0.8.1 (Swift 4 is >= 0.4.x, Swift 3 is 0.3.x)

Quickly install using CocoaPods:

pod 'Down'

Install using Carthage:

github "johnxnguyen/Down"

Due to limitations in Carthage regarding platform specification, you need to define the platform with Carthage.

e.g.

carthage update --platform iOS

Install using Swift Package Manager:

To add Down to your project, select File → Swift Packages → Add Package Dependency and enter the GitHub URL for Down.See Adding Package Dependencies to Your App for detailed instructions.

Or manually install:

  1. Clone this repository
  2. Drag and drop the Down project into your workspace file, adding the framework in the embedded framework section
  3. Build and run your app
  4. ?
  5. Profit

Robust Performance

cmark can render a Markdown version of War and Peace in the blink of an eye (127 milliseconds on a ten year old laptop, vs. 100-400 milliseconds for an eye blink). In our benchmarks, cmark is 10,000 times faster than the original Markdown.pl, and on par with the very fastest available Markdown processors.

The library has been extensively fuzz-tested using american fuzzy lop. The test suite includes pathological cases that bring many other Markdown parsers to a crawl (for example, thousands-deep nested bracketed text or block quotes).

Output Formats

  • Web View (see DownView class)
  • HTML
  • XML
  • LaTeX
  • groff man
  • CommonMark Markdown
  • NSAttributedString
  • AST (abstract syntax tree)

View Rendering

The DownView class offers a very simple way to parse a UTF-8 encoded string with Markdown and convert it to a web view that can be added to any view:

let downView = try? DownView(frame: self.view.bounds, markdownString: "**Oh Hai**") {
    // Optional callback for loading finished
}
// Now add to view or constrain w/ Autolayout
// Or you could optionally update the contents at some point:
try? downView?.update(markdownString:  "## [Google](https://google.com)") {
    // Optional callback for loading finished
}

Meta example of rendering this README:

Parsing API

The Down struct has everything you need if you just want out-of-the-box setup for parsing and conversion.

let down = Down(markdownString: "## [Down](https://github.com/johnxnguyen/Down)")

// Convert to HTML
let html = try? down.toHTML()
// "<h2><a href=\"https://github.com/johnxnguyen/Down\">Down</a></h2>\n"

// Convert to XML
let xml = try? down.toXML()
// "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n<document xmlns=\"http://commonmark.org/xml/1.0\">\n  <heading level=\"2\">\n    <link destination=\"https://github.com/johnxnguyen/Down\" title=\"\">\n      <text>Down</text>\n    </link>\n  </heading>\n</document>\n"

// Convert to groff man
let man = try? down.toGroff()
// ".SS\nDown (https://github.com/johnxnguyen/Down)\n"

// Convert to LaTeX
let latex = try? down.toLaTeX()
// "\\subsection{\\href{https://github.com/johnxnguyen/Down}{Down}}\n"

// Convert to CommonMark Markdown
let commonMark = try? down.toCommonMark()
// "## [Down](https://github.com/johnxnguyen/Down)\n"

// Convert to an attributed string
let attributedString = try? down.toAttributedString()
// NSAttributedString representation of the rendered HTML;
// by default, uses a stylesheet that matches NSAttributedString's default font,
// but you can override this by passing in your own, using the 'stylesheet:' parameter.

// Convert to abstract syntax tree
let ast = try? down.toAST()
// Returns pointer to AST that you can manipulate

Rendering Granularity

If you'd like more granularity for the output types you want to support, you can create your own struct conforming to at least one of the renderable protocols:

  • DownHTMLRenderable
  • DownXMLRenderable
  • DownLaTeXRenderable
  • DownGroffRenderable
  • DownCommonMarkRenderable
  • DownASTRenderable
  • DownAttributedStringRenderable

Example:

public struct MarkdownToHTML: DownHTMLRenderable {
    /**
     A string containing CommonMark Markdown
    */
    public var markdownString: String

    /**
     Initializes the container with a CommonMark Markdown string which can then be rendered as HTML using `toHTML()`

     - parameter markdownString: A string containing CommonMark Markdown

     - returns: An instance of Self
     */
    @warn_unused_result
    public init(markdownString: String) {
        self.markdownString = markdownString
    }
}

Configuration of DownView

DownView can be configured with a custom bundle using your own HTML / CSS or to do things like supportingDynamic Type or custom fonts, etc. It's completely configurable.

This option can be found in DownView's instantiation function.

Prevent zoom

The default implementation of the DownView allows for zooming in the rendered content. If you want to disable this, then you’ll need to instantiate the DownView with a custom bundle where the viewport in index.html has been assigned user-scalable=no. More info can be found here.

Options

Each protocol has options that will influence either rendering or parsing:

/**
 Default options
*/
public static let `default` = DownOptions(rawValue: 0)

// MARK: - Rendering Options

/**
 Include a `data-sourcepos` attribute on all block elements
*/
public static let sourcePos = DownOptions(rawValue: 1 << 1)

/**
 Render `softbreak` elements as hard line breaks.
*/
public static let hardBreaks = DownOptions(rawValue: 1 << 2)

/**
 Suppress raw HTML and unsafe links (`javascript:`, `vbscript:`,
 `file:`, and `data:`, except for `image/png`, `image/gif`,
 `image/jpeg`, or `image/webp` mime types).  Raw HTML is replaced
 by a placeholder HTML comment. Unsafe links are replaced by
 empty strings. Note that this option is provided for backwards
 compatibility, but safe mode is now the default.
*/
public static let safe = DownOptions(rawValue: 1 << 3)

/**
 Allow raw HTML and unsafe links. Note that safe mode is now
 the default, and the unsafe option must be used if rendering
 of raw HTML and unsafe links is desired.
*/
public static let unsafe = DownOptions(rawValue: 1 << 17)

// MARK: - Parsing Options

/**
 Normalize tree by consolidating adjacent text nodes.
*/
public static let normalize = DownOptions(rawValue: 1 << 4)

/**
 Validate UTF-8 in the input before parsing, replacing illegal
 sequences with the replacement character U+FFFD.
*/
public static let validateUTF8 = DownOptions(rawValue: 1 << 5)

/**
 Convert straight quotes to curly, --- to em dashes, -- to en dashes.
*/
public static let smart = DownOptions(rawValue: 1 << 6)

/**
 Combine smart typography with HTML rendering.
*/
public static let smartUnsaFe = DownOptions(rawValue: (1 << 17) + (1 << 6))

Supports

Swift; iOS 9+, tvOS 9+, macOS 10.11+

Markdown Specification

Down is built upon the CommonMark specification.

A little help from my friends

Please feel free to fork and create a pull request for bug fixes or improvements, being sure to maintain the general coding style, adding tests, and adding comments as necessary.

Credit

This library is a wrapper around cmark, which is built upon the CommonMark Markdown specification.

cmark is Copyright (c) 2014, John MacFarlane. View full license.

  • 内核信号量类似于自旋锁,当锁关闭时,它不允许内核控制路径继续执行。与自旋锁不同的是,当内核控制路径试图获取内核信号量所保护的忙资源时,相应的进程被挂起,进而会导致进程切换;而自旋锁不会导致进程切换。因此,只有可以睡眠的函数才能获取内核信号量;中断处理程序和可延迟函数都不能使用内核信号量。 内核信号量结构如下: /** * 内核信号量结构 */ struct se

  • DOWN操作:linux内核中,对信号量的DOWN操作有如下几种: void down(struct semaphore *sem); //不可中断 int down_interruptible(struct semaphore *sem);//可中断 int down_killable(struct semaphore *sem);//睡眠的进程可以因为受到致命信号而被唤醒,中断获取信号量的操作

  • 英语down的中文是什么意思 英语down是一个多词性的单词,而它具体的中文意思也是各有不同的。以下是百分网小编为大家整理了关于英语单词down表达的中文意思及例句,一起来看看吧! 英语单词down的中文意思 英 [daʊn] 美 [daʊn] 第三人称单数:downs第三人称复数:downs现在分词:downing过去分词:downed过去式:downed 副词 向下; (坐、倒、躺)下; (表

  • 处理过程 1. 检查设备诊断信息中的logbuffer日志,故障时间的日志已经被覆盖,没有发现 GigabitEthernet 2/0/0接口DOWN的记录。 2. 检查GigabitEthernet 2/0/0接口统计信息,发现接口物理和协议都DOWN,并且 Output方向有较多的碰撞错误(3417095 collisions, 3992031 late collisions),初步怀疑防火墙

  • ceph修复osd为down的情况 尝试一、直接重新激活所有osd 1、查看osd树 root@ceph01:~# ceph osd tree ID WEIGHT TYPE NAME UP/DOWN REWEIGHT PRIMARY-AFFINITY -1 0.29279 root default -2 0

  • 看到这个报错,是不是觉得很嘲讽,down了 还 666呢,搞心态吧。也不知道谁定义的这个报错。 先说下报错的背景,开发环境中。我们有个调度系统,并且允许其他系统的使用。调度平台主要功能 定时执行一些,设定好的任务、命令行作业。 大数据平台,反馈出一个调度系统执行作业时,一直报错 session is down 666,导致作业一直执行失败,严重影响了他们的开发,需要我协助解决。 主要原因,调度系统

  •     本人在项目运用中写了一个数据推送的组件,需要多线程频繁调用远程接口进行传输数据,远程请求通过HttpClient 使用 CloseableHttpClient 发起连接后,使用CloseableHttpResponse 接受返回结果,一开始每次请求耗时时间都比较长,因此引入了httpClient连接池。     为什么要使用连接池: 1、降低延迟:如果不采用连接池,每次连接发起Http请求

  • 思科交换机端口down或up故障原因 接入层交换机出现故障,这个交换机的端口f0/6下连一个tp-link 的四口小交换机,上联端口为cisco 3560,有一段时间发现这个F0/6经常down ,然后过一会又up,如此反复,时间有的时候有1天,有的时候有几个小时就发作一次。后来,查了网上的文章,总结了几个原因: 1.可能是lookback包的问题,从f0/6发送的包,又被发回了f0/6造成环路,

  • 源码如下: #include #include #include #include #include char *net_detect(char* net_name) { int skfd = 0; struct ifreq ifr; skfd = socket(AF_INET, SOCK_DGRAM, 0); if(skfd < 0) { printf("%s:%d Open socket er

  • 这个恶心的异常是个什么异常呢?我也不知道,最近把公司一个球机的app项目移植到手机上,经常崩掉,在控制台上能看到的错误只有一行: AndroidRuntime: Shutting down VM 这能看出什么啊?没有详细的堆栈信息,根本没法知道是哪个类哪一行报出来的异常,只能从Application开始,一点一点的注释代码,通过这样的排除法来打到是哪里导致的异常,而且我每解决一个异常,另一个类有异

  • 在sh interface时, 可能会有几种情况: 1. Router#sh int e0 Ethernet0 is up,line protocol is up 第一个信息Serial0 is up是考察到Physical Layer,它会检查连线否有接上或启动。 第二个信息line protocol is up是考察到 Data-link Layer,会从连接端寻找 keepalive 的信号

  • 一、遇到的问题 1、重启机器后,网络异常报:Failed to start LSB: Bring up/down networking 经常会遇到虚拟机重启后,无法建立服务器远程连接的问题,经排查网络不通; 重启网络服务 #重启网络:注意CentOS6需要使用service network restart命令 [root@hu ~]# systemctl restart network Rest

  • 一、查看osd状态找到down状态的osd ceph osd tree 二、删除对应osd 1、调整osd 的crush weight ceph osd crush reweight osd.18 0.1 2、停止osd进程 systemctl stop osd.18 3、将节点状态标记为out ceph osd out osd.18 4、从crush中移除节点 ceph osd crus

 相关资料
  • 问题内容: 在我的应用中,您可以下载一些文件。我使用Android 类进行下载。下载完成后,应该显示一条消息,说明文件已下载。问题是,可能同时有2,3或4个下载。我的代码如下所示: 如何获得完成下载的当前文件名? 非常感谢你。 问题答案: 我想您想在块中放入类似的内容。替换为您的DownloadManager实例。

  • 问题内容: 在我的应用程序上,我使用通用的图像下载器BaseImageDownloader类同步加载画廊的内容。对于来自Imageloader.getInstance()。loadImage异步函数的相同内容,它不会给出任何安全异常并按原样加载图像,但是当我尝试使用BaseImageDownloader同步下载它(而且Imageloader.getInstance()。loadImage()相同)

  • 问题内容: 沿以下几行创建用于下载文件的按钮/链接非常方便: 和 但是,我想 触发仅在单击按钮/链接时下载文件的生成 。换句话说,单击后,我将调用一个方法来生成文件(在本例中为Pentaho报告),将其放置在临时位置并返回指向该文件的指针。然后我告诉那个使用它。问题是, 这有可能 吗? 目前,我们有类似下面的代码,可以正常工作,但是我对是否可以代替它感兴趣。 (如果有区别,请参见1.4.18节。)

  • 问题内容: 我刚刚将项目更新为最新版本的Firebase Storage,现在收到警告:不建议使用downloadURL():使用StorageReference.downloadURLWithCompletion()获取当前的下载URL。 我看了看Firebase图片上传文档,但它仍然引用了现在使用的折旧价格。在下面的代码中,我将以字符串形式获取图像的下载URL。该代码有效,但由于已贬值,因此现

  • 问题内容: 这是我下载的代码: 现在,响应只能在完成处理程序内部访问。 我的问题是如何在下载完成之前访问响应? 我需要NSURLResponse知道: ExpectedContentLength 建议的文件名 MIME类型 问题答案: 不使用共享会话 保留会话属性,使用此功能进行初始化。 然后使用 dataTask 下载图片 在此委托方法中,您可以获得 响应 然后将 dataTask 更改为 do

  • 本文向大家介绍使用a标签的download属性下载文件会有跨域问题吗?如何解决?相关面试题,主要包含被问及使用a标签的download属性下载文件会有跨域问题吗?如何解决?时的应答技巧和注意事项,需要的朋友参考一下 最近刚遇到这个问题,后台返回的图片链接,点击按钮批量下载,标签的 属性只对同源文件有效, 所以我们这里先把图片 url 转为 blob 格式,然后再下载

  • 问题内容: 我在python中将selenium与chromedriver一起使用。 我的问题是selenium导致我尝试访问chrome下载页面(chrome:// downloads)上的元素时出现错误。例如,我尝试获取文件URL“ http://file.jpg ”。 但是当我尝试通过其ID获取元素时,出现了异常。 码: 例外: 通过javascript使用也不适合我。在浏览器中可以看到元素

  • 问题内容: 我正在使用Selenium进行一些网络抓取,现在我想找到用户可以单击并在链接文本,按钮文本,element ,元素中包含“下载”字样(大写)的所有元素。元素或。这可以包括链接,按钮或任何其他元素。 在这个答案中,我找到了一个xpath,供某人在某个xpath中基于特定文本(或不区分大小写和部分匹配)搜索按钮来搜索: 但是即使该页面上有以下链接,在此页面上也不会返回任何结果: 有人知道如