Skip to content

zunda-pixel/MarkdownView

Repository files navigation

MarkdownView

MarkdownView uses swift-markdown as Parser

Markdown Sample
import Algorithms
import MarkdownView
import Markdown
import SwiftUI

struct MarkdownView: View {
  let markdown: String

  var contents: [MarkupContent] {
    let document = Document(
        parsing: markdown,
        options: [.parseBlockDirectives, .parseSymbolLinks, .parseMinimalDoxygen, .parseSymbolLinks]
    )
    return MarkdownViewParser.parse(document: document)
  }
  
  var body: some View {
    ScrollView {
      LazyVStack(alignment: .leading, spacing: 10) {
        ForEach(contents.indexed(), id: \.index) { _, content in
          MarkupContentView(content: content)
        }
      }
    }
  }
}

Adding MarkdownView as a Dependency

To use the MarkdownView plugin in a SwiftPM project, add the following line to the dependencies in your Package.swift file:

.package(url: "https://github.com/zunda-pixel/MarkdownView", from: "0.0.4"),

Include "MarkdownView" as a dependency for your target:

.target(
  name: "<target>",
  dependencies: [
    .product(name: "MarkdownView", package: "MarkdownView"),
  ]
),