Skip to content

Commit

Permalink
Updates based on review
Browse files Browse the repository at this point in the history
  • Loading branch information
MSzabi committed Oct 4, 2024
1 parent 38c83e3 commit e938e2f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 25 deletions.
53 changes: 34 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,40 @@ Set this property to `false` to disable this plugin.
- `className` (`string`, optional, defaults to `'table-wrapper'`): Class to use for the table wrapper.
</details>

### collapsible_heading

<details>
<summary>Wrap specific headings in detail tag and make the content collapsible</summary>

If an array of heading tags is provided, all those tags and the related content will be wrapped in a details tag, with the heading as the summary.

Nesting multiple collapsible sections is supported.

**Example Markdown input:**

# H1 header
Test row

**Example HTML output:**

<details class="collapsible">
<summary>
<h1>H1 header</h1>
</summary>
<p>Test row</p>
</details>

**Options:**

Pass options for this plugin as the `collapsible_heading` property of the `do-markdownit` plugin options.
This plugin is disabled by default, pass an object to enable it.

- `levels` (`number[]`): List of heading tags to wrap (ex: `2`).
- `open` (`boolean`): Flag indicating if the wrapped sections should be expanded by default.
- `className` (`string`, optional, defaults to `'collapsible'`): Class name to use on the collapsed section.

</details>

### callout

<details>
Expand Down Expand Up @@ -1133,25 +1167,6 @@ Set this property to `false` to disable this plugin.
- `sizeUnits` (`string[]`, optional, defaults to `['', 'px', '%']`): Image size units to allow.
</details>

### collapsible_heading
<details>
<summary>Wrap specific headings in detail tag and make the content collapsible</summary>

If an array of heading tags is provided, all those tags and the related content will be wrapped in a details tag, with the heading as the summary.

Nesting multiple collapsible sections is supported.

**Options:**

Pass options for this plugin as the `collapsible_heading` property of the `do-markdownit` plugin options.
This plugin is disabled by default, pass an object to enable it.

- `levels` (`number[]`): List of heading tags to wrap (ex: `2`).
- `open` (`boolean`): Flag indicating if the wrapped sections should be expanded by default.
- `className` (`string`, optional, defaults to `'collapsible'`): Class name to use on the collapsed section.

</details>

### link_attributes

<details>
Expand Down
2 changes: 1 addition & 1 deletion dev/client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2024 DigitalOcean
Copyright 2023 DigitalOcean
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const safeObject = require('./util/safe_object');
* @property {false|import('./rules/html_comment').HtmlCommentOptions} [html_comment] Disable HTML comment stripping, or set options for the feature.
* @property {false} [image_caption] Disable image captions.
* @property {false|import('./rules/table_wrapper').TableWrapperOptions} [table_wrapper] Disable table wrapper, or set options for the feature.
* @property {import('./modifiers/collapsible_headings').CollapsibleHeadingOptions} [collapsible_headings] Enable transforming headings into collapsible content.
* @property {false|import('./modifiers/collapsible_headings').CollapsibleHeadingOptions} [collapsible_headings] Enable transforming headings into collapsible content.
* @property {false|import('./rules/embeds/callout').CalloutOptions} [callout] Disable callout block syntax, or set options for the feature.
* @property {false|import('./rules/embeds/rsvp_button').RsvpButtonOptions} [rsvp_button] Disable RSVP buttons, or set options for the feature.
* @property {false|import('./rules/embeds/terminal_button').TerminalButtonOptions} [terminal_button] Disable terminal buttons, or set options for the feature.
Expand Down
10 changes: 6 additions & 4 deletions rules/collapsible_heading.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ const safeObject = require('../util/safe_object');
*/

/**
* Add support for collapsing headings.
* Wrap specific headings in detail tag and make the content collapsible
*
* When enabled this plugin wraps the specified headings and the content after in a collapsible section.
* If an array of heading tags is provided, all those tags and the related content will be wrapped in a details tag, with the heading as the summary.
*
* Nesting multiple collapsible sections is supported.
*
* @example
* # H1 header
Expand Down Expand Up @@ -79,7 +81,7 @@ module.exports = (md, options) => {
const openDetails = new state.Token('details', 'details', 1);
openDetails.block = true;
openDetails.attrSet('class', md.utils.escapeHtml(typeof optsObj.className === 'string' ? optsObj.className : 'collapsible'));
if (optsObj.open) openDetails.attrSet('open', '');
if (optsObj.open !== false) openDetails.attrSet('open', '');
newTokens.push(openDetails);

// Create the summary element
Expand Down Expand Up @@ -126,5 +128,5 @@ module.exports = (md, options) => {
});
};

md.core.ruler.push('collapsbile_heading', collapsibleHeading);
md.core.ruler.push('collapsible_heading', collapsibleHeading);
};

0 comments on commit e938e2f

Please sign in to comment.