/**
 * @license Copyright (c) 2017-2025, CKSource Holding sp. z o.o. All rights reserved.
 * For licensing, see LICENSE.md.
 */

'use strict';

const {
	transformMarkdownAdmonitions,
	fastCheckIfContainsAdmonition
} = require( '../../../utils/transform-markdown-admonitions' );

/**
 * Make sure it's executed after `execute-and-insert-function-results.js` filter.
 */
hexo.extend.filter.register( 'before_post_render', page => {
	if ( page.projectTheme !== 'gloria' || !page.content || !fastCheckIfContainsAdmonition( page.content ) ) {
		return page;
	}

	const renderedAdmonition = ( { type, content } ) =>
		`<info-box ${ type.toLowerCase() }>\n${ content.join( '\n' ) }\n</info-box>`;

	page.content = transformMarkdownAdmonitions( renderedAdmonition, page.content );

	return page;
}, 7 );
