Skip to content

Commit

Permalink
Improve highlight styles support
Browse files Browse the repository at this point in the history
Closes #6
  • Loading branch information
GaelGirodon committed Sep 27, 2022
1 parent 72d066f commit b11de49
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ to add a style to code blocks.

The `--highlight-style` option can receive the name of a
[Hightlight.js style](https://github.com/highlightjs/highlight.js/tree/master/src/styles)
(file name without extension, e.g. `solarized-dark`) or the path to a custom
style file (a local path or a HTTP URL).
(file name without extension, e.g. `monokai`) or the path to a custom style
file (a local path or a HTTP URL).

#### Additional features

Expand Down
2 changes: 1 addition & 1 deletion src/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class Style {
async loadHighlightStyle(style) {
// Predefined highlight style
let stylePath = paths.join(HLJS_STYLES_PATH, style + ".css");
if (!/^[\w-]+$/.test(style) || !(await files.isReadable(stylePath))) {
if (!/^(\w+\/)?[\w-]+$/.test(style) || !(await files.isReadable(stylePath))) {
// Custom highlight style
stylePath = await this.validate(style, style, "highlight style");
}
Expand Down
16 changes: 16 additions & 0 deletions test/processor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@ describe("Processor", () => {
});
});

describe('mdtodoc doc.md -l "page" -t "github" --highlight-style "base16/solarized-dark"', () => {
it("should use a highlight style from the base16 folder", async () => {
const proc = new Processor({
layout: "page",
theme: "github",
highlightStyle: "base16/solarized-dark",
});
const src = buildDataPath("README.md");
const dst = buildDataPath("README.html");
await proc.process([src]);
assert.isTrue(await files.exists(dst));
const html = await files.readAllText(dst);
assert.include(html, "background:#002b36");
});
});

describe('mdtodoc doc.md -l "page" -t "github" -s "atom-one-light" --numbered-headings --code-copy --mermaid', () => {
it("should enable additional extensions", async () => {
const proc = new Processor({
Expand Down

0 comments on commit b11de49

Please sign in to comment.