Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,39 @@
<key>LSHandlerRank</key>
<string>Owner</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>json</string>
</array>
<key>CFBundleTypeName</key>
<string>JSON Document</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSItemContentTypes</key>
<array>
<string>public.json</string>
</array>
<key>LSHandlerRank</key>
<string>Alternate</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>yaml</string>
<string>yml</string>
</array>
<key>CFBundleTypeName</key>
<string>YAML Document</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSItemContentTypes</key>
<array>
<string>public.yaml</string>
</array>
<key>LSHandlerRank</key>
<string>Alternate</string>
</dict>
</array>
<key>UTImportedTypeDeclarations</key>
<array>
Expand Down
6 changes: 5 additions & 1 deletion Sources/MarkdownViewerLib/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ public struct ContentView: View {
return "\(total)/\(resolved)"
}

private var markdownForRendering: String {
HTMLRenderer.wrapForRendering(currentText, fileExtension: fileURL?.pathExtension)
}

private var effectiveOverrideHTML: String? {
if showDiff { return diffHTML }
switch viewMode {
Expand Down Expand Up @@ -264,7 +268,7 @@ public struct ContentView: View {
Divider()
}
MarkdownWebView(
markdown: currentText,
markdown: markdownForRendering,
fileURL: fileURL,
overrideHTML: effectiveOverrideHTML,
searchText: showSearch ? searchText : "",
Expand Down
12 changes: 12 additions & 0 deletions Sources/MarkdownViewerLib/HTMLRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ public enum HTMLRenderer {
.replacingOccurrences(of: "{{MARKDOWN_CONTENT}}", with: escaped)
}

public static func wrapForRendering(_ text: String, fileExtension: String?) -> String {
guard let ext = fileExtension?.lowercased() else { return text }
switch ext {
case "json":
return "```json\n\(text)\n```"
case "yaml", "yml":
return "```yaml\n\(text)\n```"
default:
return text
}
}

static func escapeForJSTemplateLiteral(_ string: String) -> String {
string
.replacingOccurrences(of: "\\", with: "\\\\")
Expand Down
2 changes: 1 addition & 1 deletion Sources/MarkdownViewerLib/MarkdownDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public extension UTType {
}

public struct MarkdownDocument: FileDocument {
public static var readableContentTypes: [UTType] = [.markdown, .plainText]
public static var readableContentTypes: [UTType] = [.markdown, .plainText, .json, .yaml]

public var text: String

Expand Down
Loading
Loading