35 lines
1.0 KiB
JavaScript
Executable File
35 lines
1.0 KiB
JavaScript
Executable File
'use strict';
|
|
|
|
const postFolding = (args, content) => {
|
|
// Parse arguments - support both '::' and ',' as delimiters
|
|
const delimiter = args.join(' ').includes('::') ? '::' : ',';
|
|
const [style, title = ''] = args.join(' ').split(delimiter).map(arg => arg.trim());
|
|
|
|
// Render markdown content
|
|
const renderedContent = hexo.render.renderSync({
|
|
text: content,
|
|
engine: 'markdown'
|
|
}).split('\n').join('');
|
|
|
|
// Replace heading tags with paragraph tags that have heading classes
|
|
const processedContent = renderedContent.replace(
|
|
/<(h[1-6])>/g,
|
|
(_, tag) => `<p class='${tag}'>`
|
|
).replace(
|
|
/<\/(h[1-6])>/g,
|
|
() => '</p>'
|
|
);
|
|
|
|
// Build the HTML with or without custom style
|
|
const styleAttr = style ? ` class="${style}"` : '';
|
|
|
|
return `<details${styleAttr} data-header-exclude>
|
|
<summary><i class="fa-solid fa-chevron-right"></i>${title} </summary>
|
|
<div class='content'>
|
|
${processedContent}
|
|
</div>
|
|
</details>`;
|
|
};
|
|
|
|
hexo.extend.tag.register('folding', postFolding, {ends: true});
|