Skip to content
Merged
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
105 changes: 85 additions & 20 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.9
// swift-tools-version: 6.1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Update the advertised Swift requirement

Because this tools-version line makes SwiftPM 6.1 the minimum, the README Requirements section still saying Swift 5.9+ is now wrong; users on Swift 5.9 or 5.10 following the published install docs will fail while loading the manifest before they can build. Update the documented minimum/toolchain compatibility along with this manifest change.

Useful? React with 👍 / 👎.

// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -16,6 +16,49 @@ let package = Package(
.library(name: "MarkdownView", targets: ["MarkdownView"]),
.library(name: "MarkdownParser", targets: ["MarkdownParser"]),
],
traits: [
// By default every language grammar is enabled, so existing consumers
// see no change. Opt into a subset by disabling defaults and listing
// only the languages you need, e.g. `traits: ["Swift", "JSON"]`.
.default(enabledTraits: [
"Python",
"JavaScript",
"TypeScript",
"Go",
"Rust",
"Swift",
"C",
"CPP",
"Java",
"Ruby",
"Bash",
"JSON",
"HTML",
"CSS",
"CSharp",
"Kotlin",
"SQL",
"YAML",
]),
.trait(name: "Python", description: "Python syntax highlighting"),
.trait(name: "JavaScript", description: "JavaScript syntax highlighting"),
.trait(name: "TypeScript", description: "TypeScript and TSX syntax highlighting"),
.trait(name: "Go", description: "Go syntax highlighting"),
.trait(name: "Rust", description: "Rust syntax highlighting"),
.trait(name: "Swift", description: "Swift syntax highlighting"),
.trait(name: "C", description: "C syntax highlighting"),
.trait(name: "CPP", description: "C++ syntax highlighting"),
.trait(name: "Java", description: "Java syntax highlighting"),
.trait(name: "Ruby", description: "Ruby syntax highlighting"),
.trait(name: "Bash", description: "Bash/shell syntax highlighting"),
.trait(name: "JSON", description: "JSON syntax highlighting"),
.trait(name: "HTML", description: "HTML syntax highlighting"),
.trait(name: "CSS", description: "CSS syntax highlighting"),
.trait(name: "CSharp", description: "C# syntax highlighting"),
.trait(name: "Kotlin", description: "Kotlin syntax highlighting"),
.trait(name: "SQL", description: "SQL syntax highlighting"),
.trait(name: "YAML", description: "YAML syntax highlighting"),
],
dependencies: [
.package(url: "https://github.com/mgriebling/SwiftMath", from: "1.7.3"),
.package(url: "https://github.com/tree-sitter/swift-tree-sitter", from: "0.9.0"),
Expand Down Expand Up @@ -51,24 +94,42 @@ let package = Package(
"MarkdownParser",
"SwiftMath",
.product(name: "SwiftTreeSitter", package: "swift-tree-sitter"),
.product(name: "TreeSitterPython", package: "tree-sitter-python"),
.product(name: "TreeSitterJavaScript", package: "tree-sitter-javascript"),
.product(name: "TreeSitterTypeScript", package: "tree-sitter-typescript"),
.product(name: "TreeSitterGo", package: "tree-sitter-go"),
.product(name: "TreeSitterRust", package: "tree-sitter-rust"),
.product(name: "TreeSitterSwift", package: "tree-sitter-swift"),
.product(name: "TreeSitterC", package: "tree-sitter-c"),
.product(name: "TreeSitterCPP", package: "tree-sitter-cpp"),
.product(name: "TreeSitterJava", package: "tree-sitter-java"),
.product(name: "TreeSitterRuby", package: "tree-sitter-ruby"),
.product(name: "TreeSitterBash", package: "tree-sitter-bash"),
.product(name: "TreeSitterJSON", package: "tree-sitter-json"),
.product(name: "TreeSitterHTML", package: "tree-sitter-html"),
.product(name: "TreeSitterCSS", package: "tree-sitter-css"),
.product(name: "TreeSitterCSharp", package: "tree-sitter-c-sharp"),
.product(name: "TreeSitterKotlin", package: "tree-sitter-kotlin"),
.product(name: "TreeSitterSql", package: "tree-sitter-sql"),
.product(name: "TreeSitterYAML", package: "tree-sitter-yaml"),
.product(name: "TreeSitterPython", package: "tree-sitter-python",
condition: .when(traits: ["Python"])),
.product(name: "TreeSitterJavaScript", package: "tree-sitter-javascript",
condition: .when(traits: ["JavaScript"])),
.product(name: "TreeSitterTypeScript", package: "tree-sitter-typescript",
condition: .when(traits: ["TypeScript"])),
.product(name: "TreeSitterGo", package: "tree-sitter-go",
condition: .when(traits: ["Go"])),
.product(name: "TreeSitterRust", package: "tree-sitter-rust",
condition: .when(traits: ["Rust"])),
.product(name: "TreeSitterSwift", package: "tree-sitter-swift",
condition: .when(traits: ["Swift"])),
.product(name: "TreeSitterC", package: "tree-sitter-c",
condition: .when(traits: ["C"])),
.product(name: "TreeSitterCPP", package: "tree-sitter-cpp",
condition: .when(traits: ["CPP"])),
.product(name: "TreeSitterJava", package: "tree-sitter-java",
condition: .when(traits: ["Java"])),
.product(name: "TreeSitterRuby", package: "tree-sitter-ruby",
condition: .when(traits: ["Ruby"])),
.product(name: "TreeSitterBash", package: "tree-sitter-bash",
condition: .when(traits: ["Bash"])),
.product(name: "TreeSitterJSON", package: "tree-sitter-json",
condition: .when(traits: ["JSON"])),
.product(name: "TreeSitterHTML", package: "tree-sitter-html",
condition: .when(traits: ["HTML"])),
.product(name: "TreeSitterCSS", package: "tree-sitter-css",
condition: .when(traits: ["CSS"])),
.product(name: "TreeSitterCSharp", package: "tree-sitter-c-sharp",
condition: .when(traits: ["CSharp"])),
.product(name: "TreeSitterKotlin", package: "tree-sitter-kotlin",
condition: .when(traits: ["Kotlin"])),
.product(name: "TreeSitterSql", package: "tree-sitter-sql",
condition: .when(traits: ["SQL"])),
.product(name: "TreeSitterYAML", package: "tree-sitter-yaml",
condition: .when(traits: ["YAML"])),
],
resources: [.process("Resources")]
),
Expand All @@ -83,5 +144,9 @@ let package = Package(
"MarkdownParser",
]
),
]
],
// Preserve the Swift 5 language mode. Bumping swift-tools-version to 6.1
// (required for traits) would otherwise default the package to the Swift 6
// language mode and turn pre-existing concurrency warnings into errors.
swiftLanguageModes: [.v5]
)
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The plain-text streaming fast path applies to safe token appends that do not int
## Requirements

