Git Product home page Git Product logo

swiftdown's Introduction

SwiftDown

codecov

πŸ“– Description

A markdown editor component for your SwiftUI apps.

  • πŸŽ‰ Live preview directly in editor for most of Markdown elements, without web based preview.
  • ⚑️ Fast, built on top of cmark.
  • πŸ—’ Pure markdown, no proprietary format.
  • πŸ’»:πŸ“± macOS and iOS support.

πŸ› οΈ Install

πŸ“¦ Swift Package Manager

Either use Xcode to add the package dependency or add the following dependency to your Package.swift:

.package(url: "https://github.com/qeude/SwiftDown.git", from: "0.4.1),

πŸ”§ Usage

import SwiftDown
import SwiftUI

struct ContentView: View {
    @State private var text: String = ""

    var body: some View {
        SwiftDownEditor(text: $text)
            .insetsSize(40)
            .theme(Theme.BuiltIn.defaultDark.theme())
    }
}

πŸ–ŒοΈ Themes

πŸ–Ό BuildIn themes

Default Dark

Default Light

πŸ§‘β€πŸŽ¨ Custom themes

SwiftDown supports theming by using config .json files as this one Then init your custom theme as below.

Theme(themePath: Bundle.main.path(forResource: "my-custom-theme", ofType: "json"))

πŸ‘¨πŸ»β€πŸ’» Author

swiftdown's People

Contributors

ingun37 avatar qeude avatar rossbrandon avatar

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  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  avatar

swiftdown's Issues

Cannot resolve package dependencies?

After add dependency i always receive this error

Failed to resolve dependencies Dependencies could not be resolved because package 'swiftdown' is required using a stable-version but 'swiftdown' depends on an unstable-version package 'swiftlint' and root depends on 'swiftdown' 0.3.0.

Enter a space first and then the # symbol, an error will occur

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Input a " "(Space)
  2. Input a "#"
  3. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

toMarkdownNode method in MarkdownEngine.swift
error: Swift/StringUTF8View.swift:192: Fatal error: String index is out of bounds

Desktop (please complete the following information):

  • OS: Sonoma
  • Version 14.2.1

Additional context
Add any other context about the problem here.

Cannot resolve package dependencies?

Any idea why I'm getting this error when I try to add it via Package Manager?
Failed to resolve dependencies Dependencies could not be resolved because root depends on 'swiftdown' 0.3.0..<1.0.0

Plug-in ended with uncaught signal: 5)

Describe the bug
Adding the package to my iOS 16 project causes the error Plug-in ended with uncaught signal: 5)

To Reproduce
Steps to reproduce the behavior:

  1. Add Swiftdown as a dependency via the Xcode dependency manager
  2. See error

Additional context
I'm using Version 14.3.1 on a project for iOS 16

Markdown Processor source?

Can you release a swift package of the markdown engine? as in, an independent library I can import to use your markdown styling.
For example, I'd like to use something like this:

import SwiftDownMD

struct Comment: View {
    let comment: Comment
    var body: some View {
        VStack {
            Markdown(comment.body)
        }
    }
}

4 errors when loading

  1. "Value of type 'ShiftDown' has not member 'onTextChange'" - SwiftDownEditor.swift
  2. "Missing argument for parameter 'offset' in call" - SwiftDownEditor.swift
  3. "Cannot find 'textView' in scope" - SwiftDownEditor.swift
  4. "Cannot find 'textView" in scope" - SwiftDownEditor.swift

Screen Shot 2021-03-22 at 8 24 03 PM

Support todo markup with custom control.

In Markdown, the syntax - [ ] allows you to create todo lists.

How difficult would it be to implement this syntax but with a custom renderer displaying a checkbox.

Cursor jumping to the end of line

Hi! I am experiencing a cursor jump to the end of text on each formatting being applied. Anything I could do to stop this from happening?

Odd behavior with SwiftDown inside a NavigationSplitView

Describe the bug
I started attempting to integrate SwiftDown into a cross-platform SwiftUI project that utilizes a NavigationSplitView, and noticed an odd behavior where SwiftDown seems to always be referencing an older item. I've tried many different variations of utilizing NavigationSplitView, but all of them exhibit this issue. If I use the deprecated NavigationView instead, this problem does not occur.

To Reproduce
Here's some sample code to show off the issue: https://gist.github.com/garrettmurray/4e23b2478f89beae47913a78d9c194a2

You'll note that only the SwiftDown field suffers from this issueβ€”editing via the TextEditor in the same VStack appropriately updates the correct, currently-selected item.

Expected behavior
SwiftDown field would edit the correct item's text, like TextEditor does.

Screenshots
Attaching a video of this bug in action as well, using the sample code linked above.

SwiftDownSplitViewExample.mov

Desktop (please complete the following information):

  • OS: macOS
  • Version 14.3.1

Styling is not applied when using navigation

First of all: SwiftDown is a great package! I tried several markdown editor packages that support live styling and SwiftDown has by far the best editing experience.

