Swiftpack.co -  hbowie/NotenikMkdown as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
A Markdown parser developed for use with Notenik
.package(url: "https://github.com/hbowie/NotenikMkdown.git", from: "0.3.0")


The Markdown parser provided with Notenik attempts to satisfy all of the requirements laid out on the Markdown syntax page found on the Daring Fireball site.

There are a few known exceptions.

  • For use within Notenik, you may use double square brackets enclosing the title of another Note to create a link to that Note.

  • Headings may be auto-numbered in a fashion similar to the usual numbering of ordered items.

  • Automatic links for email addresses do not perform any randomized decimal and hex entity-encoding of the email addresses.

  • Backticks-style quotes are not converted to curly quotes.

  • Heading lines will automatically have IDs assigned to them, with the IDs closely based on the contents of the heading lines.

  • A table of contents can be generated by placing '[toc]' (in upper- or lower-case) at any point in the document. The resulting list will contain links to all of the headings following the table of contents.


An example of a typical calling sequence follows.

let md = MkdownParser(markdown)
md.wikiLinkLookup = wikiLinkLookup

Parsing Strategy

The class 'MkdownParser' is the overall parser that is called in order to convert Markdown to HTML.

The first phase of the parser breaks the input text down into lines, examining the beginning and end of each line, and identifying the type of each line.

  • The class 'MkdownLinePhase' is used to keep track of where the parser is within each line, as it is being examined.

  • The enum 'MkdownLineType' defines the various types of lines.

  • The class 'MkdownLine' stores each line, including its type, and the blocks containing the line, and other metadata about the line.

  • The class 'MkdownBlock' identifies an HTML block tag within which a line resides.

  • The class 'MkdownBlockStack' contains an array of blocks surrounding each line.

The resulting lines are stored in an array, which is passed on to the next phase of the parser's processing.

The second phase of the parser goes through the array of lines and generates the HTML output.

The first sub-phase (2.a) breaks the contents of each line down into atomic units, known as "chunks".

  • The class 'MkdownChunk' provides a container for one chunk.

  • The enum 'MkdownChunkType' defines all the possible types of chunks.

The next sub-phase (2.b) goes through the chunks within a block, looking for matches between beginning and ending markers of various sorts.

The final sub-phase (2.c) then goes through the chunks and generates HTML.


Stars: 0
Last commit: 3 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API