@cellgit/markdown-render 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +436 -178
  2. package/README.zh-CN.md +530 -0
  3. package/THIRD-PARTY-NOTICES.md +332 -0
  4. package/dist/markdown-render.css +3 -3
  5. package/dist/markdown-render.esm.css +3 -3
  6. package/dist/markdown-render.esm.js +1 -91452
  7. package/dist/markdown-render.html +20 -75
  8. package/dist/markdown-render.js +1 -91457
  9. package/dist/scripts/bridge.js +119 -0
  10. package/dist/scripts/chat-renderer.js +2770 -0
  11. package/dist/scripts/copy.js +155 -0
  12. package/dist/scripts/height-sync.js +205 -0
  13. package/dist/scripts/renderer.js +398 -0
  14. package/ios-example/MarkdownViewController.swift +123 -33
  15. package/ios-example/README.md +2 -0
  16. package/ios-example/SwiftUIMarkdownExample.swift +111 -0
  17. package/package.json +17 -9
  18. package/dist/fonts/KaTeX_AMS-Regular.ttf +0 -0
  19. package/dist/fonts/KaTeX_AMS-Regular.woff +0 -0
  20. package/dist/fonts/KaTeX_Caligraphic-Bold.ttf +0 -0
  21. package/dist/fonts/KaTeX_Caligraphic-Bold.woff +0 -0
  22. package/dist/fonts/KaTeX_Caligraphic-Regular.ttf +0 -0
  23. package/dist/fonts/KaTeX_Caligraphic-Regular.woff +0 -0
  24. package/dist/fonts/KaTeX_Fraktur-Bold.ttf +0 -0
  25. package/dist/fonts/KaTeX_Fraktur-Bold.woff +0 -0
  26. package/dist/fonts/KaTeX_Fraktur-Regular.ttf +0 -0
  27. package/dist/fonts/KaTeX_Fraktur-Regular.woff +0 -0
  28. package/dist/fonts/KaTeX_Main-Bold.ttf +0 -0
  29. package/dist/fonts/KaTeX_Main-Bold.woff +0 -0
  30. package/dist/fonts/KaTeX_Main-BoldItalic.ttf +0 -0
  31. package/dist/fonts/KaTeX_Main-BoldItalic.woff +0 -0
  32. package/dist/fonts/KaTeX_Main-Italic.ttf +0 -0
  33. package/dist/fonts/KaTeX_Main-Italic.woff +0 -0
  34. package/dist/fonts/KaTeX_Main-Regular.ttf +0 -0
  35. package/dist/fonts/KaTeX_Main-Regular.woff +0 -0
  36. package/dist/fonts/KaTeX_Math-BoldItalic.ttf +0 -0
  37. package/dist/fonts/KaTeX_Math-BoldItalic.woff +0 -0
  38. package/dist/fonts/KaTeX_Math-Italic.ttf +0 -0
  39. package/dist/fonts/KaTeX_Math-Italic.woff +0 -0
  40. package/dist/fonts/KaTeX_SansSerif-Bold.ttf +0 -0
  41. package/dist/fonts/KaTeX_SansSerif-Bold.woff +0 -0
  42. package/dist/fonts/KaTeX_SansSerif-Italic.ttf +0 -0
  43. package/dist/fonts/KaTeX_SansSerif-Italic.woff +0 -0
  44. package/dist/fonts/KaTeX_SansSerif-Regular.ttf +0 -0
  45. package/dist/fonts/KaTeX_SansSerif-Regular.woff +0 -0
  46. package/dist/fonts/KaTeX_Script-Regular.ttf +0 -0
  47. package/dist/fonts/KaTeX_Script-Regular.woff +0 -0
  48. package/dist/fonts/KaTeX_Size1-Regular.ttf +0 -0
  49. package/dist/fonts/KaTeX_Size1-Regular.woff +0 -0
  50. package/dist/fonts/KaTeX_Size2-Regular.ttf +0 -0
  51. package/dist/fonts/KaTeX_Size2-Regular.woff +0 -0
  52. package/dist/fonts/KaTeX_Size3-Regular.ttf +0 -0
  53. package/dist/fonts/KaTeX_Size3-Regular.woff +0 -0
  54. package/dist/fonts/KaTeX_Size4-Regular.ttf +0 -0
  55. package/dist/fonts/KaTeX_Size4-Regular.woff +0 -0
  56. package/dist/fonts/KaTeX_Typewriter-Regular.ttf +0 -0
  57. package/dist/fonts/KaTeX_Typewriter-Regular.woff +0 -0
