-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: endpoint * feat: highlight code * feat: highlight code
- Loading branch information
Showing
306 changed files
with
15,506 additions
and
387 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
Chato/Assets.xcassets/panda-syntax-dark.min.dataset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"data" : [ | ||
{ | ||
"filename" : "panda-syntax-dark.min.css", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
Chato/Assets.xcassets/panda-syntax-dark.min.dataset/panda-syntax-dark.min.css
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Created for Chato in 2024 | ||
|
||
import Foundation | ||
import Highlightr | ||
import MarkdownUI | ||
import SwiftUI | ||
|
||
struct HI: CodeSyntaxHighlighter { | ||
func highlightCode(_ code: String, language: String?) -> Text { | ||
if let highlightedCode = highlightr.highlight(code, as: language) { | ||
return convertToText(highlightedCode) | ||
} else { | ||
return Text("") | ||
} | ||
} | ||
|
||
static var shared = HI() | ||
let highlightr: Highlightr | ||
|
||
private init() { | ||
highlightr = Highlightr()! | ||
if !highlightr.setTheme(to: "panda-syntax-dark") { | ||
print("failed to load panda-syntax-dark.min.css") | ||
} | ||
} | ||
} | ||
|
||
private func convertToText(_ attributedString: NSAttributedString) -> Text { | ||
var result = Text("") // Start with an empty Text | ||
attributedString.enumerateAttributes(in: NSRange(location: 0, length: attributedString.length), options: []) { attributes, range, _ in | ||
// Create a substring for the given range | ||
let substring = attributedString.attributedSubstring(from: range).string | ||
|
||
// Create a Text view with attributes applied | ||
var text = Text(substring) | ||
|
||
// Apply attributes to the Text | ||
text = text.font(.callout) // Change font to SwiftUI Font | ||
// if let font = attributes[.font] as? UIFont { | ||
// text = text.font(.system(size: font.pointSize)) // Change font to SwiftUI Font | ||
// } | ||
if let color = attributes[.foregroundColor] as? UIColor { | ||
text = text.foregroundColor(Color(color)) // Change color to SwiftUI Color | ||
} | ||
// Add more attributes as needed (e.g. underline, strikethrough, etc.) | ||
|
||
// Combine the attributed Text fragments | ||
result = result + text | ||
} | ||
|
||
return result.fontDesign(.monospaced) | ||
} |
25 changes: 0 additions & 25 deletions
25
Chato/Theme+Effect/SyntaxHighlighter/SplashCodeSyntaxHighlighter.swift
This file was deleted.
Oops, something went wrong.
45 changes: 0 additions & 45 deletions
45
Chato/Theme+Effect/SyntaxHighlighter/TextOutputFormat.swift
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.