Skip to content

Commit

Permalink
Add customize highlight.theme custom path support (#517)
Browse files Browse the repository at this point in the history
* add themeUrl option to support custom theme file path

* Update api-site-config.md
  • Loading branch information
huang-x-h authored and JoelMarcey committed Apr 19, 2018
1 parent 40a9047 commit aa32ff4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
1 change: 1 addition & 0 deletions docs/api-site-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ h1 {
- `version` specifies a particular version of Highlight.js to be used.
- `hljs` provides an escape valve by passing an instance of Highlight.js to the function specified here, allowing additional languages to be registered for syntax highlighting.
- `defaultLang` defines a default language. It will be used if one is not specified at the top of the code block. You can find the [list of supported languages here](https://github.com/isagalaev/highlight.js/tree/master/src/languages).
- `themeUrl` is the custom URL of CSS theme file that you want to use with Highlight.js. If this is provided, the `theme` and `version` fields will be ignored.

`markdownPlugins` - An array of plugins to be loaded by Remarkable, the markdown parser and renderer used by Docusaurus. The plugin will receive a reference to the Remarkable instance, allowing custom parsing and rendering rules to be defined.

Expand Down
20 changes: 11 additions & 9 deletions lib/core/Head.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ class Head extends React.Component {
if (link.blog) hasBlog = true;
});

const highlightDefaultVersion = '9.12.0';
const highlightConfig = this.props.config.highlight || {
version: highlightDefaultVersion,
let highlight = {
version: '9.12.0',
theme: 'default',
...this.props.config.highlight,
};
const highlightVersion = highlightConfig.version || highlightDefaultVersion;
const highlightTheme = highlightConfig.theme || 'default';

// Use user-provided themeUrl if it exists, else construct one from version and theme.
let highlightThemeURL = highlight.themeUrl
? highlight.themeUrl
: `//cdnjs.cloudflare.com/ajax/libs/highlight.js/${
highlight.version
}/styles/${highlight.theme}.min.css`;

return (
<head>
Expand Down Expand Up @@ -73,10 +78,7 @@ class Head extends React.Component {
href="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.css"
/>
)}
<link
rel="stylesheet"
href={`//cdnjs.cloudflare.com/ajax/libs/highlight.js/${highlightVersion}/styles/${highlightTheme}.min.css`}
/>
<link rel="stylesheet" href={highlightThemeURL} />
{hasBlog && (
<link
rel="alternate"
Expand Down
6 changes: 0 additions & 6 deletions lib/core/Site.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ class Site extends React.Component {
(this.props.url || 'index.html');
let docsVersion = this.props.version || 'current';

const highlightDefaultVersion = '9.12.0';
const highlightConfig = this.props.config.highlight || {
version: highlightDefaultVersion,
theme: 'default',
};
const highlightVersion = highlightConfig.version || highlightDefaultVersion;
if (fs.existsSync(CWD + '/versions.json')) {
const latestVersion = require(CWD + '/versions.json')[0];
if (docsVersion === latestVersion) {
Expand Down

0 comments on commit aa32ff4

Please sign in to comment.