From 6524b799795710418cd24236d61c34643c464ed2 Mon Sep 17 00:00:00 2001 From: vrugtehagel Date: Sun, 16 Jun 2024 18:22:32 +0200 Subject: [PATCH] Format README --- README.md | 54 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index bc53c8d..88710c0 100644 --- a/README.md +++ b/README.md @@ -19,44 +19,56 @@ deno add @vrugtehagel/eleventy-document-outline ## Config -In your Eleventy configuration file (usually `.eleventy.js`), import/require the module and add the plugin using `.addPlugin()`: +In your Eleventy configuration file (usually `.eleventy.js`), import/require the +module and add the plugin using `.addPlugin()`: ```js -import EleventyDocumentOutline from 'eleventy-document-outline'; - -export default function(eleventyConfig){ - // … - eleventyConfig.addPlugin(EleventyDocumentOutline, { - headers: ['h1', 'h2', 'h3'], - }); - // … +import EleventyDocumentOutline from "eleventy-document-outline"; + +export default function (eleventyConfig) { + // … + eleventyConfig.addPlugin(EleventyDocumentOutline, { + headers: ["h1", "h2", "h3"], + }); + // … } ``` -As shown above, there are additional options one may pass as second argument to the `.addPlugin()` call, as an object. It may have the following keys: +As shown above, there are additional options one may pass as second argument to +the `.addPlugin()` call, as an object. It may have the following keys: -- `headers`: an array of headers to include in the document outline. By default, this is set to `['h1', 'h2', 'h3']`. Note that this can be overwritten on a case-by-case basis in the `{% outline %}` shortcode. -- `output`: a function receiving a single argument `{ id, text, header }`. The function must return a snippet of HTML to output. By default, this is +- `headers`: an array of headers to include in the document outline. By default, + this is set to `['h1', 'h2', 'h3']`. Note that this can be overwritten on a + case-by-case basis in the `{% outline %}` shortcode. +- `output`: a function receiving a single argument `{ id, text, header }`. The + function must return a snippet of HTML to output. By default, this is ```js -function output({ id, text, header }){ - return `${text}`; +function output({ id, text, header }) { + return `${text}`; } ``` -Which means the options are rendered as sibling anchor tags. The function runs once per header found, in the same order that they are found in the document. The `id` then matches the `id` attribute of the given header, the `header` matches the `.localName` (i.e. lowercased `.tagName`) and the `text` is the text found inside the header. +Which means the options are rendered as sibling anchor tags. The function runs +once per header found, in the same order that they are found in the document. +The `id` then matches the `id` attribute of the given header, the `header` +matches the `.localName` (i.e. lowercased `.tagName`) and the `text` is the text +found inside the header. ## Usage To output the list of links, use the `{% outline %}` shortcode like so: ```liquid - + ``` -In this case, only the `h2` and `h3` elements (with `id` attributes) are included in the outline. If the arguments are left out, as in `{% outline %}`, then the default headers as configured are used (if not explicityly configured, only `h1`, `h2` and `h3` elements are included). +In this case, only the `h2` and `h3` elements (with `id` attributes) are +included in the outline. If the arguments are left out, as in `{% outline %}`, +then the default headers as configured are used (if not explicityly configured, +only `h1`, `h2` and `h3` elements are included). ### Excluding a header @@ -64,4 +76,6 @@ To exclude a header, add a `data-outline-ignore` attribute to it. ### Generating header ids -This plugin does not automatically generate `id` attributes for your headers. If this is something you want or need, use a separate plugin to generate them, such as e.g. [markdown-it-anchor](https://www.npmjs.com/package/markdown-it-anchor). +This plugin does not automatically generate `id` attributes for your headers. If +this is something you want or need, use a separate plugin to generate them, such +as e.g. [markdown-it-anchor](https://www.npmjs.com/package/markdown-it-anchor).