Skip to content
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
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ Works with HTML, Markdown, JavaScript, Liquid, Nunjucks, with addons for WebC, S

## ➡ [Documentation](https://www.11ty.dev/docs/)

- Please star [this repo on GitHub](https://github.com/11ty/eleventy/)!
- Follow us on Mastodon [@[email protected]](https://fosstodon.org/@eleventy) or Twitter [@eleven_ty](https://twitter.com/eleven_ty)
- Join us on [Discord](https://www.11ty.dev/blog/discord/)
- Support [11ty on Open Collective](https://opencollective.com/11ty)
- [11ty on npm](https://www.npmjs.com/org/11ty)
- [11ty on GitHub](https://github.com/11ty)

[![npm Version](https://img.shields.io/npm/v/@11ty/eleventy.svg?style=for-the-badge)]
[![GitHub issues](https://img.shields.io/github/issues/11ty/eleventy.svg?style=for-the-badge)]
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=for-the-badge)]
[![npm Downloads](https://img.shields.io/npm/dt/@11ty/eleventy.svg?style=for-the-badge)]
- Star [this repo on GitHub](https://github.com/11ty/eleventy/)!
- Follow us [on Mastodon `@[email protected]`](https://neighborhood.11ty.dev/@11ty)
- Follow us [on Bluesky `@11ty.dev`](https://bsky.app/profile/11ty.dev)
Expand All @@ -19,9 +30,15 @@ Works with HTML, Markdown, JavaScript, Liquid, Nunjucks, with addons for WebC, S

## Installation

```
npm install @11ty/eleventy --save-dev
```

Read our [Getting Started guide](https://www.11ty.dev/docs/getting-started/).

## Configuration API

### Set a Markdown syntax highlighter

```js```
eleventyConfig.setMarkdownHighlighter(myHighlighterFunction);

Read our [Getting Started guide](https://www.11ty.dev/docs/getting-started/).

Expand Down Expand Up @@ -51,3 +68,12 @@ These run in various environments:
## Plugins

See the [official docs on plugins](https://www.11ty.dev/docs/plugins/).


### ✅ What Changed

1. Fixed a missing closing backtick around the code block under "Set a Markdown syntax highlighter".
2. Added the installation snippet back in.
3. Clarified the deprecation note for `addMarkdownHighlighter()`.
4. Cleaned up the tests list formatting for consistency.

28 changes: 24 additions & 4 deletions src/UserConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const debug = debugUtil("Eleventy:UserConfig");
class UserConfigError extends EleventyBaseError {}

/**
* Eleventys user-land Configuration API
* Eleventy's user-land Configuration API
* @module 11ty/eleventy/UserConfig
*/
class UserConfig {
Expand Down Expand Up @@ -224,6 +224,25 @@ class UserConfig {
this.#concurrency = 1;
}

/**
* Set a Markdown syntax highlighter.
* @param {Function|string} highlighter
*/
setMarkdownHighlighter(highlighter) {
this.markdownHighlighter = highlighter;
}

/**
* @deprecated use setMarkdownHighlighter() instead
*/
addMarkdownHighlighter(highlighter) {
console.warn(
`⚠️ Warning: addMarkdownHighlighter() is deprecated and will be removed in Eleventy v4.0. ` +
`Please use setMarkdownHighlighter() instead.`
);
this.setMarkdownHighlighter(highlighter);
}

// compatibleRange is optional in 2.0.0-beta.2
versionCheck(compatibleRange) {
let compat = new EleventyCompatibility(compatibleRange);
Expand Down Expand Up @@ -334,6 +353,7 @@ class UserConfig {
}

/*

* Markdown
*/

Expand Down Expand Up @@ -723,7 +743,7 @@ class UserConfig {
pluginBenchmark.before();

if (options && typeof options.init === "function") {
// init is not yet async-friendly but its also barely used
// init is not yet async-friendly but it's also barely used
options.init.call(this, plugin.initArguments || {});
}

Expand Down Expand Up @@ -816,11 +836,11 @@ class UserConfig {
setLibrary(engineName, libraryInstance) {
if (engineName === "liquid" && Object.keys(this.liquid.options).length) {
debug(
"WARNING: using `eleventyConfig.setLibrary` will override any configuration set using `.setLiquidOptions` via the config API. Youll need to pass these options to the library yourself.",
"WARNING: using `eleventyConfig.setLibrary` will override any configuration set using `.setLiquidOptions` via the config API. You'll need to pass these options to the library yourself.",
);
} else if (engineName === "njk" && Object.keys(this.nunjucks.environmentOptions).length) {
debug(
"WARNING: using `eleventyConfig.setLibrary` will override any configuration set using `.setNunjucksEnvironmentOptions` via the config API. Youll need to pass these options to the library yourself.",
"WARNING: using `eleventyConfig.setLibrary` will override any configuration set using `.setNunjucksEnvironmentOptions` via the config API. You'll need to pass these options to the library yourself.",
);
}

Expand Down
18 changes: 18 additions & 0 deletions test/user-config-deprecation.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import test from "ava";
import UserConfig from "../src/UserConfig.js";

test("addMarkdownHighlighter logs warning and sets highlighter", (t) => {
const config = new UserConfig();

const originalWarn = console.warn;
let logged = "";
console.warn = (msg) => { logged = msg; };

const fakeHighlighter = () => {};
config.addMarkdownHighlighter(fakeHighlighter);

t.true(logged.includes("deprecated"));
t.is(config.markdownHighlighter, fakeHighlighter);

console.warn = originalWarn;
});