Skip to content

Commit 5b100ac

Browse files
authored
Merge pull request #30 from nodes-app/20-update-logo-on-demo-project
Add app icon and richer demo for MarkdownEngineDemo
2 parents 376c6e7 + d25d47d commit 5b100ac

6 files changed

Lines changed: 270 additions & 6 deletions

File tree

‎Demo/MarkdownEngineDemo.xcodeproj/project.pbxproj‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@
99
/* Begin PBXBuildFile section */
1010
1A2B3C0000000000000004BB /* MarkdownEngineDemoApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A2B3C0000000000000004AA /* MarkdownEngineDemoApp.swift */; };
1111
1A2B3C0000000000000005BB /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A2B3C0000000000000005AA /* ContentView.swift */; };
12+
1A2B3C0000000000000006BB /* MDE.icon in Resources */ = {isa = PBXBuildFile; fileRef = 1A2B3C0000000000000006AA /* MDE.icon */; };
1213
1A2B3C0000000000000007CC /* MarkdownEngine in Frameworks */ = {isa = PBXBuildFile; productRef = 1A2B3C0000000000000007BB /* MarkdownEngine */; };
14+
1A2B3C0000000000000008BB /* MarkdownEngineCodeBlocks in Frameworks */ = {isa = PBXBuildFile; productRef = 1A2B3C0000000000000008AA /* MarkdownEngineCodeBlocks */; };
15+
1A2B3C0000000000000009BB /* MarkdownEngineLatex in Frameworks */ = {isa = PBXBuildFile; productRef = 1A2B3C0000000000000009AA /* MarkdownEngineLatex */; };
1316
/* End PBXBuildFile section */
1417

1518
/* Begin PBXFileReference section */
1619
1A2B3C0000000000000003DD /* MarkdownEngineDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MarkdownEngineDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
1720
1A2B3C0000000000000004AA /* MarkdownEngineDemoApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkdownEngineDemoApp.swift; sourceTree = "<group>"; };
1821
1A2B3C0000000000000005AA /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
22+
1A2B3C0000000000000006AA /* MDE.icon */ = {isa = PBXFileReference; lastKnownFileType = folder.iconcomposer.icon; path = MDE.icon; sourceTree = "<group>"; };
1923
/* End PBXFileReference section */
2024

