From 54d6b790dc6b5da189541d99fd4cf2075d624212 Mon Sep 17 00:00:00 2001 From: Vinicius Reis Date: Fri, 4 Mar 2022 11:21:16 -0300 Subject: =?UTF-8?q?=F0=9F=93=84=20(2184):=20add=20missing=20comments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Vinicius Reis --- src/markdownit/containers.js | 28 +++++++++++++++++++++++++++- src/nodes/CustomContainer.js | 22 ++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/markdownit/containers.js b/src/markdownit/containers.js index 1196f9b8e..9cdc3dc7e 100644 --- a/src/markdownit/containers.js +++ b/src/markdownit/containers.js @@ -1,11 +1,33 @@ +/* + * @copyright Copyright (c) 2022 Vinicius Reis + * + * @author Vinicius Reis + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + import container from 'markdown-it-container' export const typesAvailable = ['info', 'warn', 'error', 'success'] const buildRender = type => (tokens, idx, options, env, slf) => { - // add a class to the opening tag const tag = tokens[idx] + // add attributes to the opening tag if (tag.nesting === 1) { tag.attrSet('data-container', type) tag.attrJoin('class', `custom-container custom-container-${type}`) @@ -14,7 +36,11 @@ const buildRender = type => (tokens, idx, options, env, slf) => { return slf.renderToken(tokens, idx, options, env, slf) } +/** + * @param {object} md Markdown object + */ export default (md) => { + // create a custom container to each type typesAvailable.forEach(type => { md.use(container, type, { render: buildRender(type), diff --git a/src/nodes/CustomContainer.js b/src/nodes/CustomContainer.js index a1ebd391b..920c075e4 100644 --- a/src/nodes/CustomContainer.js +++ b/src/nodes/CustomContainer.js @@ -1,3 +1,25 @@ +/* + * @copyright Copyright (c) 2022 Vinicius Reis + * + * @author Vinicius Reis + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + import { Node, mergeAttributes } from '@tiptap/core' import { typesAvailable } from '../markdownit/containers' -- cgit v1.2.3