- iOS 16+ / macOS 13+ / visionOS 1+
- Swift 5.9+
- Swift 6.1+ (Swift tools 6.1, required for package traits)

## Installation

Expand All @@ -56,6 +56,24 @@ dependencies: [

Then add `"MarkdownView"` as a dependency of your target.

### Selecting languages with package traits

Syntax highlighting ships grammars for many languages, each behind a [package trait](https://docs.swift.org/swiftpm/documentation/packagemanagerdocs/packagetraits/). By default every language is enabled, so no configuration is needed.

To keep only the languages you use — pruning the rest from resolution and build — disable the defaults and list the traits you want:

```swift
dependencies: [
.package(
url: "https://github.com/HumanInterfaceDesign/MarkdownView",
branch: "main",
traits: ["Swift", "JSON"]
),
]
```

Available traits: `Python`, `JavaScript`, `TypeScript` (includes TSX), `Go`, `Rust`, `Swift`, `C`, `CPP`, `Java`, `Ruby`, `Bash`, `JSON`, `HTML`, `CSS`, `CSharp`, `Kotlin`, `SQL`, `YAML`. A language whose trait is disabled simply renders as plain text. Traits are a SwiftPM feature; adding the package through Xcode's UI always uses the default (all-languages) set.

## Usage

<img width="575" height="283" alt="Xcode 2026-03-02 09 24 19" src="https://github.com/user-attachments/assets/3c6b9fc2-f8c4-4afa-94a1-7fc47501b6b2" />
Expand Down
Loading
Loading