GithubHelp home page GithubHelp logo

breakmeovo / markdownview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from keitaoouchi/markdownview

0.0 0.0 0.0 3.92 MB

Markdown View for iOS.

License: MIT License

JavaScript 9.83% Ruby 3.26% Objective-C 0.82% CSS 18.01% Swift 66.00% HTML 2.09%

markdownview's Introduction

MarkdownView

CI Status Swift 5.2 Carthage compatible Version License Swift Package Manager compatible

MarkdownView is a WKWebView based UI element, and internally use markdown-it, highlight-js.

GIF

How to use

UIViewController

import MarkdownView

let md = MarkdownView()
md.load(markdown: "# Hello World!")

SwiftUI

import SwiftUI
import MarkdownView

struct SampleUI: View {
  var body: some View {
    ScrollView {        
      MarkdownUI(body: markdown)
        .onTouchLink { link in 
          print(link)
          return false
        }
        .onRendered { height in 
          print(height)
        }
    }
  }
  
  private var markdown: String {
    let path = Bundle.main.path(forResource: "sample", ofType: "md")!
    let url = URL(fileURLWithPath: path)
    return try! String(contentsOf: url, encoding: String.Encoding.utf8)
  }
}

Options

md.isScrollEnabled = false

// called when rendering finished
md.onRendered = { [weak self] height in
  self?.mdViewHeight.constant = height
  self?.view.setNeedsLayout()
}

// called when user touch link
md.onTouchLink = { [weak self] request in
  guard let url = request.url else { return false }

  if url.scheme == "file" {
    return false
  } else if url.scheme == "https" {
    let safari = SFSafariViewController(url: url)
    self?.navigationController?.pushViewController(safari, animated: true)
    return false
  } else {
    return false
  }
}

Experimental Features

This is not stable ๐Ÿ™‡

Custom CSS Styling

Please check Example/ViewController/CustomCss.swift.

Plugins

Please check Example/ViewController/Plugins.swift. Each plugin should be self-contained, with no external dependent plugins.

Here is a sample project that builds markdown-it-new-katex as a compatible library.

Requirements

Target Version
iOS => 13.0
Swift => 5.2

Installation

MarkdownView is available through Swift Package Manager or CocoaPods or Carthage.

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/keitaoouchi/MarkdownView.git", from: "1.7.1")
]

Alternatively, you can add the package directly via Xcode.

CocoaPods

pod "MarkdownView"

Carthage

github "keitaoouchi/MarkdownView"

for detail, please follow the Carthage Instruction

Author

keita.oouchi, [email protected]

License

bootstrap is licensed under MIT license.
highlight.js is licensed under BSD-3-Clause license.
markdown-it is licensed under MIT license.

MarkdownView is available under the MIT license. See the LICENSE file for more info.

markdownview's People

Contributors

keitaoouchi avatar stevearm avatar dependabot[bot] avatar

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.