Skip to content

Commit bf3a46c

Browse files
committed
Added support for code highlight themes
1 parent 0a8fc70 commit bf3a46c

File tree

2 files changed

+82
-45
lines changed

2 files changed

+82
-45
lines changed

README.md

+28-4
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,25 @@ Reveal.initialize({
108108
// with the default themes list. Alternatively, provide an
109109
// array to specify the themes to make available in the
110110
// themes menu panel, for example...
111+
//
111112
// [
112-
// { name: 'Black', theme: 'css/theme/black.css' },
113-
// { name: 'White', theme: 'css/theme/white.css' },
114-
// { name: 'League', theme: 'css/theme/league.css' }
113+
// { name: 'Black', theme: 'dist/theme/black.css' },
114+
// { name: 'White', theme: 'dist/theme/white.css' },
115+
// { name: 'League', theme: 'dist/theme/league.css' },
116+
// {
117+
// name: 'Dark',
118+
// theme: 'lib/reveal.js/dist/theme/black.css',
119+
// highlightTheme: 'lib/reveal.js/plugin/highlight/monokai.css'
120+
// },
121+
// {
122+
// name: 'Code: Zenburn',
123+
// highlightTheme: 'lib/reveal.js/plugin/highlight/zenburn.css'
124+
// }
115125
// ]
126+
//
127+
// Note: specifying highlightTheme without a theme will
128+
// change the code highlight theme while leaving the
129+
// presentation theme unchanged.
116130
themes: false,
117131

118132
// Specifies the path to the default theme files. If your
@@ -121,7 +135,7 @@ Reveal.initialize({
121135
// when 'themes' is set to 'true'. If you provide your own
122136
// list of themes or 'themes' is set to 'false' the
123137
// 'themesPath' option is ignored.
124-
themesPath: 'css/theme/',
138+
themesPath: 'dist/theme/',
125139

126140
// Specifies if the transitions menu panel will be shown.
127141
// Set to 'true' to show the transitions menu panel with
@@ -184,6 +198,16 @@ If you are using the themes panel you need to ensure the theme stylesheet in the
184198
<link rel="stylesheet" href="css/theme/black.css" id="theme" />
185199
```
186200

201+
If your themes configuration includes code highlight themes you need to ensure the highlights theme stylesheet in the presentation uses the `id="highlight-theme"` attribute. For example...
202+
203+
```html
204+
<link
205+
rel="stylesheet"
206+
href="plugin/highlight/zenburn.css"
207+
id="highlight-theme"
208+
/>
209+
```
210+
187211
## Slide Titles
188212

189213
The slide titles used in the menu can be supplied explicitly or are taken directly from the presentation, using the following rules...

plugin.js

+54-41
Original file line numberDiff line numberDiff line change
@@ -536,45 +536,40 @@ const Plugin = () => {
536536
var h = parseInt(item.getAttribute('data-slide-h'));
537537
var v = parseInt(item.getAttribute('data-slide-v'));
538538
var theme = item.getAttribute('data-theme');
539+
var highlightTheme = item.getAttribute('data-highlight-theme');
539540
var transition = item.getAttribute('data-transition');
541+
540542
if (!isNaN(h) && !isNaN(v)) {
541543
deck.slide(h, v);
542-
closeMenu();
543-
} else if (theme) {
544-
// take note of the previous theme and remove it, then create a new stylesheet reference and insert it
545-
// this is required to force a load event so we can change the menu style to match the new style
546-
var stylesheet = select('link#theme');
547-
var parent = stylesheet.parentElement;
548-
var sibling = stylesheet.nextElementSibling;
549-
stylesheet.remove();
550-
551-
var newStylesheet = stylesheet.cloneNode();
552-
newStylesheet.setAttribute('href', theme);
553-
newStylesheet.onload = function () {
554-
matchRevealStyle();
555-
};
556-
parent.insertBefore(newStylesheet, sibling);
544+
}
545+
546+
if (theme) {
547+
changeStylesheet('theme', theme);
548+
}
549+
550+
if (highlightTheme) {
551+
changeStylesheet('highlight-theme', highlightTheme);
552+
}
557553

558-
closeMenu();
559-
} else if (transition) {
554+
if (transition) {
560555
deck.configure({ transition: transition });
561-
closeMenu();
562-
} else {
563-
var link = select('a', item);
564-
if (link) {
565-
if (
566-
force ||
567-
!options.sticky ||
568-
(options.autoOpen && link.href.startsWith('#')) ||
569-
link.href.startsWith(
570-
window.location.origin + window.location.pathname + '#'
571-
)
572-
) {
573-
link.click();
574-
}
556+
}
557+
558+
var link = select('a', item);
559+
if (link) {
560+
if (
561+
force ||
562+
!options.sticky ||
563+
(options.autoOpen && link.href.startsWith('#')) ||
564+
link.href.startsWith(
565+
window.location.origin + window.location.pathname + '#'
566+
)
567+
) {
568+
link.click();
575569
}
576-
closeMenu();
577570
}
571+
572+
closeMenu();
578573
}
579574

580575
function clicked(event) {
@@ -950,15 +945,17 @@ const Plugin = () => {
950945
var menu = create('ul', { class: 'slide-menu-items' });
951946
panel.appendChild(menu);
952947
options.themes.forEach(function (t, i) {
953-
var item = create(
954-
'li',
955-
{
956-
class: 'slide-menu-item',
957-
'data-theme': t.theme,
958-
'data-item': '' + (i + 1)
959-
},
960-
t.name
961-
);
948+
var attrs = {
949+
class: 'slide-menu-item',
950+
'data-item': '' + (i + 1)
951+
};
952+
if (t.theme) {
953+
attrs['data-theme'] = t.theme;
954+
}
955+
if (t.highlightTheme) {
956+
attrs['data-highlight-theme'] = t.highlightTheme;
957+
}
958+
var item = create('li', attrs, t.name);
962959
menu.appendChild(item);
963960
item.onclick = clicked;
964961
});
@@ -1136,6 +1133,22 @@ const Plugin = () => {
11361133
return el;
11371134
}
11381135

1136+
function changeStylesheet(id, href) {
1137+
// take note of the previous theme and remove it, then create a new stylesheet reference and insert it
1138+
// this is required to force a load event so we can change the menu style to match the new style
1139+
var stylesheet = select('link#' + id);
1140+
var parent = stylesheet.parentElement;
1141+
var sibling = stylesheet.nextElementSibling;
1142+
stylesheet.remove();
1143+
1144+
var newStylesheet = stylesheet.cloneNode();
1145+
newStylesheet.setAttribute('href', href);
1146+
newStylesheet.onload = function () {
1147+
matchRevealStyle();
1148+
};
1149+
parent.insertBefore(newStylesheet, sibling);
1150+
}
1151+
11391152
// modified from math plugin
11401153
function loadResource(url, type, callback) {
11411154
var head = document.querySelector('head');

0 commit comments

Comments
 (0)