@@ -0,0 +1,111 @@
1
+ import SwiftUI
2
+
3
+ /// Demonstrates how to embed `MarkdownViewController` inside SwiftUI
4
+ struct SwiftUIMarkdownExampleView: View {
5
+ @State private var markdown = """
6
+ # SwiftUI + MarkdownRender
7
+
8
+ - 自动暗黑模式
9
+ - 代码高亮
10
+ - 数学公式支持
11
+
12
+ $$x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}$$
13
+ """
14
+
15
+ @State private var contentHeight: CGFloat = 20
16
+
17
+ var body: some View {
18
+ ScrollView {
19
+ MarkdownViewControllerRepresentable(markdown: markdown, contentHeight: $contentHeight)
20
+ .frame(height: contentHeight)
21
+ .animation(.easeInOut(duration: 0.2), value: contentHeight)
22
+ .padding()
23
+ }
24
+ .background(Color(.systemBackground))
25
+ .navigationTitle("Markdown Preview")
26
+ .toolbar {
27
+ Button("随机内容") {
28
+ markdown = SwiftUIMarkdownExampleView.randomMarkdown()
29
+ }
30
+ }
31
+ }
32
+
33
+ private static func randomMarkdown() -> String {
34
+ let samples: [String] = [
35
+ """
36
+ # ChatGPT 风格
37
+
38
+ ```swift
39
+ func greet(_ name: String) {
40
+ print("Hello, \\(name)!")
41
+ }
42
+ ```
43
+ """,
44
+ """
45
+ ## 表格示例
46
+
47
+ | 语言 | 类型 |
48
+ |------|------|
49
+ | Swift | 静态 |
50
+ | JavaScript | 动态 |
51
+ """,
52
+ """
53
+ # 数学
54
+
55
+ Inline: $E = mc^2$
56
+
57
+ Block:
58
+ $$
59
+ \\int_{-\\infty}^{+\\infty} e^{-x^2} dx = \\sqrt{\\pi}
60
+ $$
61
+ """
62
+ ]
63
+ return samples.randomElement() ?? samples[0]
64
+ }
65
+ }
66
+
67
+ struct MarkdownViewControllerRepresentable: UIViewControllerRepresentable {
68
+ var markdown: String
69
+ @Binding var contentHeight: CGFloat
70
+
71
+ func makeCoordinator() -> Coordinator {
72
+ Coordinator(contentHeight: $contentHeight)
73
+ }
74
+
75
+ func makeUIViewController(context: Context) -> MarkdownViewController {
76
+ let controller = MarkdownViewController()
77
+ controller.onContentHeightChange = { [weak coordinator = context.coordinator] height in
78
+ coordinator?.updateHeight(height)
79
+ }
80
+ return controller
81
+ }
82
+
83
+ func updateUIViewController(_ uiViewController: MarkdownViewController, context: Context) {
84
+ uiViewController.renderMarkdown(markdown)
85
+ }
86
+
87
+ final class Coordinator {
88
+ private var contentHeight: Binding<CGFloat>
89
+
90
+ init(contentHeight: Binding<CGFloat>) {
91
+ self.contentHeight = contentHeight
92
+ }
93
+
94
+ func updateHeight(_ height: CGFloat) {
95
+ guard height >= 0 else { return }
96
+ if abs(contentHeight.wrappedValue - height) > 0.5 {
97
+ contentHeight.wrappedValue = height
98
+ }
99
+ }
100
+ }
101
+ }
102
+
103
+ #if DEBUG
104
+ struct SwiftUIMarkdownExampleView_Previews: PreviewProvider {
105
+ static var previews: some View {
106
+ NavigationView {
107
+ SwiftUIMarkdownExampleView()
108
+ }
109
+ }
110
+ }
111
+ #endif
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "@cellgit/markdown-render",
3
- "version": "0.1.0",
4
- "description": "A frontend markdown rendering library with syntax highlighting, math support, and iOS system colors adaptation",
3
+ "version": "1.0.0",
4
+ "description": "Streaming-friendly markdown renderer with KaTeX math, code highlighting, and iOS-ready WebView bundle.",
5
+ "engines": {
6
+ "node": ">=18"
7
+ },
5
8
  "type": "module",
