|
1 | | -# SwiftMathMarkdown |
| 1 | +# MathMarkdown |
2 | 2 |
|
3 | 3 | ## Approaches |
4 | | -- Study attributed-string-builder and migrate Markdownosaur visit code in. |
5 | | -- Assemble multiple Markdown to AttributedString collection, review and compare differences later. |
6 | | -- MarkupFormatter & MarkupTreeDumper uses MarkupWalker protocol |
7 | | -- BreakDeleter (MarkupFormatter), SoftBreakDeleter both uses MarkupRewriter. |
| 4 | +- Use RegEx to preprocess Markdown text, and substitute math latex code that swift-markdown and cmark-gfm cannot handle by UUIDs. |
| 5 | +- Apply swift-markdown parsing on the substituted text. |
| 6 | +- Use MarkupWalker to extract the finalized list of network images, local images and math images that need to be generated. |
| 7 | +- Use Async/Await to handle SwiftMathImage and Image download |
| 8 | +- Embed Remote NSTextAttachment(iOS) and NSTextAttachmentCell(macOS) into NSAttributedString |
| 9 | +- Build using a Formatter on NSAttributedString for PDF generation. |
| 10 | +- Prepare for async notification to refresh NSTextAttachment or NSTextAttachmentCell. |
8 | 11 |
|
9 | | -## Asynchronous Behaviour consideration |
10 | | -- SwiftMathDownosaur could accept two closures, one to handle latex images generation, and the other local or remote images loading |
11 | | -- These can be asynchronous loading effect, keeps changing the contents of the attributed string when contents arrives. |
12 | | -- Each arrival or notification of the contents, triggers a textLayout refresh. |
13 | | -- So far, no implementation approaches. May be a bit of Combine. |
14 | | - |
15 | | -## Notes |
16 | | -- Done apply change to Downosaur. AttributedStringBuilder seems complex. |
17 | | - |
18 | | -## Limitations |
| 12 | +## Some Limitations |
19 | 13 | - objcio.attributed-string-builder (supports cocoa only, uses TextBlock), adopt its MarkupWalker approach, |
20 | | -- Markdownosaur uses only MarkupVisitor approach |
21 | 14 | - NSAttributedString, paragraphStyle implementation is different across cocoa and uikit. The former has TextBlock for Table. |
22 | | -- May need to lower the support on iOS. |
23 | | -- All code uses struct on MarkupVisitor/MarkupWalker, thus cannot subclass and override. |
| 15 | +- struct based MarkupVisitor and MarkupWalkers cannot be subclassed. |
| 16 | +- NSImage, drawn using CoreGraphics preserves Glphy Infos while UIImage does not, end upwith awkward multi-line math equations across PDF pages. |
24 | 17 |
|
25 | 18 | ## References |
26 | | -- not depend on apple/swift-markdown https://github.com/objecthub/swift-markdownkit.git |
| 19 | +- This does not depend on apple/swift-markdown https://github.com/objecthub/swift-markdownkit.git |
27 | 20 | - Renderer is publishing to SwiftUI only https://github.com/LiYanan2004/MarkdownView.git/Sources/MardownView/Renderer/Renderer.swift |
28 | | -- Interesting library to configure view on Markdown visitor, https://github.com/johnxnguyen/Down.git |
| 21 | +- Other library to configure view on Markdown visitor, https://github.com/johnxnguyen/Down.git |
29 | 22 | - Unfortunately, this only supports MacOS but not iOS. https://github.com/objcio/attributed-string-builder.git |
30 | 23 | - apple/swift-docc/Sources/SwiftDocC/Model/Rendering/RenderContentCompiler use MarkupVisitor |
31 | | -- https://github.com/nathantannar4/StyleKit.git read StyleKit/StyleKit/Font.swift on Bundle handling. |
| 24 | +- read StyleKit/StyleKit/Font.swift on Bundle handling https://github.com/nathantannar4/StyleKit.git . |
32 | 25 | - This is mainly cgContext based rendering, not even covering pdf, https://github.com/shaps80/GraphicsRenderer/tree/master |
33 | 26 | - Mainly for drawing stuff, use with GraphicsRenderer, https://github.com/shaps80/InkKit.git |
34 | | - |
35 | | -## Sample inline math |
36 | | -This is a sample `\sqrt{5z+6}-(9+y)^3` test. |
0 commit comments