Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Expose new syntect default variant features #11

Merged
merged 1 commit into from
Apr 25, 2024
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
15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,22 @@ repository = "https://github.com/CosmicHorrorDev/two-face"
homepage = "https://github.com/CosmicHorrorDev/two-face"

[package.metadata.docs.rs]
all-features = true
features = ["syntect-default-onig"]

[features]
# TODO: I don't like having to set this as a default, but `syntect` can't
# compile without a regex impl
# `syntect` can't compile without a regex implementation, so we match its
# default of onig
default = ["syntect-onig"]

# A minimal set of `syntect` features with the onig regex implementation
syntect-onig = ["syntect/regex-onig"]
# A minimal set of `syntect` features with the fancy regex implementation
syntect-fancy = ["syntect/regex-fancy"]

# Don't like this, but I want to link to the functions provided by this from my
# documentation
unstable = ["syntect/default-syntaxes"]
# Toggles on `syntect`'s `default-onig` feature
syntect-default-onig = ["syntect-onig", "syntect/default-onig"]
# Toggles on `syntect`'s `default-fancy` feature
syntect-default-fancy = ["syntect-fancy", "syntect/default-fancy"]

[dependencies]
once_cell.workspace = true
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ that are missing from the default set like TOML, TypeScript, and Dockerfile

The following

```toml
[dependencies]
syntect = "0.5.1"
two-face = "0.2.0"
```cmd
$ cargo add two-face --features syntect-default-onig
```

```rust
use two_face::re_exports::syntect;

const TOML_TEXT: &str = "\
[section]
key = 123
Expand Down Expand Up @@ -61,19 +61,19 @@ implementation with the one you're using from syntect

To use [`Oniguruma`](https://github.com/kkos/oniguruma) aka onig

```toml
```cmd
[dependencies]
# `onig` is the default
syntect = "0.5.1"
two-face = "0.2.0"
two-face = "0.3.1"
```

To use [`fancy-regex`](https://github.com/fancy-regex/fancy-regex)

```toml
[dependencies]
syntect = { version = "0.5.1", default-features = false, features = ["default-fancy"] }
two-face = { version = "0.2.0", default-features = false, features = ["syntect-fancy"] }
two-face = { version = "0.3.1", default-features = false, features = ["syntect-fancy"] }
```

## Legal
Expand Down
25 changes: 19 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
//!
//! # Example
//!
//! ```toml
//! [dependencies]
//! syntect = "0.5.1"
//! two-face = "0.2.0"
//! ```text
//! $ cargo add two-face --features syntect-default-onig
//! ```
//!
//! ```
//! use two_face::re_exports::syntect;
//!
//! const TOML_TEXT: &str = "\
//! [section]
//! key = 123
Expand Down Expand Up @@ -53,15 +53,15 @@
//! [dependencies]
//! # `onig` is the default
//! syntect = "0.5.1"
//! two-face = "0.2.0"
//! two-face = "0.3.1"
//! ```
//!
//! To use [`fancy-regex`](https://github.com/fancy-regex/fancy-regex)
//!
//! ```toml
//! [dependencies]
//! syntect = { version = "0.5.1", default-features = false, features = ["default-fancy"] }
//! two-face = { version = "0.2.0", default-features = false, features = ["syntect-fancy"] }
//! two-face = { version = "0.3.1", default-features = false, features = ["syntect-fancy"] }
//! ```

#[cfg(doctest)]
Expand All @@ -72,6 +72,19 @@ pub mod acknowledgement;
pub mod syntax;
pub mod theme;

/// Dependency re-exports for user's convenience
///
/// # `syntect`
///
/// By default `two-face` uses the minimal feature set from `syntect` required for things to work,
/// but the default features can be toggled on with the `syntect-default-onig` and
/// `syntect-default-fancy` feature flags (depending on which syntect regex implementation you're
/// using). If you need more granular features than the ones provided then you should probably
/// depend directly on `syntect` instead
pub mod re_exports {
pub use syntect;
}

// Compile error if we're using syntaxes without setting fancy vs onig
#[cfg(not(any(feature = "syntect-onig", feature = "syntect-fancy")))]
compile_error!(
Expand Down