Skip to content

Commit c9cfe22

Browse files
committed
Apply some code style changes.
1 parent 5572d3d commit c9cfe22

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/renderer/html_handlebars/hbs_renderer.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -892,15 +892,15 @@ fn fix_code_blocks(html: &str) -> String {
892892
.into_owned()
893893
}
894894

895+
static CODE_BLOCK_RE: Lazy<Regex> =
896+
Lazy::new(|| Regex::new(r##"((?s)<code[^>]?class="([^"]+)".*?>(.*?)</code>)"##).unwrap());
897+
895898
fn add_playground_pre(
896899
html: &str,
897900
playground_config: &Playground,
898901
edition: Option<RustEdition>,
899902
) -> String {
900-
static ADD_PLAYGROUND_PRE: Lazy<Regex> =
901-
Lazy::new(|| Regex::new(r##"((?s)<code[^>]?class="([^"]+)".*?>(.*?)</code>)"##).unwrap());
902-
903-
ADD_PLAYGROUND_PRE
903+
CODE_BLOCK_RE
904904
.replace_all(html, |caps: &Captures<'_>| {
905905
let text = &caps[1];
906906
let classes = &caps[2];
@@ -958,11 +958,12 @@ fn add_playground_pre(
958958
.into_owned()
959959
}
960960

961+
/// Modifies all `<code>` blocks to convert "hidden" lines and to wrap them in
962+
/// a `<span class="boring">`.
961963
fn hide_lines(html: &str, code_config: &Code) -> String {
962-
let regex = Regex::new(r##"((?s)<code[^>]?class="([^"]+)".*?>(.*?)</code>)"##).unwrap();
963964
let language_regex = Regex::new(r"\blanguage-(\w+)\b").unwrap();
964965
let hidelines_regex = Regex::new(r"\bhidelines=(\S+)").unwrap();
965-
regex
966+
CODE_BLOCK_RE
966967
.replace_all(html, |caps: &Captures<'_>| {
967968
let text = &caps[1];
968969
let classes = &caps[2];
@@ -981,13 +982,9 @@ fn hide_lines(html: &str, code_config: &Code) -> String {
981982
Some(capture) => Some(&capture[1]),
982983
None => {
983984
// Then look up the prefix by language
984-
let language_capture = language_regex.captures(classes);
985-
match &language_capture {
986-
Some(capture) => {
987-
code_config.hidelines.get(&capture[1]).map(|p| p.as_str())
988-
}
989-
None => None,
990-
}
985+
language_regex.captures(classes).and_then(|capture| {
986+
code_config.hidelines.get(&capture[1]).map(|p| p.as_str())
987+
})
991988
}
992989
};
993990

0 commit comments

Comments
 (0)