remark-custom-container
Advanced tools
Comparing version 1.3.0 to 1.3.1
import type { Plugin } from "unified"; | ||
export declare const REGEX_BEGIN: RegExp; | ||
export declare const REGEX_END: RegExp; | ||
interface CustomContainerOptions { | ||
export interface CustomContainerOptions { | ||
/** | ||
@@ -13,2 +13,10 @@ * @defaultValue "remark-container" | ||
containerTag?: string; | ||
/** | ||
* @defaultValue {className: string[]} | ||
*/ | ||
titleElement?: Record<string, unknown> | null; | ||
/** | ||
* @defaultValue undefined | ||
*/ | ||
additionalProperties?: (className?: string, title?: string) => Record<string, unknown>; | ||
} | ||
@@ -15,0 +23,0 @@ export declare const plugin: Plugin<[CustomContainerOptions?]>; |
@@ -7,2 +7,4 @@ import { visit } from "unist-util-visit"; | ||
containerTag: "div", | ||
titleElement: {}, | ||
additionalProperties: undefined, | ||
}; | ||
@@ -18,3 +20,7 @@ const isLiteralNode = (node) => { | ||
// Constructs `Parent` node of custom directive which contains given children. | ||
const constructContainer = (children, className) => { | ||
const constructContainer = (children, className, title) => { | ||
let properties; | ||
if (settings.additionalProperties) { | ||
properties = settings.additionalProperties(className, title ?? ""); | ||
} | ||
return { | ||
@@ -27,2 +33,3 @@ type: "container", | ||
className: [settings.className, className.toLowerCase()], | ||
...(properties && { ...properties }), | ||
}, | ||
@@ -38,3 +45,6 @@ }, | ||
hName: "div", | ||
hProperties: { className: [`${settings.className}__title`] }, | ||
hProperties: { | ||
className: [`${settings.className}__title`], | ||
...(settings.titleElement && { ...settings.titleElement }), | ||
}, | ||
}, | ||
@@ -83,6 +93,7 @@ }; | ||
const containerChildren = parent.children.slice(beginIndex + 1, innerIndex); | ||
if (title?.length > 0) { | ||
// if the title exists and the settings.titleElement is not null, then construct the title div element | ||
if (title?.length && settings.titleElement !== null) { | ||
containerChildren.splice(0, 0, constructTitle(title)); | ||
} | ||
const container = constructContainer(containerChildren, type.toLowerCase()); | ||
const container = constructContainer(containerChildren, type.toLowerCase(), title); | ||
children.push(container); | ||
@@ -89,0 +100,0 @@ currentIndex = innerIndex - 1; |
@@ -10,2 +10,4 @@ "use strict"; | ||
containerTag: "div", | ||
titleElement: {}, | ||
additionalProperties: undefined, | ||
}; | ||
@@ -21,3 +23,7 @@ const isLiteralNode = (node) => { | ||
// Constructs `Parent` node of custom directive which contains given children. | ||
const constructContainer = (children, className) => { | ||
const constructContainer = (children, className, title) => { | ||
let properties; | ||
if (settings.additionalProperties) { | ||
properties = settings.additionalProperties(className, title ?? ""); | ||
} | ||
return { | ||
@@ -30,2 +36,3 @@ type: "container", | ||
className: [settings.className, className.toLowerCase()], | ||
...(properties && { ...properties }), | ||
}, | ||
@@ -41,3 +48,6 @@ }, | ||
hName: "div", | ||
hProperties: { className: [`${settings.className}__title`] }, | ||
hProperties: { | ||
className: [`${settings.className}__title`], | ||
...(settings.titleElement && { ...settings.titleElement }), | ||
}, | ||
}, | ||
@@ -86,6 +96,7 @@ }; | ||
const containerChildren = parent.children.slice(beginIndex + 1, innerIndex); | ||
if (title?.length > 0) { | ||
// if the title exists and the settings.titleElement is not null, then construct the title div element | ||
if (title?.length && settings.titleElement !== null) { | ||
containerChildren.splice(0, 0, constructTitle(title)); | ||
} | ||
const container = constructContainer(containerChildren, type.toLowerCase()); | ||
const container = constructContainer(containerChildren, type.toLowerCase(), title); | ||
children.push(container); | ||
@@ -92,0 +103,0 @@ currentIndex = innerIndex - 1; |
{ | ||
"name": "remark-custom-container", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "remark parser plugin for custom directive in markdown", | ||
@@ -5,0 +5,0 @@ "author": "koka831", |
Sorry, the diff of this file is not supported yet
16800
237