Skip to content

GIKICoder/GMarkdown

Repository files navigation

GMarkdown

语言: English | 中文

GMarkdown is a powerful and versatile Markdown rendering library designed for Swift developers. Built on top of the swift-markdown parser, GMarkdown offers pure native rendering capabilities, ensuring seamless integration and high performance for your iOS applications.

GMarkdown is currently in the testing phase. Although efforts have been made to support different styles of markdown, some code-level optimizations and modifications are still needed to make the GMarkdown architecture more reasonable. If time permits, part of the code logic will be redesigned in the future.

✨ What's New

🎉 CocoaPods Support Now Available!

GMarkdown can now be easily integrated into your project using CocoaPods. Simply add the following to your Podfile:

pod 'GMarkdown'

Features

  • Pure Native Rendering: Enjoy the benefits of pure native rendering for all your markdown content, ensuring fast and efficient performance.
  • Rich Text Support: GMarkdown supports a wide range of rich text styles, making your markdown content look professional and polished.
  • Image Rendering: Effortlessly render images within your markdown content.
  • Code Blocks: Display code with syntax highlighting, making it easy to present and read code snippets.
  • Tables: Create and render tables to organize your data effectively.
  • LaTeX Math Formulas: Render complex mathematical equations using LaTeX, perfect for academic and scientific content.
  • Mermaid Diagrams: Create beautiful flowcharts, sequence diagrams, and other visual representations using Mermaid syntax.
  • HTML Preview: Seamlessly preview and render HTML content within your markdown documents for enhanced formatting flexibility.

Requirements

GMarkdown works on iOS 13+ and depends on the following frameworks:

Installation

Swift Package Manager (Recommended)

GMarkdown is also available through Swift Package Manager. To include it in your project, add the following to your Package.swift:

dependencies: [
    .package(url: "https://github.com/GIKICoder/GMarkdown.git", from: "0.0.6")
]

CocoaPods

GMarkdown is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'GMarkdown'

Then run:

pod install

Usage

Initialization

To initialize and add a GMarkdown view to your view hierarchy:

let markdownView = GMarkdownMultiView()
view.addSubview(markdownView)
markdownView.frame = view.bounds

Example

Here's a complete example of how to load and render Markdown content from a file:

func setupMarkdown() async {
    guard let filepath = Bundle.main.path(forResource: "markdown", ofType: nil),
          let filecontents = try? String(contentsOfFile: filepath, encoding: .utf8) else {
        return
    }

    let chunks = await parseMarkdown(filecontents)

    DispatchQueue.main.async { [weak self] in
        self?.markdownView.updateMarkdown(chunks)
    }
}

func parseMarkdown(_ content: String) async -> [GMarkChunk] {
    return await withCheckedContinuation { continuation in
        DispatchQueue.global(qos: .userInitiated).async {
            let processor = GMarkProcessor()
            let chunks = processor.process(markdown: content)
            continuation.resume(returning: chunks)
        }
    }
}

Example

Youtube

Screenshots

Screenshot 1 Screenshot 2 Screenshot 3 Screenshot 4 Screenshot 5

License

GMarkdown is released under the MIT license. See LICENSE for details.

Contributions

Contributions are welcome! Please submit pull requests or open issues to help improve GMarkdown.


Happy coding!

About

iOS Markdown View in UIKit with support for code tables, LaTeX, Mermaid and more

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages