Giter VIP home page Giter VIP logo

swiftmark's Introduction

SwiftMark

Build Status

SwiftMark is a Markdown to HTML renderer built in Swift.

#pureswift

Usage

SwiftMark is a SwiftPM package (though versions 1.0.0 to 1.3.0 also work as a CocoaPod). Add this line to your dependencies array in your Package.swift:

Package(url: "https://github.com/calebkleveter/SwiftMark.git", majorVersion: 1)

Using SwiftMark is very simple. Just create a renderer, call render, and pass in the Markdown text.

do {
   let renderer = MarkdownRenderer()
   let html = try renderer.render(markdownText)
} catch let rror {
    print(error)
}

The result of the .render() method is the HTML form of the Markdown text passed in.

License

The whole SwiftMark package is under the MIT license agreement.

Attribution

Thanks to @matthewcheok and his tutorial on Writing a Lexer in Swift.

swiftmark's People

Contributors

calebkleveter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

swiftmark's Issues

Markdown Flavor

Create a struct called MarkdownFlavor with static properties with an array of the renderers to use.

public struct MarkdownFlavor {
    public static commonMark(renderers: [...])
    public static gfm(renderers: [...])


    public let renderers: [SyntaxRenderer]
}

We use a struct instead of an enum so it can be extended and have other cases added to it.

Roadmap Feature Request: LaTeX math support

Support dollars ($InlineMath$, $$DisplayMath$$) syntax as Markdown delimiters for LaTeX math expressions. Possibly also add single backslash \(InlineMath\), \[DisplayMath\] and double backslash \\(InlineMath\\), \\[DisplayMath\\] syntax. Provide an enable|disable for each implemented syntax.

Such LaTeX math sections would be passed through to html for rendering by a library such as MathJax (more comprehensive) or KaTeX (faster).

Various Markdown editing environments support LaTeX math. (e.g. Atom, MacDown, MWeb). It would be nice if markdown containing LaTeX math could be processed by SwiftMark. :-)

Aside, but related FYI, Apple has added LaTeX mathematical equation support to Pages, Numbers, Keynote, and iBooks Author. Apple: HT207569, HT202501

In my use case, dollars are most frequently used in Markdown with the double backslash as a distant second. I don't use single backslash notation except for some testing & evaluation. One such test set is here: 004.55_Markdown-CLI-Evaluation.

There is also a community syntax survey of Math in MarkDown on GitHub. The appendix summary table shows the dollars to be the a widely used Markdown math delimiter syntax.

Version 2

  • Modularity
  • Increased speed
  • Replace MarkdownRenderer with Markdown

Increase Speed

As the algorithm is currently written, the rendering is probably fairly slow. We need to run some performance tests and try some other methods of rendering:

  • Using an array of bits (with the vapor/bits package)
  • Using an array of Strings and reducing it

The way that the renderers are registered is incredibly inefficient. This should be changed.

Multi-Level Lexing and Parsing

The GFM spec states that many blocks should be automatically ended if you reach the end of a container block. This could be done if you parse the container blocks first and then their contents second, along with having the proper regex pattern at the end of your pattern (ending with $).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.