All Projects → gonzalezreal → Markdownui

gonzalezreal / Markdownui

Licence: mit
Render Markdown text in SwiftUI

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Markdownui

Flexmark Java
CommonMark/Markdown Java parser with source level AST. CommonMark 0.28, emulation of: pegdown, kramdown, markdown.pl, MultiMarkdown. With HTML to MD, MD to PDF, MD to DOCX conversion modules.
Stars: ✭ 1,673 (+708.21%)
Mutual labels:  markdown, commonmark
Texme
Self-rendering Markdown + LaTeX documents
Stars: ✭ 1,970 (+851.69%)
Mutual labels:  markdown, commonmark
Commonmark Java
Java library for parsing and rendering CommonMark (Markdown)
Stars: ✭ 1,675 (+709.18%)
Mutual labels:  markdown, commonmark
Vditor
♏ 一款浏览器端的 Markdown 编辑器,支持所见即所得(富文本)、即时渲染(类似 Typora)和分屏预览模式。An In-browser Markdown editor, support WYSIWYG (Rich Text), Instant Rendering (Typora-like) and Split View modes.
Stars: ✭ 3,773 (+1722.71%)
Mutual labels:  markdown, commonmark
Commonmark
Create, parse, and render Markdown text according to the CommonMark specification
Stars: ✭ 147 (-28.99%)
Mutual labels:  markdown, commonmark
Elm Markdown
Pure Elm markdown parsing and rendering
Stars: ✭ 96 (-53.62%)
Mutual labels:  markdown, commonmark
Mdme
Self-rendering Markdown content
Stars: ✭ 140 (-32.37%)
Mutual labels:  markdown, commonmark
Markra
A Markdown-to-JIRA syntax editor.
Stars: ✭ 64 (-69.08%)
Mutual labels:  markdown, commonmark
Markdown It
Markdown parser, done right. 100% CommonMark support, extensions, syntax plugins & high speed
Stars: ✭ 12,638 (+6005.31%)
Mutual labels:  markdown, commonmark
Vditor
♏ 一款浏览器端的 Markdown 编辑器。
Stars: ✭ 1,742 (+741.55%)
Mutual labels:  markdown, commonmark
Html To Markdown
Convert HTML to Markdown with PHP
Stars: ✭ 1,293 (+524.64%)
Mutual labels:  markdown, commonmark
Markdown
CommonMark-compliant markdown parser and renderer in Go. This repository has moved to https://gitlab.com/golang-commonmark/markdown
Stars: ✭ 180 (-13.04%)
Mutual labels:  markdown, commonmark
Marko
A markdown parser with high extensibility.
Stars: ✭ 77 (-62.8%)
Mutual labels:  markdown, commonmark
Goldmark
🏆 A markdown parser written in Go. Easy to extend, standard(CommonMark) compliant, well structured.
Stars: ✭ 1,813 (+775.85%)
Mutual labels:  markdown, commonmark
Markd
Yet another markdown parser, Compliant to CommonMark specification, written in Crystal.
Stars: ✭ 73 (-64.73%)
Mutual labels:  markdown, commonmark
Editor.md
The open source embeddable online markdown editor (component).
Stars: ✭ 11,741 (+5571.98%)
Mutual labels:  markdown, commonmark
React Markdown
Markdown component for React
Stars: ✭ 8,047 (+3787.44%)
Mutual labels:  markdown, commonmark
Qlcommonmark
QuickLook generator for beautifully rendering CommonMark documents on macOS
Stars: ✭ 36 (-82.61%)
Mutual labels:  markdown, commonmark
Down
Blazing fast Markdown / CommonMark rendering in Swift, built upon cmark.
Stars: ✭ 1,895 (+815.46%)
Mutual labels:  markdown, commonmark
Commonmark
Highly-extensible PHP Markdown parser which fully supports the CommonMark and GFM specs.
Stars: ✭ 2,128 (+928.02%)
Mutual labels:  markdown, commonmark

MarkdownUI

CI contact: @gonzalezreal

MarkdownUI is a library for rendering Markdown in SwiftUI, fully compliant with the CommonMark Spec.

Supported Platforms

You can use the Markdown SwiftUI view in the following platforms:

  • macOS 11.0+
  • iOS 14.0+
  • tvOS 14.0+

The NSAttributedString extension is available in:

  • macOS 10.12+
  • iOS 11.0+
  • tvOS 11.0+
  • watchOS 3.0+

Usage

You can create a Markdown view in SwiftUI by providing a CommonMark document.

Markdown(
    #"""
    It's very easy to make some words **bold** and other words *italic* with Markdown.

    **Want to experiment with Markdown?** Play with the [reference CommonMark
    implementation](https://spec.commonmark.org/dingus/).
    """#
)

Markdown text

From Swift 5.4 onwards, you can create a Markdown view using an embedded DSL for the contents.

Markdown {
    Heading(level: 2) {
        "Markdown lists"
    }
    "Sometimes you want numbered lists:"
    List(start: 1) {
        "One"
        "Two"
        "Three"
    }
    "Sometimes you want bullet points:"
    List {
        "Start a line with a star"
        "Profit!"
        Item {
            "And you can have sub points:"
            List {
                "Like this"
                "And this"
            }
        }
    }
}

A Markdown view renders text using a body font appropriate for the current platform. You can choose a different font or customize other properties like the foreground color, code font, or heading font sizes using the markdownStyle(_:) view modifier.

Markdown(
    #"""
    ## Inline code
    If you have inline code blocks, wrap them in backticks: `var example = true`.
    """#
)
.markdownStyle(
    DefaultMarkdownStyle(
        font: .system(.body, design: .serif),
        codeFontName: "Menlo",
        codeFontSizeMultiple: 0.88
    )
)

Markdown style

A Markdown view always uses all the available width and adjusts its height to fit its rendered text.

Use the accentColor(_:) view modifier to configure the link color.

Markdown("Play with the [reference CommonMark implementation](https://spec.commonmark.org/dingus/).")
    .accentColor(.purple)

Use modifiers like lineLimit(_:) and truncationMode(_:) to configure how the view handles space constraints.

Markdown("> Knowledge is power, Francis Bacon.")
    .lineLimit(1)

You can set the alignment of the text by using the multilineTextAlignment(_:) view modifier.

Markdown(
    #"""
    There are many different ways to style code with CommonMark. If you
    have inline code blocks, wrap them in backticks: `var example = true`.
    """#
)
.multilineTextAlignment(.trailing)

Text alignment

Using the NSAttributedString Extension

If you are not yet using SwiftUI, you can use the NSAttributedString extension to render Markdown in your app.

let attributedString = NSAttributedString(
    document: #"""
    It's very easy to make some words **bold** and other words *italic* with Markdown.
    """#,
    style: DefaultMarkdownStyle(font: .system(.body))
)

Supported Markdown Elements

MarkdownUI uses the CommonMark reference parser and it is fully compliant with the CommonMark Spec.

You can explore all the capabilities of this package in the companion demo project.

Demo

Installation

You can add MarkdownUI to an Xcode project by adding it as a package dependency.

  1. From the File menu, select Swift Packages › Add Package Dependency…
  2. Enter https://github.com/gonzalezreal/MarkdownUI into the package repository URL text field
  3. Link MarkdownUI to your application target

Other Libraries

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].