Skip to content

Commit d983fea

Browse files
authored
Merge pull request #624 from kivikakk/push-soqvoyqsyzlr
syntect optional in cli; disable syntax highlighting in bench.
2 parents 040b132 + daf30ec commit d983fea

File tree

6 files changed

+46
-20
lines changed

6 files changed

+46
-20
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ benches/pulldown-cmark
1010
benches/markdown-it
1111
/result
1212
/bench-output.md
13+
14+
benches/samply-bench-input.md
15+
/profile-*.json.gz

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

Makefile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ bench:
1313
binaries: build-comrak-branch build-comrak-main build-cmark-gfm build-pulldown-cmark build-markdown-it
1414

1515
build-comrak-branch:
16-
cargo build --release
16+
cargo build --release --bin comrak --no-default-features --features cli
1717
cp ${ROOT}/target/release/comrak ${ROOT}/benches/comrak-${COMMIT}
1818

1919
build-comrak-main:
2020
git clone https://github.com/kivikakk/comrak.git --depth 1 --single-branch ${ROOT}/vendor/comrak || true
2121
cd ${ROOT}/vendor/comrak && \
22-
cargo build --release && \
22+
cargo build --release --bin comrak --no-default-features --features cli && \
2323
cp ./target/release/comrak ${ROOT}/benches/comrak-main
2424

2525
build-cmark-gfm:
@@ -54,3 +54,16 @@ bench-all: binaries
5454
hyperfine --warmup 10 --min-runs ${MIN_RUNS} -L binary comrak-${COMMIT},comrak-main,pulldown-cmark,cmark-gfm,markdown-it './bench.sh ./{binary}' --export-markdown ${ROOT}/bench-output.md &&\
5555
echo "\n\nRun on" `date -u` >> ${ROOT}/bench-output.md
5656

57+
benches/samply-bench-input.md:
58+
cat ${ROOT}/vendor/progit/*/*/*.markdown > $@
59+
60+
SAMPLY_OPTIONS:=-r 10000 --iteration-count 20 --reuse-threads
61+
SAMPLY_COMRAK_ARGS:=--syntax-highlighting none benches/samply-bench-input.md -o /dev/null
62+
63+
samply-comrak-branch: benches/samply-bench-input.md build-comrak-branch
64+
cat ${ROOT}/vendor/progit/*/*/*.markdown > benches/samply-bench-input.md
65+
samply record -o profile-branch.json.gz ${SAMPLY_OPTIONS} ${ROOT}/benches/comrak-${COMMIT} ${SAMPLY_COMRAK_ARGS}
66+
67+
samply-comrak-main: benches/samply-bench-input.md build-comrak-main
68+
cat ${ROOT}/vendor/progit/*/*/*.markdown > benches/samply-bench-input.md
69+
samply record -o profile-main.json.gz ${SAMPLY_OPTIONS} -P 3001 ${ROOT}/benches/comrak-main ${SAMPLY_COMRAK_ARGS}

benches/bench.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#! /bin/bash
22

3-
PROG=$1
3+
PROG="$1"
44
ROOTDIR=$(git rev-parse --show-toplevel)
55

6-
for lang in ar az be ca cs de en eo es es-ni fa fi fr hi hu id it ja ko mk nl no-nb pl pt-br ro ru sr th tr uk vi zh zh-tw; do \
7-
cat $ROOTDIR/vendor/progit/$lang/*/*.markdown | $PROG > /dev/null
8-
done
6+
cat $ROOTDIR/vendor/progit/*/*/*.markdown | "$PROG" > /dev/null

flake.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@
100100
clippy
101101
cargo-fuzz
102102
cargo-nextest
103+
cargo-flamegraph
104+
samply
103105
python3
104106
re2c
105107
hyperfine

src/main.rs

Lines changed: 22 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,23 @@ 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+
#[cfg_attr(not(feature = "syntect"), allow(unused_mut))]
324+
let mut plugins: Plugins = Plugins::default();
325+
326+
#[cfg(feature = "syntect")]
327+
{
328+
let theme = cli.syntax_highlighting;
329+
if theme.is_empty() || theme == "none" {
330+
syntax_highlighter = None;
331+
} else {
332+
adapter = SyntectAdapter::new(Some(&theme));
333+
syntax_highlighter = Some(&adapter);
334+
}
328335
}
329336

330337
let mut s: Vec<u8> = Vec::with_capacity(2048);
@@ -356,7 +363,10 @@ fn main() -> Result<(), Box<dyn Error>> {
356363
} else {
357364
match cli.format {
358365
Format::Html => {
359-
plugins.render.codefence_syntax_highlighter = syntax_highlighter;
366+
#[cfg(feature = "syntect")]
367+
{
368+
plugins.render.codefence_syntax_highlighter = syntax_highlighter;
369+
}
360370
comrak::format_html_with_plugins
361371
}
362372
Format::Xml => comrak::format_xml_with_plugins,

0 commit comments

Comments
 (0)