Markdownosaur Documentation

repository·main·Indexed 20 days ago

https://github.com/christianselig/markdownosaur

A lightweight Swift utility that converts Markdown source text into NSAttributedString objects using Apple's swift-markdown library. Designed for iOS, iPadOS, and macOS, it provides styling flexibility and support for versions earlier than iOS 15. Supports lists, emphasis, links, blockquotes, code, strikethrough, and headers.

Tokens
659
Snippets
2
Records
4
Agent score
19%

What's inside Markdownosaur

  1. What is Markdownosaur and when should I use it?

    main

    Markdownosaur is a lightweight library that uses Apple's swift-markdown library to convert Markdown source into an NSAttributedString for display on iOS, iPadOS, or macOS.

    When to use it instead of the native iOS 15+ NSAttributedString Markdown initializer:

    • When you need increased flexibility in styling the resulting NSAttributedString.
    • When you need support for Markdown elements like tables (requires custom integration).
    • When you need to support iOS versions earlier than iOS 15.
  2. Supported Markdown syntax in Markdownosaur

    main

    Markdownosaur supports a variety of standard Markdown syntax elements, which are converted into NSAttributedString. Supported features include:

    • Lists: Both ordered (numbered) and unordered (bulleted) lists, including nested items.
    • Emphasis: Bold (**text**), italics (*text*), and combined nesting (e.g., **an *[emphasized link](url)* inside strong text**).
    • Links: Standard inline links [text](url).
    • Blockquotes: Indicated by the > character.
    • Code: Inline code (using backticks) and fenced code blocks (using triple backticks).
    • Strikethrough: Text with strikethrough.
    • Headers: Standard Markdown headers (e.g., ### Header).

    Note: While tables are mentioned as supported, full support may require more than just NSAttributedString.

    func yeah() -> NSAttributedString {
        // TODO: Write code
    }
  3. Use Markdownosaur to convert Markdown to NSAttributedString

    main

    To render Markdown text, first create a Document by parsing your source string. Then, initialize a Markdownosaur instance and call attributedString(from:) passing in that document. The resulting NSAttributedString can be used in any UI component that supports attributed strings, such as a UILabel.

    let source = "Here is some **very** cool and simple Markdown"
    let document = Document(parsing: source)
    
    var markdownosaur = Markdownosaur()
    let attributedString = markdownosaur.attributedString(from: document)
    
    // For instance…
    label.attributedText = attributedString