Skip to content

Enhanced contrast theme, for users with visual restrictions etc. #1353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ impl HtmlHandlebars {
write_file(destination, "highlight.css", &theme.highlight_css)?;
write_file(destination, "tomorrow-night.css", &theme.tomorrow_night_css)?;
write_file(destination, "ayu-highlight.css", &theme.ayu_highlight_css)?;
write_file(
destination,
"contrast-highlight.css",
&theme.contrast_highlight_css,
)?;
write_file(destination, "highlight.js", &theme.highlight_js)?;
write_file(destination, "clipboard.min.js", &theme.clipboard_js)?;
write_file(
Expand Down
10 changes: 10 additions & 0 deletions src/theme/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ function playground_text(playground) {
var themeColorMetaTag = document.querySelector('meta[name="theme-color"]');
var stylesheets = {
ayuHighlight: document.querySelector("[href$='ayu-highlight.css']"),
contrastHighlight: document.querySelector("[href$='contrast-highlight.css']"),
tomorrowNight: document.querySelector("[href$='tomorrow-night.css']"),
highlight: document.querySelector("[href$='highlight.css']"),
};
Expand Down Expand Up @@ -310,17 +311,26 @@ function playground_text(playground) {
if (theme == 'coal' || theme == 'navy') {
stylesheets.ayuHighlight.disabled = true;
stylesheets.tomorrowNight.disabled = false;
stylesheets.contrastHighlight.disabled = true;
stylesheets.highlight.disabled = true;

ace_theme = "ace/theme/tomorrow_night";
} else if (theme == 'ayu') {
stylesheets.ayuHighlight.disabled = false;
stylesheets.tomorrowNight.disabled = true;
stylesheets.contrastHighlight.disabled = true;
stylesheets.highlight.disabled = true;
ace_theme = "ace/theme/tomorrow_night";
} else if (theme == 'contrast') {
stylesheets.ayuHighlight.disabled = true;
stylesheets.tomorrowNight.disabled = true;
stylesheets.contrastHighlight.disabled = false;
stylesheets.highlight.disabled = true;
ace_theme = "ace/theme/dawn";
} else {
stylesheets.ayuHighlight.disabled = true;
stylesheets.tomorrowNight.disabled = true;
stylesheets.contrastHighlight.disabled = true;
stylesheets.highlight.disabled = false;
ace_theme = "ace/theme/dawn";
}
Expand Down
84 changes: 84 additions & 0 deletions src/theme/contrast-highlight.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* An increased contrast highlighting scheme loosely based on the mdbook
* "light" highlight scheme, itself a subset of Base16 Atelier Dune Light -
* Theme by Bram de Haan
* (http://atelierbram.github.io/syntax-highlighting/atelier-schemes/dune)
* Original Base16 color scheme by Chris Kempson
* (https://github.com/chriskempson/base16)
*/

/* Comment */
.hljs-comment,
.hljs-quote {
color: #575757;
}

/* Red */
.hljs-variable,
.hljs-template-variable,
.hljs-attribute,
.hljs-tag,
.hljs-name,
.hljs-regexp,
.hljs-link,
.hljs-name,
.hljs-selector-id,
.hljs-selector-class {
color: #d70025;
}

/* Dark Orange */
.hljs-number,
.hljs-meta,
.hljs-built_in,
.hljs-builtin-name,
.hljs-literal,
.hljs-type,
.hljs-params {
color: #a61900;
}

/* Green */
.hljs-string,
.hljs-symbol,
.hljs-bullet {
color: #008200;
}

/* Blue */
.hljs-title,
.hljs-section {
color: #0030f2;
}

/* Purple */
.hljs-keyword,
.hljs-selector-tag {
color: #9d00ec;
}

.hljs {
display: block;
overflow-x: auto;
background: #f5f6f6;
color: #000;
padding: 0.5em;
}

.hljs-emphasis {
font-style: italic;
}

.hljs-strong {
font-weight: bold;
}

.hljs-addition {
color: #22863a;
background-color: #f0fff4;
}

.hljs-deletion {
color: #b31d28;
background-color: #ffeef0;
}
40 changes: 40 additions & 0 deletions src/theme/css/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,46 @@
--search-mark-bg: #a2cff5;
}

.contrast {
--bg: hsl(0, 0%, 100%);
--fg: hsl(0, 0%, 0%);

--sidebar-bg: #fafafa;
--sidebar-fg: hsl(0, 0%, 0%);
--sidebar-non-existant: #aaaaaa;
--sidebar-active: #1f1fff;
--sidebar-spacer: #f4f4f4;

--scrollbar: #747474;

--icons: #747474;
--icons-hover: #000000;

--links: #20609f;

--inline-code-color: #3c1900;

--theme-popup-bg: #fafafa;
--theme-popup-border: #cccccc;
--theme-hover: #e6e6e6;

--quote-bg: hsl(197, 37%, 96%);
--quote-border: hsl(197, 37%, 91%);

--table-border-color: hsl(0, 0%, 95%);
--table-header-bg: hsl(0, 0%, 80%);
--table-alternate-bg: hsl(0, 0%, 97%);

--searchbar-border-color: #aaa;
--searchbar-bg: #fafafa;
--searchbar-fg: #000;
--searchbar-shadow-color: #aaa;
--searchresults-header-fg: #666;
--searchresults-border-color: #888;
--searchresults-li-bg: #e4f2fe;
--search-mark-bg: #a2cff5;
}

.navy {
--bg: hsl(226, 23%, 11%);
--fg: #bcbdd0;
Expand Down
2 changes: 2 additions & 0 deletions src/theme/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<link rel="stylesheet" href="{{ path_to_root }}highlight.css">
<link rel="stylesheet" href="{{ path_to_root }}tomorrow-night.css">
<link rel="stylesheet" href="{{ path_to_root }}ayu-highlight.css">
<link rel="stylesheet" href="{{ path_to_root }}contrast-highlight.css">

<!-- Custom theme stylesheets -->
{{#each additional_css}}
Expand Down Expand Up @@ -123,6 +124,7 @@
</button>
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
<li role="none"><button role="menuitem" class="theme" id="light">{{ theme_option "Light" }}</button></li>
<li role="none"><button role="menuitem" class="theme" id="contrast">{{ theme_option "Contrast" }}</button></li>
<li role="none"><button role="menuitem" class="theme" id="rust">{{ theme_option "Rust" }}</button></li>
<li role="none"><button role="menuitem" class="theme" id="coal">{{ theme_option "Coal" }}</button></li>
<li role="none"><button role="menuitem" class="theme" id="navy">{{ theme_option "Navy" }}</button></li>
Expand Down
9 changes: 9 additions & 0 deletions src/theme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub static HIGHLIGHT_JS: &[u8] = include_bytes!("highlight.js");
pub static TOMORROW_NIGHT_CSS: &[u8] = include_bytes!("tomorrow-night.css");
pub static HIGHLIGHT_CSS: &[u8] = include_bytes!("highlight.css");
pub static AYU_HIGHLIGHT_CSS: &[u8] = include_bytes!("ayu-highlight.css");
pub static CONTRAST_HIGHLIGHT_CSS: &[u8] = include_bytes!("contrast-highlight.css");
pub static CLIPBOARD_JS: &[u8] = include_bytes!("clipboard.min.js");
pub static FONT_AWESOME: &[u8] = include_bytes!("FontAwesome/css/font-awesome.min.css");
pub static FONT_AWESOME_EOT: &[u8] = include_bytes!("FontAwesome/fonts/fontawesome-webfont.eot");
Expand Down Expand Up @@ -60,6 +61,7 @@ pub struct Theme {
pub highlight_css: Vec<u8>,
pub tomorrow_night_css: Vec<u8>,
pub ayu_highlight_css: Vec<u8>,
pub contrast_highlight_css: Vec<u8>,
pub highlight_js: Vec<u8>,
pub clipboard_js: Vec<u8>,
}
Expand Down Expand Up @@ -102,6 +104,10 @@ impl Theme {
theme_dir.join("ayu-highlight.css"),
&mut theme.ayu_highlight_css,
),
(
theme_dir.join("contrast-highlight.css"),
&mut theme.contrast_highlight_css,
),
];

let load_with_warn = |filename: &Path, dest| {
Expand Down Expand Up @@ -159,6 +165,7 @@ impl Default for Theme {
highlight_css: HIGHLIGHT_CSS.to_owned(),
tomorrow_night_css: TOMORROW_NIGHT_CSS.to_owned(),
ayu_highlight_css: AYU_HIGHLIGHT_CSS.to_owned(),
contrast_highlight_css: CONTRAST_HIGHLIGHT_CSS.to_owned(),
highlight_js: HIGHLIGHT_JS.to_owned(),
clipboard_js: CLIPBOARD_JS.to_owned(),
}
Expand Down Expand Up @@ -218,6 +225,7 @@ mod tests {
"tomorrow-night.css",
"highlight.css",
"ayu-highlight.css",
"contrast-highlight.css",
"clipboard.min.js",
];

Expand Down Expand Up @@ -246,6 +254,7 @@ mod tests {
highlight_css: Vec::new(),
tomorrow_night_css: Vec::new(),
ayu_highlight_css: Vec::new(),
contrast_highlight_css: Vec::new(),
highlight_js: Vec::new(),
clipboard_js: Vec::new(),
};
Expand Down