New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unleash the power of Block Directive #23
Conversation
- Unleash the full power for users to customize their own view instead of using MarkdownView - Update APIs - Re-structure related files
This enhancement may satisfy the feature request: #19 |
@LiYanan2004 Thank you for your always great work. It works fine on my side. However, it seems |
@hugo53 You鈥檙e right. I mean you can now add LateXView as a part of MarkdownView. If you鈥檙e working on views with static markdown text, you can simply update input string to use that pattern. If you are developing document editors, you can try to manually detect this syntax(use the dependency of LateXSwiftUI package) and dynamically wrap it using To sum up, It鈥檚 full of potential 馃榿 |
@hugo53 Congratulation. You found a bug of swift-markdown.馃ぃ This bug only occurs when the code block is the first Markdown item. I will report this bug. |
@LiYanan2004 Ah correct, I added some words at first and it works fine now. Weird bug 馃ぃ |
@hugo53 Based on the documentation, you can extract ranges that contains LateX Syntax using this method: func findLateXRanges(in text: String) -> [Range<String.Index>] {
let singleDollarPattern = #"\$((?!\$).)+\$"#
let doubleDollarPattern = #"\$\$(.+)\$\$"#
let squareBracketsPattern = #"\\\[(.+)\\\]"#
let beginEndPattern = #"\\begin{equation}(.+)\\end{equation}"#
let beginEndWithAsteriskPattern = #"\\begin{equation*}(.+)\\end{equation*}"#
let pattern = try! Regex("\(doubleDollarPattern)|\(singleDollarPattern)|\(squareBracketsPattern)|\(beginEndPattern)|\(beginEndWithAsteriskPattern)")
return text.matches(of: pattern).map { $0.range }
} |
@LiYanan2004 Thank you for suggestion. I will check more on that! |
Modifications
Custom View inside MarkdownView
Now, BlockDirectiveDisplayable gives you text from the body of block directives.
You can add custom view inside MarkdownView by implementing
BlockDirectiveDisplayable
.Example
If you want to support LateX in your app along with MarkdownView.
Define your provider:
Then, adding it to MarkdownView:
馃帀 That鈥檚 it. Now if you write markdown like this:
You can see this:
Deprecations
The required function
makeView(arguments:innerView:)
has been replaced withmakeView(arguments:text:)