Skip to content

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.

License

Notifications You must be signed in to change notification settings

GIKICoder/GMarkdown

Repository files navigation

GMarkdown

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.

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.

Requirements

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

Installation

Swift Package Manager

GMarkdown is 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.1")
]

CocoaPods

If you prefer using CocoaPods, you can integrate GMarkdown via cocoapods-spm:

spm_pkg "GMarkdown", :url => "https://github.com/GIKICoder/GMarkdown.git", :branch => "main"

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)
        }
    }
}

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

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.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages