Skip to content

Commit faa2e9e

Browse files
committed
Support text_direction attribute in HTML output
1 parent d5276e7 commit faa2e9e

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/renderer/html_handlebars/hbs_renderer.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,10 @@ fn make_data(
595595
"language".to_owned(),
596596
json!(config.book.language.clone().unwrap_or_default()),
597597
);
598+
data.insert(
599+
"text_direction".to_owned(),
600+
json!(config.book.realized_text_direction()),
601+
);
598602
data.insert(
599603
"book_title".to_owned(),
600604
json!(config.book.title.clone().unwrap_or_default()),
@@ -951,6 +955,8 @@ struct RenderItemContext<'a> {
951955

952956
#[cfg(test)]
953957
mod tests {
958+
use crate::config::TextDirection;
959+
954960
use super::*;
955961

956962
#[test]
@@ -1090,4 +1096,9 @@ mod tests {
10901096
assert_eq!(&*got, *should_be);
10911097
}
10921098
}
1099+
#[test]
1100+
fn test_json_direction() {
1101+
assert_eq!(json!(TextDirection::RightToLeft), json!("rtl"));
1102+
assert_eq!(json!(TextDirection::LeftToRight), json!("ltr"));
1103+
}
10931104
}

src/theme/index.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE HTML>
2-
<html lang="{{ language }}" class="{{ default_theme }}">
2+
<html lang="{{ language }}" class="{{ default_theme }}" dir="{{ text_direction }}">
33
<head>
44
<!-- Book generated using mdBook -->
55
<meta charset="UTF-8">

0 commit comments

Comments
 (0)