diff --git a/Cargo.lock b/Cargo.lock index 64610cc2f..98eaa81ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2645,6 +2645,17 @@ version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49d64318d8311fc2668e48b63969f4343e0a85c4a109aa8460d6672e364b8bd1" +[[package]] +name = "two-face" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37bed2135b2459c7eefba72c906d374697eb15949c205f2f124e3636a46b5eeb" +dependencies = [ + "once_cell", + "serde", + "syntect", +] + [[package]] name = "typed-arena" version = "2.0.2" @@ -2692,6 +2703,7 @@ dependencies = [ "toml", "tracing", "ttf-parser", + "two-face", "typed-arena", "typst-macros", "typst-syntax", diff --git a/Cargo.toml b/Cargo.toml index 9e6e5ac0c..bd82c3192 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -104,6 +104,7 @@ tracing-error = "0.2" tracing-flame = "0.2.0" tracing-subscriber = "0.3.17" ttf-parser = "0.19.2" +two-face = { version = "0.3.0", default-features = false, features = ["syntect-fancy"] } typed-arena = "2" unicode_names2 = "1.2" unicode-bidi = "0.3.13" diff --git a/NOTICE b/NOTICE index 92e1a54a3..650625851 100644 --- a/NOTICE +++ b/NOTICE @@ -215,7 +215,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ================================================================================ ================================================================================ -Syntaxes in `crates/typst-library/assets/syntect.bin` are generated from syntax +Syntaxes embedded within the `two-face` crate are generated from syntax definitions which can be found here: https://github.com/sharkdp/bat/tree/master/assets/syntaxes diff --git a/crates/typst/Cargo.toml b/crates/typst/Cargo.toml index af90a1d8b..a22bb7927 100644 --- a/crates/typst/Cargo.toml +++ b/crates/typst/Cargo.toml @@ -54,6 +54,7 @@ time = { workspace = true } toml = { workspace = true } tracing = { workspace = true } ttf-parser = { workspace = true } +two-face = { workspace = true } typed-arena = { workspace = true } unicode-bidi = { workspace = true } unicode-math-class = { workspace = true } diff --git a/crates/typst/assets/syntect.bin b/crates/typst/assets/syntect.bin deleted file mode 100644 index 043602a47..000000000 Binary files a/crates/typst/assets/syntect.bin and /dev/null differ diff --git a/crates/typst/src/text/raw.rs b/crates/typst/src/text/raw.rs index aa2f93f88..1f9f9ccb0 100644 --- a/crates/typst/src/text/raw.rs +++ b/crates/typst/src/text/raw.rs @@ -734,31 +734,10 @@ fn parse_theme( /// The syntect syntax definitions. /// -/// Code for syntax set generation is below. The `syntaxes` directory is from +/// Syntax set is generated from the syntaxes from the `bat` project /// -/// -/// ```ignore -/// fn main() { -/// let mut builder = syntect::parsing::SyntaxSet::load_defaults_nonewlines().into_builder(); -/// builder.add_from_folder("syntaxes/02_Extra", false).unwrap(); -/// syntect::dumps::dump_to_file(&builder.build(), "syntect.bin").unwrap(); -/// } -/// ``` -/// -/// The following syntaxes are disabled due to compatibility issues: -/// ```text -/// syntaxes/02_Extra/Assembly (ARM).sublime-syntax -/// syntaxes/02_Extra/Elixir/Regular Expressions (Elixir).sublime-syntax -/// syntaxes/02_Extra/JavaScript (Babel).sublime-syntax -/// syntaxes/02_Extra/LiveScript.sublime-syntax -/// syntaxes/02_Extra/PowerShell.sublime-syntax -/// syntaxes/02_Extra/SCSS_Sass/Syntaxes/Sass.sublime-syntax -/// syntaxes/02_Extra/SLS/SLS.sublime-syntax -/// syntaxes/02_Extra/VimHelp.sublime-syntax -/// syntaxes/02_Extra/cmd-help/syntaxes/cmd-help.sublime-syntax -/// ``` pub static RAW_SYNTAXES: Lazy = - Lazy::new(|| syntect::dumps::from_binary(include_bytes!("../../assets/syntect.bin"))); + Lazy::new(two_face::syntax::extra_no_newlines); /// The default theme used for syntax highlighting. pub static RAW_THEME: Lazy = Lazy::new(|| synt::Theme { diff --git a/tests/ref/text/raw-code.png b/tests/ref/text/raw-code.png index f772ba411..d3373f5f7 100644 Binary files a/tests/ref/text/raw-code.png and b/tests/ref/text/raw-code.png differ