Skip to content

Commit

Permalink
feat: Support Markdown syntax highlighting (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbmorley authored May 3, 2024
1 parent c515c95 commit 440d925
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
[submodule "scripts/build-tools"]
path = scripts/build-tools
url = https://github.com/jbmorley/build-tools.git
[submodule "HighlightedTextEditor"]
path = HighlightedTextEditor
url = [email protected]:jbmorley/HighlightedTextEditor.git
1 change: 1 addition & 0 deletions HighlightedTextEditor
Submodule HighlightedTextEditor added at 500680
17 changes: 17 additions & 0 deletions Thoughts.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
D89224A42BD7368F00DA0932 /* TimeZoneTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D89224A32BD7368F00DA0932 /* TimeZoneTests.swift */; };
D89224A72BD736B900DA0932 /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = D89224A62BD736B900DA0932 /* Date.swift */; };
D89224A92BD736DF00DA0932 /* TimeZone.swift in Sources */ = {isa = PBXBuildFile; fileRef = D89224A82BD736DF00DA0932 /* TimeZone.swift */; };
D8BA4D492BE59E16001A2A26 /* HighlightedTextEditor in Frameworks */ = {isa = PBXBuildFile; productRef = D8BA4D482BE59E16001A2A26 /* HighlightedTextEditor */; };
D8BA4D4B2BE5A2FD001A2A26 /* highlightedtexteditor-license in Resources */ = {isa = PBXBuildFile; fileRef = D8BA4D4A2BE5A2FD001A2A26 /* highlightedtexteditor-license */; };
D8C283E52BD9939E00161C82 /* TokenView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8C283E42BD9939E00161C82 /* TokenView.swift */; };
D8C283E92BD9954F00161C82 /* HashRainbow in Frameworks */ = {isa = PBXBuildFile; productRef = D8C283E82BD9954F00161C82 /* HashRainbow */; };
D8C283EE2BD9957700161C82 /* TokenViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8C283ED2BD9957700161C82 /* TokenViewModel.swift */; };
Expand Down Expand Up @@ -96,6 +98,7 @@
D89224A32BD7368F00DA0932 /* TimeZoneTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeZoneTests.swift; sourceTree = "<group>"; };
D89224A62BD736B900DA0932 /* Date.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Date.swift; sourceTree = "<group>"; };
D89224A82BD736DF00DA0932 /* TimeZone.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeZone.swift; sourceTree = "<group>"; };
D8BA4D4A2BE5A2FD001A2A26 /* highlightedtexteditor-license */ = {isa = PBXFileReference; lastKnownFileType = text; path = "highlightedtexteditor-license"; sourceTree = "<group>"; };
D8C283E42BD9939E00161C82 /* TokenView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenView.swift; sourceTree = "<group>"; };
D8C283ED2BD9957700161C82 /* TokenViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenViewModel.swift; sourceTree = "<group>"; };
D8C283EF2BD995AD00161C82 /* PickerTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PickerTextField.swift; sourceTree = "<group>"; };
Expand All @@ -118,6 +121,7 @@
files = (
D8F06D4E2B6727630039AEF4 /* Interact in Frameworks */,
D8C283E92BD9954F00161C82 /* HashRainbow in Frameworks */,
D8BA4D492BE59E16001A2A26 /* HighlightedTextEditor in Frameworks */,
D892249A2BD70CC300DA0932 /* Yams in Frameworks */,
D8F06D4B2B67275B0039AEF4 /* Diligence in Frameworks */,
);
Expand Down Expand Up @@ -280,6 +284,7 @@
D8F06D552B6734540039AEF4 /* material-icons-license */,
D8F06D532B6733650039AEF4 /* thoughts-license */,
D84010C42BD74C760049715E /* yams-license */,
D8BA4D4A2BE5A2FD001A2A26 /* highlightedtexteditor-license */,
);
path = Licenses;
sourceTree = "<group>";
Expand All @@ -305,6 +310,7 @@
D8F06D4D2B6727630039AEF4 /* Interact */,
D89224992BD70CC300DA0932 /* Yams */,
D8C283E82BD9954F00161C82 /* HashRainbow */,
D8BA4D482BE59E16001A2A26 /* HighlightedTextEditor */,
);
productName = "Disk Stickies";
productReference = D852AEFE2B6027CA00B77A3D /* Thoughts.app */;
Expand Down Expand Up @@ -383,6 +389,7 @@
D8F06D4C2B6727630039AEF4 /* XCLocalSwiftPackageReference "interact" */,
D89224982BD70CC300DA0932 /* XCRemoteSwiftPackageReference "Yams" */,
D8C283E72BD9954F00161C82 /* XCRemoteSwiftPackageReference "HashRainbow" */,
D8BA4D472BE59DC5001A2A26 /* XCLocalSwiftPackageReference "HighlightedTextEditor" */,
);
productRefGroup = D852AEFF2B6027CA00B77A3D /* Products */;
projectDirPath = "";
Expand All @@ -406,6 +413,7 @@
D852AF062B6027CC00B77A3D /* Assets.xcassets in Resources */,
D84010C52BD74C760049715E /* yams-license in Resources */,
D8C283F72BD9ADC400161C82 /* hashrainbow-license in Resources */,
D8BA4D4B2BE5A2FD001A2A26 /* highlightedtexteditor-license in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -803,6 +811,10 @@
/* End XCConfigurationList section */

