summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcN3rd <subs.in.tokyo@gmail.com>2021-09-03 18:33:04 +0300
committerEric Huss <eric@huss.org>2023-09-02 07:50:21 -0700
commit7717b9dcf26a1250f859c17101affc9e00c126c0 (patch)
tree502f30665bf073c846065e00e08d0eea43e88f7c
parent819a108f073c84d835407ea0fe1ff322bd1cf238 (diff)
Support `text_direction` attribute in HTML output
-rw-r--r--src/renderer/html_handlebars/hbs_renderer.rs12
-rw-r--r--src/theme/index.hbs2
2 files changed, 13 insertions, 1 deletions
diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs
index 709aa066..8ea2f49e 100644
--- a/src/renderer/html_handlebars/hbs_renderer.rs
+++ b/src/renderer/html_handlebars/hbs_renderer.rs
@@ -649,6 +649,10 @@ fn make_data(
json!(config.book.language.clone().unwrap_or_default()),
);
data.insert(
+ "text_direction".to_owned(),
+ json!(config.book.realized_text_direction()),
+ );
+ data.insert(
"book_title".to_owned(),
json!(config.book.title.clone().unwrap_or_default()),
);
@@ -1088,6 +1092,8 @@ struct RenderItemContext<'a> {
#[cfg(test)]
mod tests {
+ use crate::config::TextDirection;
+
use super::*;
use pretty_assertions::assert_eq;
@@ -1299,4 +1305,10 @@ mod tests {
assert_eq!(&*got, *should_be);
}
}
+
+ #[test]
+ fn test_json_direction() {
+ assert_eq!(json!(TextDirection::RightToLeft), json!("rtl"));
+ assert_eq!(json!(TextDirection::LeftToRight), json!("ltr"));
+ }
}
diff --git a/src/theme/index.hbs b/src/theme/index.hbs
index a3129f2b..61b0e273 100644
--- a/src/theme/index.hbs
+++ b/src/theme/index.hbs
@@ -1,5 +1,5 @@
<!DOCTYPE HTML>
-<html lang="{{ language }}" class="{{ default_theme }}">
+<html lang="{{ language }}" class="{{ default_theme }}" dir="{{ text_direction }}">
<head>
<!-- Book generated using mdBook -->
<meta charset="UTF-8">