Giter Club home page Giter Club logo

swiftui-markdown's Introduction

SwiftUI Markdown

Buy me a coffee CI SwiftUI Support

Render Markdown text in SwiftUI. It is a preview based on the Marked implementation.

swiftui-markdown.mov

Markdown Package Screenshot

Markdown Package Screenshot

Markdown Package Screenshot

Installation

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

  1. From the File menu, select Add Packages…
  2. Enter https://github.com/jaywcjlove/swiftui-markdown the Search or Enter Package URL search field
  3. Link Markdown to your application target

Or add the following to Package.swift:

.package(url: "https://github.com/jaywcjlove/swiftui-markdown", from: "1.0.0")

Or add the package in Xcode.

Usage

import SwiftUI
import Markdown

struct ContentView: View {
  @State private var mdStr: String = """
    ## Hello World
    
    Render Markdown text in SwiftUI.
    """
  var body: some View {
    VStack {
      Markdown(content: $mdStr)
      TextEditor(text: $mdStr)
    }
  }
}

.markdownStyle()

Setting markdown related styles.

Markdown(content: $mdStr)
  .markdownStyle(
      MarkdownStyle(
        padding: 0, paddingTop: 115, paddingBottom: 2, paddingLeft: 130, paddingRight: 5
      )
  )
Markdown(content: $mdStr)
  .markdownStyle(MarkdownStyle(padding: 35 ))

Configure

image

Contributors

As always, thanks to our amazing contributors!

Made with contributors.

License

Licensed under the MIT License.

swiftui-markdown's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

swiftui-markdown's Issues

Example could not work

2023-08-17 18:57:13.138245+0800 MD2[3201:3124067] [SwiftUI] Accessing Environment<ColorScheme>'s value outside of being installed on a View. This will always read the default value and will not update.
2023-08-17 18:57:13.144124+0800 MD2[3201:3124067] -[WKWebView _setDrawsTransparentBackground:] is deprecated and should not be used.
2023-08-17 18:57:13.190866+0800 MD2[3201:3124067] Metal API Validation Enabled
2023-08-17 18:57:13.305731+0800 MD2[3201:3124067] [Process] 0x12205c480 - [PID=0] WebProcessProxy::didFinishLaunching: Invalid connection identifier (web process failed to launch)
2023-08-17 18:57:13.305812+0800 MD2[3201:3124067] [Process] 0x12205c480 - [PID=0] WebProcessProxy::processDidTerminateOrFailedToLaunch: reason=Crash
2023-08-17 18:57:13.306167+0800 MD2[3201:3124067] [Process] 0x12082de18 - [pageProxyID=6, webPageID=7, PID=0] WebPageProxy::processDidTerminate: (pid 0), reason=Crash
2023-08-17 18:57:13.306356+0800 MD2[3201:3124067] [Loading] 0x12082de18 - [pageProxyID=6, webPageID=7, PID=0] WebPageProxy::dispatchProcessDidTerminate: reason=Crash
2023-08-17 18:57:13.306372+0800 MD2[3201:3124067] [Loading] 0x12082de18 - [pageProxyID=6, webPageID=7, PID=0] WebPageProxy::dispatchProcessDidTerminate: Not eagerly reloading the view because it is not currently visible
2023-08-17 18:57:13.388055+0800 MD2[3201:3124067] [Process] 0x12205c100 - [PID=3207] WebProcessProxy::didClose: (web process 3207 crash)
2023-08-17 18:57:13.388084+0800 MD2[3201:3124067] [Process] 0x12205c100 - [PID=3207] WebProcessProxy::processDidTerminateOrFailedToLaunch: reason=Crash
2023-08-17 18:57:13.388139+0800 MD2[3201:3124067] [Process] 0x12082de18 - [pageProxyID=6, webPageID=7, PID=3207] WebPageProxy::processDidTerminate: (pid 3207), reason=Crash
2023-08-17 18:57:13.394372+0800 MD2[3201:3124067] [Loading] 0x12082de18 - [pageProxyID=6, webPageID=7, PID=3207] WebPageProxy::dispatchProcessDidTerminate: reason=Crash
2023-08-17 18:57:13.394400+0800 MD2[3201:3124067] [Process] 0x12082de18 - [pageProxyID=6, webPageID=7, PID=3207] WebPageProxy::tryReloadAfterProcessTermination: process crashed and the client did not handle it, not reloading the page because we reached the maximum number of attempts
2023-08-17 18:57:13.395249+0800 MD2[3201:3124067] [Process] 0x122018340 - NetworkProcessProxy::didClose (Network Process 3206 crash)
2023-08-17 18:57:13.396340+0800 MD2[3201:3124483] flock failed to lock list file (/var/folders/45/mympflmx17v2f4l9x5ls42h80000gn/C/cn.kikicoding.MD2//cn.kikicoding.MD2/com.apple.metal/31001/libraries.list): errno = 35
2023-08-17 18:57:13.396907+0800 MD2[3201:3124483] flock failed to lock list file (/var/folders/45/mympflmx17v2f4l9x5ls42h80000gn/C/cn.kikicoding.MD2//cn.kikicoding.MD2/com.apple.metal/16777235_530/functions.list): errno = 35

code is

//
//  ContentView.swift
//  MD2
//
//  Created by meng xianlang on 2023/8/17.
//

import SwiftUI
import Markdown

struct ContentView: View {
    @State private var mdStr: String = """
    ## Hello World
    
    Render Markdown text in SwiftUI
    """
    var body: some View {
        VStack {
            Markdown(content: $mdStr)
            TextEditor(text: $mdStr)
            
        }
        .padding()
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
    

How to use it offline?

It works fine when there is a network connection, but it doesn't display correctly when there is no network connection at all.
Another is that text other than code blocks cannot be selected?

Hope you can help me, thanks.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v4
  • peaceiris/actions-gh-pages v4
.github/workflows/tag.yml
  • actions/checkout v4
  • peaceiris/actions-gh-pages v4
  • ncipollo/release-action v1

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.