/* Begin XCLocalSwiftPackageReference section */
D8BA4D472BE59DC5001A2A26 /* XCLocalSwiftPackageReference "HighlightedTextEditor" */ = {
isa = XCLocalSwiftPackageReference;
relativePath = HighlightedTextEditor;
};
D8F06D492B67275B0039AEF4 /* XCLocalSwiftPackageReference "diligence" */ = {
isa = XCLocalSwiftPackageReference;
relativePath = diligence;
Expand Down Expand Up @@ -838,6 +850,11 @@
package = D89224982BD70CC300DA0932 /* XCRemoteSwiftPackageReference "Yams" */;
productName = Yams;
};
D8BA4D482BE59E16001A2A26 /* HighlightedTextEditor */ = {
isa = XCSwiftPackageProductDependency;
package = D8BA4D472BE59DC5001A2A26 /* XCLocalSwiftPackageReference "HighlightedTextEditor" */;
productName = HighlightedTextEditor;
};
D8C283E82BD9954F00161C82 /* HashRainbow */ = {
isa = XCSwiftPackageProductDependency;
package = D8C283E72BD9954F00161C82 /* XCRemoteSwiftPackageReference "HashRainbow" */;
Expand Down
12 changes: 11 additions & 1 deletion Thoughts/Extensions/Licensable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ fileprivate let hashRainbowLicense = License(id: "https://github.com/saramah/Has
title: "GitHub"),
])

fileprivate let highlightedTextEditorLicense = License(id: "https://github.com/kyle-n/HighlightedTextEditor",
name: "HighlightedTextEditor",
author: "Kyle Nazario",
text: String(contentsOfResource: "highlightedtexteditor-license"),
attributes: [
.url(URL(string: "https://github.com/kyle-n/HighlightedTextEditor/")!,
title: "GitHub"),
])

fileprivate let yamsLicense = License(id: "https://github.com/jpsim/Yams",
name: "Yams",
author: "JP Simard",
Expand All @@ -59,8 +68,9 @@ fileprivate let thoughtsLicense = License(id: "https://github.com/inseven/though
licenses: [
.interact,
.licensable,
materialIconsLicense,
hashRainbowLicense,
highlightedTextEditorLicense,
materialIconsLicense,
yamsLicense,
])

Expand Down
21 changes: 21 additions & 0 deletions Thoughts/Licenses/highlightedtexteditor-license
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Kyle Nazario

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 4 additions & 2 deletions Thoughts/ThoughtsApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ struct ThoughtsApp: App {
}

About(repository: "inseven/thoughts", copyright: "Copyright © 2024 Jason Morley") {
Diligence.Action("GitHub", url: URL(string: "https://github.com/inseven/thoughts")!)
Diligence.Action("Support", url: URL(address: "[email protected]", subject: Self.title)!)
Action("Website", url: URL(string: "https://thoughts.jbmorley.co.uk")!)
Action("Privacy Policy", url: URL(string: "https://thoughts.jbmorley.co.uk/privacy-policy")!)
Action("GitHub", url: URL(string: "https://github.com/inseven/thoughts")!)
Action("Support", url: URL(address: "[email protected]", subject: Self.title)!)
} acknowledgements: {
Acknowledgements("Developers") {
Credit("Jason Morley", url: URL(string: "https://jbmorley.co.uk"))
Expand Down
19 changes: 15 additions & 4 deletions Thoughts/Views/ComposeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import SwiftUI

import HighlightedTextEditor

struct ComposeView: View {

var applicationModel: ApplicationModel
Expand All @@ -41,12 +43,21 @@ struct ComposeView: View {
var body: some View {
@Bindable var applicationModel = applicationModel
VStack(spacing: 0) {
TextEditor(text: $applicationModel.document.content)
.scrollContentBackground(.hidden)
HighlightedTextEditor(text: $applicationModel.document.content, highlightRules: .markdown)
// .introspect { editor in
// let font = NSFont.monospacedSystemFont(ofSize: 14, weight: .regular)
// editor.textView.font = font
// }
// .scrollContentBackground(.hidden)
.frame(minWidth: 400)
.font(.system(size: 14, design: .monospaced))
.monospaced()
.edgesIgnoringSafeArea(.all)

// TextEditor(text: $applicationModel.document.content)
// .scrollContentBackground(.hidden)
// .frame(minWidth: 400)
// .font(.system(size: 14, design: .monospaced))
// .monospaced()
// .edgesIgnoringSafeArea(.all)
Divider()
HStack {
TokenView("Add tags...", tokens: $applicationModel.document.tags)
Expand Down
10 changes: 10 additions & 0 deletions Thoughts/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@

import SwiftUI

struct FontInspector: View {

@Environment(\.font) var font

var body: some View {
Text("Cheeese")
}

}

struct ContentView: View {

var applicationModel: ApplicationModel
Expand Down

0 comments on commit 440d925

Please sign in to comment.