Ink: A Pure-Swift Markdown Parser by John Sundell

John Sundell:

Welcome to Ink, a fast and flexible Markdown parser written in Swift. It can be used to convert Markdown-formatted strings into HTML, and also supports metadata parsing, as well as powerful customization options for fine-grained post-processing. It was built with a focus on Swift-based web development and other HTML-centered workflows.

Ink is used to render all articles on

This sort of performance is harder to achieve than you’d think:

Ink was designed to be as fast and efficient as possible, to enable hundreds of full-length Markdown articles to be parsed in a matter of seconds, while still offering a fully customizable API as well. Two key characteristics make this possible:

  1. Ink aims to get as close to O(N) complexity as possible, by minimizing the amount of times it needs to read the Markdown strings that are passed to it, and by optimizing its HTML rendering to be completely linear. While true O(N) complexity is impossible to achieve when it comes to Markdown parsing, because of its very flexible syntax, the goal is to come as close to that target as possible.
  2. A high degree of memory efficiency is achieved thanks to Swift’s powerful String API, which Ink makes full use of — by using string indexes, ranges and substrings, rather than performing unnecessary string copying between its various operations.

There’s some common syntax that isn’t supported (yet?), but this is already a great Markdown implementation.

Thursday, 28 November 2019