diff options
author | Vinicius Reis <vinicius.reis@nextcloud.com> | 2022-03-10 01:06:59 +0300 |
---|---|---|
committer | Vinicius Reis <vinicius.reis@nextcloud.com> | 2022-03-14 17:38:28 +0300 |
commit | 0bc2bbbc5e7989eb3f0ceba702255c552dbdac47 (patch) | |
tree | a084ef3597498c53e068e446dd61560170dac9e9 /src | |
parent | e1863ef939b01a22e3efcfd908e8339dbdbf36ea (diff) |
🚚 (#2184): use callout instead of callout-container
Signed-off-by: Vinicius Reis <vinicius.reis@nextcloud.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/EditorFactory.js | 4 | ||||
-rw-r--r-- | src/markdownit/callouts.js (renamed from src/markdownit/containers.js) | 4 | ||||
-rw-r--r-- | src/markdownit/index.js | 4 | ||||
-rw-r--r-- | src/mixins/menubar.js | 16 | ||||
-rw-r--r-- | src/nodes/Callouts.js (renamed from src/nodes/CalloutsContainer.js) | 18 | ||||
-rw-r--r-- | src/nodes/index.js | 4 | ||||
-rw-r--r-- | src/tests/markdownit.spec.js | 6 |
7 files changed, 28 insertions, 28 deletions
diff --git a/src/EditorFactory.js b/src/EditorFactory.js index 9dbdc8f69..ee31c96bf 100644 --- a/src/EditorFactory.js +++ b/src/EditorFactory.js @@ -44,7 +44,7 @@ import { BulletList, TaskList, TaskItem, - CalloutContainer, + Callout, } from './nodes' import { Markdown, Emoji } from './extensions' import { translate as t } from '@nextcloud/l10n' @@ -90,7 +90,7 @@ const createEditor = ({ content, onCreate, onUpdate, extensions, enableRichEditi ListItem, TaskList, TaskItem, - CalloutContainer, + Callout, Underline, Image.configure({ currentDirectory, inline: true }), Emoji.configure({ diff --git a/src/markdownit/containers.js b/src/markdownit/callouts.js index 0e64f62c4..0eb3423b5 100644 --- a/src/markdownit/containers.js +++ b/src/markdownit/callouts.js @@ -30,7 +30,7 @@ const buildRender = type => (tokens, idx, options, env, slf) => { // add attributes to the opening tag if (tag.nesting === 1) { tag.attrSet('data-callout', type) - tag.attrJoin('class', `callout-container callout-container-${type}`) + tag.attrJoin('class', `callout callout-${type}`) } return slf.renderToken(tokens, idx, options, env, slf) @@ -40,7 +40,7 @@ const buildRender = type => (tokens, idx, options, env, slf) => { * @param {object} md Markdown object */ export default (md) => { - // create a custom container to each type + // create a custom container to each callout type typesAvailable.forEach(type => { md.use(container, type, { render: buildRender(type), diff --git a/src/markdownit/index.js b/src/markdownit/index.js index 3143f8453..5c8d35b14 100644 --- a/src/markdownit/index.js +++ b/src/markdownit/index.js @@ -2,13 +2,13 @@ import MarkdownIt from 'markdown-it' import taskLists from 'markdown-it-task-lists' import underline from './underline' import splitMixedLists from './splitMixedLists' -import containers from './containers' +import callouts from './callouts' const markdownit = MarkdownIt('commonmark', { html: false, breaks: false }) .enable('strikethrough') .use(taskLists, { enable: true, labelAfter: true }) .use(splitMixedLists) .use(underline) - .use(containers) + .use(callouts) export default markdownit diff --git a/src/mixins/menubar.js b/src/mixins/menubar.js index e4697b1ba..6dcd9f59b 100644 --- a/src/mixins/menubar.js +++ b/src/mixins/menubar.js @@ -174,33 +174,33 @@ export default [ { label: t('text', 'Info'), class: 'icon-info', - isActive: ['calloutContainer', { type: 'info' }], + isActive: ['callout', { type: 'info' }], action: (command) => { - return command.toggleCalloutCustomContainer({ type: 'info' }) + return command.toggleCallout({ type: 'info' }) }, }, { label: t('text', 'Success'), class: 'icon-success', - isActive: ['calloutContainer', { type: 'success' }], + isActive: ['callout', { type: 'success' }], action: (command) => { - return command.toggleCalloutCustomContainer({ type: 'success' }) + return command.toggleCallout({ type: 'success' }) }, }, { label: t('text', 'Warning'), class: 'icon-warn', - isActive: ['calloutContainer', { type: 'warn' }], + isActive: ['callout', { type: 'warn' }], action: (command) => { - return command.toggleCalloutCustomContainer({ type: 'warn' }) + return command.toggleCallout({ type: 'warn' }) }, }, { label: t('text', 'Error'), class: 'icon-error', - isActive: ['calloutContainer', { type: 'error' }], + isActive: ['callout', { type: 'error' }], action: (command) => { - return command.toggleCalloutCustomContainer({ type: 'error' }) + return command.toggleCallout({ type: 'error' }) }, }, ], diff --git a/src/nodes/CalloutsContainer.js b/src/nodes/Callouts.js index 47374b7f9..afc68b0e2 100644 --- a/src/nodes/CalloutsContainer.js +++ b/src/nodes/Callouts.js @@ -21,11 +21,11 @@ */ import { Node, mergeAttributes, isNodeActive } from '@tiptap/core' -import { typesAvailable } from '../markdownit/containers' +import { typesAvailable } from '../markdownit/callouts' export default Node.create({ - name: 'calloutContainer', + name: 'callout', content: 'paragraph+', @@ -37,7 +37,7 @@ export default Node.create({ return { types: typesAvailable, HTMLAttributes: { - class: 'callout-container', + class: 'callout', }, } }, @@ -51,7 +51,7 @@ export default Node.create({ renderHTML: attributes => { return { 'data-callout': attributes.type, - class: `callout-container-${attributes.type}`, + class: `callout-${attributes.type}`, } }, }, @@ -87,21 +87,21 @@ export default Node.create({ addCommands() { return { - setCalloutCustomContainer: attributes => ({ commands }) => { + setCallout: attributes => ({ commands }) => { return commands.wrapIn(this.name, attributes) }, - toggleCalloutCustomContainer: attributes => ({ commands, state }) => { + toggleCallout: attributes => ({ commands, state }) => { if (!isNodeActive(state, this.name)) { - return commands.setCalloutCustomContainer(attributes) + return commands.setCallout(attributes) } if (!isNodeActive(state, this.name, attributes)) { return commands.updateAttributes(this.name, attributes) } - return commands.unsetCalloutCustomContainer() + return commands.unsetCallout() }, - unsetCalloutCustomContainer: () => ({ commands }) => { + unsetCallout: () => ({ commands }) => { return commands.lift(this.name) }, } diff --git a/src/nodes/index.js b/src/nodes/index.js index 89ad98c26..0f8e70a43 100644 --- a/src/nodes/index.js +++ b/src/nodes/index.js @@ -27,7 +27,7 @@ import TaskItem from './TaskItem' import TaskList from './TaskList' import TrailingNode from './TrailingNode' import Heading from './Heading' -import CalloutContainer from './CalloutsContainer' +import Callout from './Callouts' export { Image, @@ -37,5 +37,5 @@ export { TaskList, TrailingNode, Heading, - CalloutContainer, + Callout, } diff --git a/src/tests/markdownit.spec.js b/src/tests/markdownit.spec.js index 3b0938b0b..69ce3673d 100644 --- a/src/tests/markdownit.spec.js +++ b/src/tests/markdownit.spec.js @@ -1,5 +1,5 @@ import markdownit from './../markdownit' -import { typesAvailable } from './../markdownit/containers' +import { typesAvailable } from '../markdownit/callouts' describe('markdownit', () => { @@ -27,12 +27,12 @@ describe('markdownit', () => { `)) }) - describe('callout containers', () => { + describe('callouts', () => { typesAvailable.forEach((type) => { it(`render ${type}`, () => { const rendered = markdownit.render(`::: ${type}\nHey there!\n:::`) expect(stripIndent(rendered)).toBe(stripIndent( - `<div data-callout="${type}" class="callout-container callout-container-${type}"> + `<div data-callout="${type}" class="callout callout-${type}"> <p>Hey there!</p> </div>` )) |