bmoliveira / markdownkit Goto Github PK
View Code? Open in Web Editor NEWA simple and customizable Markdown Parser for Swift
License: MIT License
A simple and customizable Markdown Parser for Swift
License: MIT License
Hello,
I'm just trying to use your code. I download Example project but I have a compilation Error
ld: warning: directory not found for option '-F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/Developer/Library/Frameworks'
Can you please help
Hi, I've noticed that the following markdown text is not rendering as expected:
# Heading with **bold text**
The bold part of the text is being rescaled down, instead of maintaining the header font size.
Hi,
I would like to use that lib to format my label.
The idea is that I have a structure like this:
title1
Description1
title2
Description2
etc...
I would like to have some space between the title and the description. one "\n" is not enough and "\n\n" is too much.
Do you have any idea about how I could do that?
If you go to File > Swift Packages > Add Package Dependency, paste in https://github.com/bmoliveira/MarkdownKit.git, click Next, leave it at the default up to 1.4.1 rule, click Next, you'll get an error stating:
https://github.com/bmoliveira/MarkdownKit.git has no Package.swift manifest for version 1.4.1 in https://github.com/bmoliveira/MarkdownKit.git
If you instead put in 1.7.0 as is implied in the Readme, you'll get an error stating:
Dependencies could not be resolved because no versions of 'MarkdownKit' match the requirement 1.7.0..<2.0.0 and root depends on 'MarkdownKit' 1.7.0..<2.0.0.
I didn't see any right-to-left support, so I implemented a custom element if it helps anyone:
https://gist.github.com/joshkopecek/11e3f27f0969b4155ccbe0562e5c7cd6
plz
Hi,
I have a problem with markdown. when i use single word like ' Hello ' word style correctly will be changed to bold. but when i use a word in a sentences like ' Test Hello Test ' bold style not working and sentence will be shown 'Test Hello Test '
I have the need for the header element to have a specific line height (added as an NSAttributedString attribute during parsing). I'm not seeing a straightforward way to do this. Have thought about:
Subclass MarkdownHeader and replace MarkdownParser.header with subclass instance. However, MarkdownParser.header is defined with let and can't be updated.
I could add a custom element with the same regex to replace the header-defined text before the default element could parse it. However, custom elements are currently parsed after default elements.
Are there other solutions I'm not seeing. If I were to fork, is there a suggested option that would be more acceptable to a pull request back into core project?
Thanks for all the work so far. Like having a lightweight and Swift option for Markdown.
MarkdownBold does not work for "(**BOLD**)"
string, but works for "( **BOLD**)"
fixed by using custom element:
class MarkdownWorkingBold: MarkdownBold {
private static let regex = "(\\s+|^|\\B)(\\*\\*|__)(.+?)(\\2)"
override var regex: String {
return MarkdownWorkingBold.regex
}
}
I am unable to set the custom font for the regular text. My font file only contains a single font style, so it crashes at initialisation of MarkdownParser where it is unable to find its corresponding MarkdownBold font. Previously in Swift 2.3, it used to use the font set to UILable, but with the update to Swift 3.0, it no longer supports that. Any idea how to support that? Here is how I initialised MarkdownParser
let markdownParser = MarkdownParser(font: UIFont(name: "Some Custom Font Name", size: 16.0))
If I have multi level list it doesn't render correctly
The init functions in MarkdownCodeEscaping, MarkdownEscaping and MarkdownUnescaping are not public (default constructors are in 'internal' protection level). Hence the code outside of the pod cannot create instances of these classes, and other open functions in those classes are not really customizable. Thanks.
thx
What if an URL has brackets, such as a lot of Wikipedia URLs? Currently, those don't get parsed correctly.
[Here](http://example.com/test(1).html)
Doesn't display in correct format. Thanks
Is it possible to enable auto hyperlink?
The text used for MarkdownKit is get dynamically. I would like that the links (ex: https://youtbe.com) are transformed automatically to links clickable, is it possible?
After upgrading from version 1.5 to 1.6 via cocoapods, my app crashed when trying to parse markdown text. The error was thrown when this method in the MarkdownParser was called:
open func removeCustomElement(_ element: MarkdownElement) {
guard let index = customElements.index(where: { someElement -> Bool in
return element === someElement
}) else {
return
}
customElements.remove(at: index)
}
The error was because element
was not retained. Downgrading to 1.5 fixed the issue for me. Please let me know if I can provide any more helpful information.
Our app relies on MarkdownKit
for parsing and formatting articles, some of which containing links. Through crash reports, we learned that some of our users are experiencing crashes in MarkdownLink
's formatText()
method. We have been unable to reproduce this error.
Details of the stack trace of our crash are shown below:
Any insights as to why this is occurring, or how we should go about troubleshooting this crash?
Thank you for your help.
Any app to which I add MarkdownKit began to crash during lunchtime on an iOS device (works fine on simulator). Xcode Version 11.3.1 (11C504), iOS 13.3.1, MarkdownKit 1.6. The error messages are below:
dyld: Library not loaded: @rpath/MarkdownKit.framework/MarkdownKit
Referenced from: /private/var/containers/Bundle/Application/8B2E7228-0DAD-45E6-B85E-3E5473770964/fdslakfjdslkfj.app/fdslakfjdslkfj
Reason: no suitable image found. Did find:
/private/var/containers/Bundle/Application/8B2E7228-0DAD-45E6-B85E-3E5473770964/fdslakfjdslkfj.app/Frameworks/MarkdownKit.framework/MarkdownKit: code signature invalid for '/private/var/containers/Bundle/Application/8B2E7228-0DAD-45E6-B85E-3E5473770964/fdslakfjdslkfj.app/Frameworks/MarkdownKit.framework/MarkdownKit'
/private/var/containers/Bundle/Application/8B2E7228-0DAD-45E6-B85E-3E5473770964/fdslakfjdslkfj.app/Frameworks/MarkdownKit.framework/MarkdownKit: stat() failed with errno=25
/private/var/containers/Bundle/Application/8B2E7228-0DAD-45E6-B85E-3E5473770964/fdslakfjdslkfj.app/Frameworks/MarkdownKit.framework/MarkdownKit: code signature invalid for '/private/var/containers/Bundle/Application/8B2E7228-0DAD-45E6-B85E-3E5473770964/fdslakfjdslkfj.app/Frameworks/MarkdownKit.framework/MarkdownKit'
/private/var/containers/Bundle/Application/8B2E7228-0DAD-45E6-B85E-3E5473770964/fdslakfjdslkfj.app/Frameworks/MarkdownKit.framework/MarkdownKit: stat() failed with errno=1
/private/var/containers/Bundle/Application/8B2E7228-0DAD-45E6-B85E-3E5473770964/fdslakfjdslkfj.app/Frameworks/MarkdownKit.framework/MarkdownKit: code signature invalid for '/private/var/containers/Bundle/Application/8B2E7228-0DAD-45E6-B85E-3E5473770964/fdslakfjdslkfj.app/Frameworks/MarkdownKit.framework/MarkdownKit'
/private/var/containers/Bundle/Application/8B2E7228-0DAD-45E6-B85E-3E5473770964/fdslakfjdslkfj.app/Frameworks/MarkdownKit.framework/MarkdownKit: stat() failed with errno=1
for eg-
**_~~harshsurati~~_**
Hi! I was glad to find this project, I was trying to use Down, but it's attributed string rendering leaves much to be desired. I thought this seemed like a great way to get a dark mode friendly Markdown parser into my project... and it is! So, thank you.
Unfortunately there appears to be a problem with link colors. Here's some example code...
var textColor: UIColor = .black
if #available(iOS 13.0, *) {
textColor = .label
}
let markdownParser = MarkdownParser(font: UIFont.preferredFont(forTextStyle: .body), color: textColor)
markdownParser.link.color = textColor
return markdownParser.parse("A string [with a link](http://foo.com), and so on.")
While the main content of the string is colored properly no matter what, the link color appears to be stuck as a black color, even without the link.color
call. I've tried link.color = .red
as well, and no dice.
Error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'The specified URL has an unsupported scheme. Only HTTP and HTTPS URLs are supported.
I tried entering apple.com
, http://apple.com
, or https://apple.com
inside my app's text view. They all still lead to the same exception.
I put several print statements inside your formatText(_:range:link:)
function within MarkdownLink.swift
file:
open func formatText(_ attributedString: NSMutableAttributedString, range: NSRange,
link: String) {
print("link:\(link)")
guard let encodedLink = link.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlHostAllowed)
else {
return
}
print("encoded link: \(encodedLink)")
guard let url = URL(string: link) ?? URL(string: encodedLink) else { return }
print("url: \(url)")
attributedString.addAttribute(NSLinkAttributeName, value: url, range: range)
}
and get the following output in the console, which shows no problem:
link:https://apple.com
encoded link: https:%2F%2Fapple.com
url: https://apple.com
Since the maintainer appears to have abandoned this, I have cloned and renamed this project, and merged most of the outstanding PRs manually. I also support Swift 4. New PRs are welcomed as well. https://github.com/davidlari/Haring
When I try to install MarkdownKit via Carthage I get the following error:
Dependency "MarkdownKit" has no shared framework schemes
Hello,
Tank you for your cool Pod.
I wanna know if there is a way to define font size
regards
seb
Are the https links supported?
I was trying this library and faced the issue that lists doesn't have the correct indentation, like when the content of a line from a list breaks line, the second line starts below the "โ" indicator.
What I would expect is to start below of the first character fo the first line
First of all: Awesome framework, thank you for open-sourcing it! ๐
When nesting emphasis and strong delimiters (i.e. bold and italic delimiters) as follows:
_**word**_
I would expect word
to be formatted both bold and italic:
word
This is specified in the CommonMark Spec and as you can see above, it's also the default behavior on GitHub.
The MarkdownKit parser currently formats the Markdown input above as only italic:
word
I would suggest to change the parser's behavior according to the specification.
In my case I have this string that is displayed as a button label.
"Already registered? **Login**"
let parser = MarkdownParser(font: UIFont.systemFont(ofSize: 17))
parser.automaticLinkDetectionEnabled = false
parser.bold.color = UIColor.white
parser.header.color = UIColor.white
My problem is that "Already registered?" is displayed in blue and "Login" is white as set by bold-attribute. How can the color for regular text be set? Why is it set to blue?
Is it possible to change the appearance of the background color of markdown code blocks? I would like to be able to change the appearance of the parsed markdown.
I believe it's the case that markdown standard means number of hashes equates to Hn index, which is inversely proportional to font size.
So
However, MarkdownKit by default has this the wrong way around, ### is the largest font.
([linkme](schema://domain/whees))
results in (linkme
-> schema://domain/whees)
where one would expect (linkme)
-> schema://domain/whees
.
This can be fixed by making the link regex not greedy. The downside is that embedded parentheses in links will not be parsed correctly.
Another approach is to try to balance the bracket: any closing bracket at the end of the link that's is not matched by an opening bracket will be assumed to outside of the actual link. This heuristic seems to work well in practice. I've made a PR for this (#79).
Hey,
Do you plan to add macOS support?
For example, the string swift code
will be parsed to 0073007700690066007400200063006f00640065
It's seems that the list bullet color is always black? When I use a color in a list for dark mode, the text color in the list changed, but the bullets didn't.
I've found at least 2 bugs with the Code element:
Example:
func bug() {}
shows as:
swift
func bug() {}
Example:
/// lets test `this` out
show as
/// lets test out
Hello, please make it Carthage able :)
The app is crashing on this format of link:
[(William) Davenport Griffen](/artists/(william)-davenport-griffen)
The issue is with the name William in brackets. It seems that the framework treats (William) as a separate link.. instead of just a plain text.
The app is crashing in the MarkdownLink.swift
file on formatText
function.
v1.6 don't support for macOS
Steps to reproduce
let markdownParser = MarkdownParser()
let markdown = """
Link with implicit scheme: old.reddit.com
Link with explicit scheme: https://old.reddit.com/
"""
textView.attributedText = markdownParser.parse(markdown)
Expected behaviour
Either the link is opened in Safari,
or the text is not formatted as a link at all
Actual behaviour
Could not find any actions for URL old.reddit.com without any result.
My suggestion would be to have an option for a default scheme for links that is added if the scheme is nil.
Since Xcode 11 includes Swift Package Manager, it would be nice to support it
CocoaPods
and Carthage
are awesome tools and make our life really easier, but there are some devs who still don't know how to use them.
It would be cool to add the Manual installation guide in your README.md
. You can take a look at my iOS Readme Template to see how you can do it.
Due to #38 (comment) the root library should be renamed from MarkdownKit_osx to something more pleasing.
We are looking for a solution that will work with Xcode 10.2. Thanks!
I have experienced a crash in the unescapeUTF16
method in String+UTF16.swift
. The markdown that led to the crash can be found here: https://github.com/apple/swift-evolution/blob/master/proposals/0240-ordered-collection-diffing.md
The crash was found on the line let endIndex = index(self.startIndex, offsetBy: $0 + 4)
in the following code snippet:
stride(from: 0, to: count, by: 4).forEach {
let startIndex = index(self.startIndex, offsetBy: $0)
let endIndex = index(self.startIndex, offsetBy: $0 + 4)
let hex4 = String(self[startIndex..<endIndex])
if let utf16 = UInt16(hex4, radix: 16) {
utf16Array.append(utf16)
}
}
I'm trying to install via Carthage on Xcode 12.2 and keep getting this error:
*** Building scheme "MarkdownKit-AppKit" in MarkdownKit.xcworkspace
*** Building scheme "MarkdownKit" in MarkdownKit.xcworkspace
Build Failed
Task failed with exit code 1:
/usr/bin/xcrun lipo -create /Users/tj/Library/Caches/org.carthage.CarthageKit/DerivedData/12.2_12B45b/MarkdownKit/1.7.0/Build/Intermediates.noindex/ArchiveIntermediates/MarkdownKit/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/MarkdownKit.framework/MarkdownKit /Users/tj/Library/Caches/org.carthage.CarthageKit/DerivedData/12.2_12B45b/MarkdownKit/1.7.0/Build/Products/Release-iphonesimulator/MarkdownKit.framework/MarkdownKit -output /Volumes/VNStorage/Repos/iosSwitchbacks/switchbacks-ios/Carthage/Build/iOS/MarkdownKit.framework/MarkdownKit
This usually indicates that project itself failed to compile. Please check the xcodebuild log for more details: /var/folders/yt/zk5_9dxd08b_4gpddjpl6qx00000gn/T/carthage-xcodebuild.RtHQE3.log
Is this because Xcode 12.2 (Swift 5.3.1) is not supported? Or maybe arm64
architecture needs to be excluded?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.