There is one thing I am struggling with: it appears that styling is only applied when editing text (so typing in the editor), but not when the view is initially loaded. This can be demonstrated when you use navigation in a project, e.g. have a list of documents and when you click on a document, the corresponding contents are being shown in a SwiftDown view. Initially all text has the same color and font size, but if you give SwiftDown focus and type one character, then all styling gets updated.

I tried to fiddle with the .onAppear() modifier, but is unclear to me how I could trigger 'update styling' in the SwiftDownEditor. Does someone has an idea how to handle this? Thanks in advance!

License

Currently, the repo doesn't have a license yet.

Support the changing of theme dynamically

Is your feature request related to a problem? Please describe.
Currently, SwiftDownEditor stores the theme internally, and therefore the theme is not able to be changed from the outside. For modern apps which support light and dark mode, this means any SwiftDownEditors in use will always be stuck with the theme they were created with, which leads to a poor user experience.

Describe the solution you'd like
Ideally, setting the theme would redraw the SwiftDownEditor, such that you could base the current theme on the environment's color scheme to automatically support light/dark modes. This would also allow for a user to change themes while utilizing the editor, with, say, a drop-down of available themes.

Describe alternatives you've considered
Without this, the SwiftDownEditor would need to effectively be removed from the hierarchy, and recreated, which doesn't feel very SwiftUI-like.

Additional context
A quick example of what I expected to do for supporting system-wide dark/light mode:

@Environment(\.colorScheme) var colorScheme

SwiftDownEditor(text: $itemText)
  .insetsSize(20)
  .theme(colorScheme == .dark ? Theme.BuiltIn.defaultDark.theme() : Theme.BuiltIn.defaultLight.theme())
  .debounceTime(0.5)

Enable detected links as actual links

Is your feature request related to a problem? Please describe.
One expectation of a Markdown preview is that links are actually clickable when they're identified and displayed as links.

Describe the solution you'd like
Two possible ways to solve this as I think about it (conveniently without any concern about implementation πŸ˜†):

A. Add logic to wrap detected link nodes in their link so that the entire [Text](https://link) is linked as a single unit (this seems complex).
Or
B. Allow for the isAutomaticLinkDetectionEnabled attribute of NSTextView to be utilized (and the UIDataDectorTypes.link equivalent on iOS) which would only link the actual URL from the link, but would at least still make the link clickable.

Seems like B would be much easier and get 90% of the way there, though it's less accurate to the preview technically. Would still be preferable, I think, to no linking at all, however.

Describe alternatives you've considered
Obviously, this isn't a blocker to using SwiftDownEditor, but it does mean one of the core features of Markdown doesn't actually do anything when you match it, which is odd.

Hide markdown syntax when cursor leaves position

Is it possible to have the markdown syntax hide as the cursor leaves the text? Sort of like Obsidian does in their live preview mode?

Eg when writing **bold** to only show bold? (Notice that the asterisks have been "hidden")

Popover and visuals

I was taking a look at the package and noticed a weird behavior when typing the text where its plain text before formatting, I was wondering if you knew of any work arounds.

I was also wondering where the popover to insert an emoji was from.

Privacy concerns

Hey, I was happy to find this package and wanted to try it in my project. However, I faced some warnings that intrigue me.

Describe the bug
When installing the package, Xcode asks for Keychain access. And then, after refusing it, it shows up the error:

Build plug-ins with malicious code can harm your Mac or compromise your privacy. Be sure you trust the source of build plug-ins before you enable them.

Screenshot 1
Screenshot 2

Question
Why does it need access to the keychain? Is this package safe?

Modifier .isEditable() does not work

See error in accessor code: isEditable is set to true whatever value is passed :

public func isEditable(_ isEditable: Bool) -> Self {
    var editor = self
    editor.isEditable = true // <-- here
    return editor
  }

All builds fail because of duplicated symbols

Describe the bug
All builds fail because of duplicated symbols when also using MarkdownUI

To Reproduce

  1. Create a new project
  2. Add this library as dependency
  3. Add MarkdownUI as dependency
  4. All builds fail

Expected behavior
The app builds without compilation errors

Screenshots
Bildschirmfoto 2024-02-21 um 09 36 50

Desktop (please complete the following information):

  • OS: macOS
  • Version 14.3

Smartphone (please complete the following information):

  • Device: iPhone 15 Pro
  • OS: iOS
  • Version 17.2

Additional context
none

Text binding not working as expected

import SwiftUI
import SwiftDown

struct DownTest: View {
    @State private var text: String = "Reply"
    
    var body: some View {
        VStack {
            SwiftDownEditor(text: $text).frame(height: 50)
            TextField("", text: $text).frame(height: 50)
            Button {
               self.text = ""
            } label: {
                Text("Clear")
            }
        }
    }
}

struct DownTest_Previews: PreviewProvider {
    static var previews: some View {
        DownTest()
    }
}

The text should clear as the TextField does when you run this code.

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.