Skip to content

Commit 79b3035

Browse files
committed
make syntect optional in cli.
1 parent 040b132 commit 79b3035

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ lto = true
3131

3232
[[bin]]
3333
name = "comrak"
34-
required-features = ["cli", "syntect"]
34+
required-features = ["cli"]
3535
doc = false
3636

3737
[dependencies]
@@ -55,7 +55,7 @@ toml = "0.7.3"
5555

5656
[features]
5757
default = ["cli", "syntect", "bon"]
58-
cli = ["clap", "shell-words", "xdg", "fmt2io"]
58+
cli = ["clap", "bon", "shell-words", "xdg", "fmt2io"]
5959
shortcodes = ["emojis"]
6060
bon = ["dep:bon"]
6161

src/main.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ use std::{boxed::Box, io::BufWriter};
1010

1111
use clap::{Parser, ValueEnum};
1212

13-
use comrak::{
14-
adapters::SyntaxHighlighterAdapter, plugins::syntect::SyntectAdapter, Arena, ListStyleType,
15-
Options, Plugins,
16-
};
13+
#[cfg(feature = "syntect")]
14+
use comrak::{adapters::SyntaxHighlighterAdapter, plugins::syntect::SyntectAdapter};
15+
use comrak::{Arena, ListStyleType, Options, Plugins};
1716
use comrak::{ExtensionOptions, ParseOptions, RenderOptions};
1817

1918
const EXIT_SUCCESS: i32 = 0;
@@ -136,6 +135,7 @@ struct Cli {
136135

137136
/// Syntax highlighting for codefence blocks. Choose a theme or 'none' for disabling.
138137
#[arg(long, value_name = "THEME", default_value = "base16-ocean.dark")]
138+
#[cfg(feature = "syntect")]
139139
syntax_highlighting: String,
140140

141141
/// Specify bullet character for lists (-, +, *) in CommonMark output
@@ -315,16 +315,22 @@ fn main() -> Result<(), Box<dyn Error>> {
315315
render,
316316
};
317317

318+
#[cfg(feature = "syntect")]
318319
let syntax_highlighter: Option<&dyn SyntaxHighlighterAdapter>;
319-
let mut plugins: Plugins = Plugins::default();
320+
#[cfg(feature = "syntect")]
320321
let adapter: SyntectAdapter;
321322

322-
let theme = cli.syntax_highlighting;
323-
if theme.is_empty() || theme == "none" {
324-
syntax_highlighter = None;
325-
} else {
326-
adapter = SyntectAdapter::new(Some(&theme));
327-
syntax_highlighter = Some(&adapter);
323+
let mut plugins: Plugins = Plugins::default();
324+
325+
#[cfg(feature = "syntect")]
326+
{
327+
let theme = cli.syntax_highlighting;
328+
if theme.is_empty() || theme == "none" {
329+
syntax_highlighter = None;
330+
} else {
331+
adapter = SyntectAdapter::new(Some(&theme));
332+
syntax_highlighter = Some(&adapter);
333+
}
328334
}
329335

330336
let mut s: Vec<u8> = Vec::with_capacity(2048);
@@ -356,7 +362,10 @@ fn main() -> Result<(), Box<dyn Error>> {
356362
} else {
357363
match cli.format {
358364
Format::Html => {
359-
plugins.render.codefence_syntax_highlighter = syntax_highlighter;
365+
#[cfg(feature = "syntect")]
366+
{
367+
plugins.render.codefence_syntax_highlighter = syntax_highlighter;
368+
}
360369
comrak::format_html_with_plugins
361370
}
362371
Format::Xml => comrak::format_xml_with_plugins,

0 commit comments

Comments
 (0)