2125
/* Begin PBXFrameworksBuildPhase section */
@@ -24,6 +28,8 @@
2428
buildActionMask = 2147483647;
2529
files = (
2630
1A2B3C0000000000000007CC /* MarkdownEngine in Frameworks */,
31+
1A2B3C0000000000000008BB /* MarkdownEngineCodeBlocks in Frameworks */,
32+
1A2B3C0000000000000009BB /* MarkdownEngineLatex in Frameworks */,
2733
);
2834
runOnlyForDeploymentPostprocessing = 0;
2935
};
@@ -51,6 +57,7 @@
5157
children = (
5258
1A2B3C0000000000000004AA /* MarkdownEngineDemoApp.swift */,
5359
1A2B3C0000000000000005AA /* ContentView.swift */,
60+
1A2B3C0000000000000006AA /* MDE.icon */,
5461
);
5562
path = MarkdownEngineDemo;
5663
sourceTree = "<group>";
@@ -73,6 +80,8 @@
7380
name = MarkdownEngineDemo;
7481
packageProductDependencies = (
7582
1A2B3C0000000000000007BB /* MarkdownEngine */,
83+
1A2B3C0000000000000008AA /* MarkdownEngineCodeBlocks */,
84+
1A2B3C0000000000000009AA /* MarkdownEngineLatex */,
7685
);
7786
productName = MarkdownEngineDemo;
7887
productReference = 1A2B3C0000000000000003DD /* MarkdownEngineDemo.app */;
@@ -119,6 +128,7 @@
119128
isa = PBXResourcesBuildPhase;
120129
buildActionMask = 2147483647;
121130
files = (
131+
1A2B3C0000000000000006BB /* MDE.icon in Resources */,
122132
);
123133
runOnlyForDeploymentPostprocessing = 0;
124134
};
@@ -140,6 +150,7 @@
140150
1A2B3C0000000000000002BB /* Debug */ = {
141151
isa = XCBuildConfiguration;
142152
buildSettings = {
153+
ASSETCATALOG_COMPILER_APPICON_NAME = MDE;
143154
CODE_SIGN_IDENTITY = "-";
144155
CODE_SIGN_STYLE = Automatic;
145156
COMBINE_HIDPI_IMAGES = YES;
@@ -165,6 +176,7 @@
165176
1A2B3C0000000000000002CC /* Release */ = {
166177
isa = XCBuildConfiguration;
167178
buildSettings = {
179+
ASSETCATALOG_COMPILER_APPICON_NAME = MDE;
168180
CODE_SIGN_IDENTITY = "-";
169181
CODE_SIGN_STYLE = Automatic;
170182
COMBINE_HIDPI_IMAGES = YES;
@@ -338,6 +350,14 @@
338350
isa = XCSwiftPackageProductDependency;
339351
productName = MarkdownEngine;
340352
};
353+
1A2B3C0000000000000008AA /* MarkdownEngineCodeBlocks */ = {
354+
isa = XCSwiftPackageProductDependency;
355+
productName = MarkdownEngineCodeBlocks;
356+
};
357+
1A2B3C0000000000000009AA /* MarkdownEngineLatex */ = {
358+
isa = XCSwiftPackageProductDependency;
359+
productName = MarkdownEngineLatex;
360+
};
341361
/* End XCSwiftPackageProductDependency section */
342362
};
343363
rootObject = 1A2B3C0000000000000001AA /* Project object */;

‎Demo/MarkdownEngineDemo/ContentView.swift‎

Lines changed: 158 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,173 @@
88
import SwiftUI
99
import MarkdownEngine
1010

11+
// Optional bridge products. Each is independent — drop either of these
12+
// `#if` blocks (or remove the matching Swift Package product dependency
13+
// from the Xcode project) and the demo still compiles. Code blocks fall
14+
// back to plain monospace; LaTeX falls back to its raw `$…$` source.
15+
#if canImport(MarkdownEngineCodeBlocks)
16+
import MarkdownEngineCodeBlocks
17+
#endif
18+
#if canImport(MarkdownEngineLatex)
19+
import MarkdownEngineLatex
20+
#endif
21+
1122
struct ContentView: View {
1223
@State private var text: String = sampleMarkdown
1324

1425
var body: some View {
15-
NativeTextViewWrapper(text: $text)
26+
NativeTextViewWrapper(text: $text, configuration: configuration)
27+
}
28+
29+
/// The engine talks to your app through service protocols. Two of them —
30+
/// `SyntaxHighlighter` and `LatexRenderer` — render the code-block and
31+
/// LaTeX visuals. The base `MarkdownEngine` ships no-op defaults
32+
/// (plain monospace, raw `$…$`); the optional `MarkdownEngineCodeBlocks`
33+
/// and `MarkdownEngineLatex` products ship ready-made bridges backed by
34+
/// HighlighterSwift and SwiftMath respectively.
35+
///
36+
/// This demo opportunistically plugs in whichever bridges are linked,
37+
/// so you can see exactly what each one adds.
38+
private var configuration: MarkdownEditorConfiguration {
39+
var config = MarkdownEditorConfiguration.default
40+
41+
#if canImport(MarkdownEngineCodeBlocks)
42+
// Syntax highlighting for fenced code blocks. Auto-switches between
43+
// `atom-one-light` and `atom-one-dark` with system appearance.
44+
config.services.syntaxHighlighter = HighlighterSwiftBridge()
45+
#endif
46+
47+
#if canImport(MarkdownEngineLatex)
48+
// LaTeX rendering for `$inline$` and `$$block$$` math. Uses the
49+
// Latin Modern math font and tints formulas to match the theme.
50+
config.services.latex = SwiftMathBridge()
51+
#endif
52+
53+
return config
1654
}
1755
}
1856

19-
private let sampleMarkdown = """
57+
/// Builds the demo markdown shown when the editor first loads.
58+
///
59+
/// The text is composed from a fixed header/footer plus three feature
60+
/// sections — inline formatting, block math, and code — that swap between
61+
/// a full showcase and a short "feature unavailable" note depending on
62+
/// which optional bridge products are linked.
63+
///
64+
/// When a bridge is missing, the fallback links to the README section
65+
/// that explains how to enable that feature in your own app.
66+
private var sampleMarkdown: String {
67+
[
68+
markdownHeader,
69+
inlineFormattingSection,
70+
latexSection,
71+
codeSection,
72+
markdownFooter,
73+
].joined(separator: "\n\n")
74+
}
75+
76+
private let markdownHeader = """
2077
# MarkdownEngine
2178
22-
A native macOS Markdown editor built on **TextKit 2**, bridged to SwiftUI.
79+
A native macOS Markdown editor built on **TextKit 2**, bridged to SwiftUI — brought to you by [nodes-web.com](https://nodes-web.com).
80+
81+
Edit this text live. Formatting updates as you type.
82+
83+
---
84+
"""
85+
86+
/// Inline formatting demo. Drops the inline-LaTeX example sentence when
87+
/// the LaTeX bridge isn't linked, so the reader doesn't see raw `$…$`.
88+
private var inlineFormattingSection: String {
89+
#if canImport(MarkdownEngineLatex)
90+
return #"""
91+
## Inline formatting
92+
93+
Mix **bold**, *italic*, and ***both at once***. Reach for `inline code` when a short snippet helps. Inline math fits naturally in prose — the Pythagorean identity says $a^2 + b^2 = c^2$, and Euler's identity famously claims $e^{i\pi} + 1 = 0$.
94+
"""#
95+
#else
96+
return """
97+
## Inline formatting
98+
99+
Mix **bold**, *italic*, and ***both at once***. Reach for `inline code` when a short snippet helps.
100+
"""
101+
#endif
102+
}
103+
104+
/// Block LaTeX demo when the `MarkdownEngineLatex` bridge is linked;
105+
/// otherwise a short note pointing to the README section that explains
106+
/// how to enable LaTeX rendering.
107+
private var latexSection: String {
108+
#if canImport(MarkdownEngineLatex)
109+
return #"""
110+
## Block math
111+
112+
$$
113+
\int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi}
114+
$$
115+
116+
$$
117+
\frac{\partial}{\partial t}\Psi(\mathbf{r}, t) = -\frac{i}{\hbar}\hat{H}\,\Psi(\mathbf{r}, t)
118+
$$
119+
"""#
120+
#else
121+
return """
122+
## LaTeX
123+
124+
LaTeX (`$inline$` and `$$block$$`) is parsed but not rendered without the optional `MarkdownEngineLatex` product. See [LaTeX Rendering](https://github.com/nodes-app/swift-markdown-engine#latex-rendering) in the README to wire it up.
125+
"""
126+
#endif
127+
}
128+
129+
/// Fenced code-block demo when the `MarkdownEngineCodeBlocks` bridge is
130+
/// linked; otherwise a plain monospace example and a link to the
131+
/// README's Code Blocks section.
132+
private var codeSection: String {
133+
#if canImport(MarkdownEngineCodeBlocks)
134+
return #"""
135+
## Code
136+
137+
Swift, with syntax highlighting:
138+
139+
```swift
140+
import SwiftUI
141+
import MarkdownEngine
142+
143+
struct Editor: View {
144+
@State private var text = "# Hello"
145+
146+
var body: some View {
147+
NativeTextViewWrapper(text: $text)
148+
.frame(minWidth: 640, minHeight: 480)
149+
}
150+
}
151+
```
152+
153+
And a little JSON:
154+
155+
```json
156+
{
157+
"engine": "MarkdownEngine",
158+
"features": ["latex", "code", "wiki-links"],
159+
"version": 1.0
160+
}
161+
```
162+
"""#
163+
#else
164+
return #"""
165+
## Code
166+
167+
Fenced code blocks render as plain monospace without the optional `MarkdownEngineCodeBlocks` product. See [Code Blocks](https://github.com/nodes-app/swift-markdown-engine#code-blocks) in the README for syntax-highlighted output:
168+
169+
```swift
170+
let greeting = "Hello, world!"
171+
```
172+
"""#
173+
#endif
174+
}
23175
24-
## Features
25-
*Italic*
26-
**Bold**
176+
private let markdownFooter = """
177+
---
27178
179+
Built by [nodes-web.com](https://nodes-web.com).
28180
"""
Lines changed: 10 additions & 0 deletions
Loading
Lines changed: 10 additions & 0 deletions
Loading
Lines changed: 10 additions & 0 deletions
Loading
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"fill" : "automatic",
3+
"groups" : [
4+
{
5+
"blend-mode" : "normal",
6+
"blur-material" : 0.5,
7+
"hidden" : false,
8+
"layers" : [
9+
{
10+
"fill" : "automatic",
11+
"image-name" : "staroflife.fill 2-1.svg",
12+
"name" : "staroflife.fill 2-1",
13+
"position" : {
14+
"scale" : 3,
15+
"translation-in-points" : [
16+
0,
17+
90
18+
]
19+
}
20+
},
21+
{
22+
"image-name" : "staroflife.fill 2.svg",
23+
"name" : "staroflife.fill 2",
24+
"position" : {
25+
"scale" : 3,
26+
"translation-in-points" : [
27+
0,
28+
0
29+
]
30+
}
31+
},
32+
{
33+
"image-name" : "staroflife.fill 1.svg",
34+
"name" : "staroflife.fill 1",
35+
"position" : {
36+
"scale" : 3,
37+
"translation-in-points" : [
38+
0,
39+
-90
40+
]
41+
}
42+
}
43+
],
44+
"lighting" : "individual",
45+
"shadow" : {
46+
"kind" : "layer-color",
47+
"opacity" : 0.5
48+
},
49+
"specular" : false,
50+
"translucency" : {
51+
"enabled" : true,
52+
"value" : 0.45
53+
}
54+
}
55+
],
56+
"supported-platforms" : {
57+
"circles" : [
58+
"watchOS"
59+
],
60+
"squares" : "shared"
61+
}
62+
}

0 commit comments

Comments
 (0)