Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/nodes
diff options
context:
space:
mode:
authorVinicius Reis <vinicius.reis@nextcloud.com>2022-03-03 23:20:59 +0300
committerVinicius Reis <vinicius.reis@nextcloud.com>2022-03-14 17:38:28 +0300
commitc07bb5078cbf76f1a05e34b851a33904f7a81266 (patch)
treea2836743d81a1bc8a3c5ee877260aee4c84f9478 /src/nodes
parentf484213806fd1425d1c4de40a638ca76658007b8 (diff)
🚧 (2184): custom container tiptap extension
create a tiptap extention to create a custom-container element, missing markdown-it-container Signed-off-by: Vinicius Reis <vinicius.reis@nextcloud.com>
Diffstat (limited to 'src/nodes')
-rw-r--r--src/nodes/CustomContainer.js80
-rw-r--r--src/nodes/index.js2
2 files changed, 82 insertions, 0 deletions
diff --git a/src/nodes/CustomContainer.js b/src/nodes/CustomContainer.js
new file mode 100644
index 000000000..606a6da53
--- /dev/null
+++ b/src/nodes/CustomContainer.js
@@ -0,0 +1,80 @@
+import { Node, mergeAttributes } from '@tiptap/core'
+
+export const inputRegex = /^\s*>\s$/
+
+export default Node.create({
+
+ name: 'customContainer',
+
+ content: 'block+',
+
+ group: 'block',
+
+ defining: true,
+
+ addOptions() {
+ return {
+ types: ['info', 'warn', 'error', 'success'],
+ HTMLAttributes: {
+ class: 'custom-container',
+ },
+ }
+ },
+
+ addAttributes() {
+ return {
+ type: {
+ default: 'info',
+ rendered: false,
+ parseHTML: element => element.getAttribute('data-type'),
+ renderHTML: attributes => {
+ return {
+ 'data-type': attributes.type,
+ class: attributes.type,
+ }
+ },
+ },
+ }
+ },
+
+ parseHTML() {
+ return [
+ {
+ tag: 'div',
+ },
+ ]
+ },
+
+ renderHTML({ node, HTMLAttributes }) {
+ const { class: classy } = this.options.HTMLAttributes
+
+ const attributes = {
+ ...this.options.HTMLAttributes,
+ class: `${classy} ${classy}-${node.attrs.type}`,
+ }
+
+ return ['div', mergeAttributes(attributes, HTMLAttributes), 0]
+ },
+
+ toMarkdown: (state, node) => {
+ state.write('::: info' + (node.attrs.params || '') + '\n')
+ state.text(node.textContent, false)
+ state.ensureNewLine()
+ state.write(':::')
+ state.closeBlock(node)
+ },
+
+ addCommands() {
+ return {
+ setCustomContainer: attributes => ({ commands }) => {
+ return commands.wrapIn(this.name, attributes)
+ },
+ toggleCustomContainer: attributes => ({ commands }) => {
+ return commands.toggleWrap(this.name, attributes)
+ },
+ unsetCustomContainer: () => ({ commands }) => {
+ return commands.lift(this.name)
+ },
+ }
+ },
+})
diff --git a/src/nodes/index.js b/src/nodes/index.js
index 4340f05c9..65feda421 100644
--- a/src/nodes/index.js
+++ b/src/nodes/index.js
@@ -27,6 +27,7 @@ import TaskItem from './TaskItem'
import TaskList from './TaskList'
import TrailingNode from './TrailingNode'
import Heading from './Heading'
+import CustomContainer from './CustomContainer'
export {
Image,
@@ -36,4 +37,5 @@ export {
TaskList,
TrailingNode,
Heading,
+ CustomContainer,
}