6
9
  "main": "dist/markdown-render.esm.js",
7
10
  "module": "dist/markdown-render.esm.js",
@@ -18,6 +21,8 @@
18
21
  "dist",
19
22
  "ios-example",
20
23
  "README.md",
24
+ "README.zh-CN.md",
25
+ "THIRD-PARTY-NOTICES.md",
21
26
  "QUICK_START_iOS.md",
22
27
  "iOS_COLORS.md"
23
28
  ],
@@ -25,7 +30,9 @@
25
30
  "build": "rollup -c && node scripts/copy-katex-fonts.js && node scripts/copy-html-template.js",
26
31
  "build:ios": "npm run build && node scripts/bundle-for-ios.js",
27
32
  "prepublishOnly": "npm run build",
28
- "test": "echo \"No tests specified\" && exit 0"
33
+ "test": "node --import ./tests/register-loader.mjs --test tests/*.test.mjs",
34
+ "test:math": "node --import ./tests/register-loader.mjs --test tests/math*.test.mjs",
35
+ "math:report": "node --import ./tests/register-loader.mjs scripts/render-math-regression.mjs"
29
36
  },
30
37
  "keywords": [
31
38
  "markdown",
@@ -46,27 +53,28 @@
46
53
  "system-colors",
47
54
  "mobile"
48
55
  ],
49
- "author": "",
56
+ "author": "cellgit",
50
57
  "license": "MIT",
51
58
  "repository": {
52
59
  "type": "git",
53
- "url": "https://github.com/yourusername/markdown-render.git"
60
+ "url": "git+https://github.com/cellgit/markdown-render.git"
54
61
  },
55
62
  "bugs": {
56
- "url": "https://github.com/yourusername/markdown-render/issues"
63
+ "url": "https://github.com/cellgit/markdown-render/issues"
57
64
  },
58
- "homepage": "https://github.com/yourusername/markdown-render#readme",
65
+ "homepage": "https://github.com/cellgit/markdown-render#readme",
59
66
  "dependencies": {
60
67
  "highlight.js": "^11.9.0",
61
68
  "katex": "^0.16.9",
62
69
  "markdown-it": "^14.1.0",
63
- "markdown-it-task-lists": "^2.1.1",
64
- "markdown-it-emoji": "^3.0.0"
70
+ "markdown-it-emoji": "^3.0.0",
71
+ "markdown-it-task-lists": "^2.1.1"
65
72
  },
66
73
  "devDependencies": {
67
74
  "@rollup/plugin-commonjs": "^25.0.7",
68
75
  "@rollup/plugin-node-resolve": "^15.2.3",
69
76
  "@rollup/plugin-terser": "^0.4.4",
77
+ "jsdom": "^29.1.1",
70
78
  "rollup": "^4.9.6",
71
79
  "rollup-plugin-import-css": "^3.5.2"
72
80
  }
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file