Skip to content

Commit 7717b9d

Browse files
cN3rdehuss
authored andcommitted
Support text_direction attribute in HTML output
1 parent 819a108 commit 7717b9d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/renderer/html_handlebars/hbs_renderer.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,10 @@ fn make_data(
648648
"language".to_owned(),
649649
json!(config.book.language.clone().unwrap_or_default()),
650650
);
651+
data.insert(
652+
"text_direction".to_owned(),
653+
json!(config.book.realized_text_direction()),
654+
);
651655
data.insert(
652656
"book_title".to_owned(),
653657
json!(config.book.title.clone().unwrap_or_default()),
@@ -1088,6 +1092,8 @@ struct RenderItemContext<'a> {
10881092

10891093
#[cfg(test)]
10901094
mod tests {
1095+
use crate::config::TextDirection;
1096+
10911097
use super::*;
10921098
use pretty_assertions::assert_eq;
10931099

@@ -1299,4 +1305,10 @@ mod tests {
12991305
assert_eq!(&*got, *should_be);
13001306
}
13011307
}
1308+
1309+
#[test]
1310+
fn test_json_direction() {
1311+
assert_eq!(json!(TextDirection::RightToLeft), json!("rtl"));
1312+
assert_eq!(json!(TextDirection::LeftToRight), json!("ltr"));
1313+
}
13021314
}

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)