Skip to content

Commit 3e3d4c4

Browse files
Added an extension to Paragraph to use divs insteap of p tags and introduced a property to the component to toggle the setting
1 parent e38b532 commit 3e3d4c4

File tree

8 files changed

+55
-1
lines changed

8 files changed

+55
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { mergeAttributes } from '@tiptap/core';
2+
import Paragraph from '@tiptap/extension-paragraph';
3+
4+
/** Extension for div tag support
5+
* Replaces the default p tags when typing text to div tags
6+
* Extends the following extension: https://github.com/ueberdosis/tiptap/blob/main/packages/extension-paragraph/src/paragraph.ts
7+
*/
8+
export const DivParagraph = Paragraph.extend({
9+
parseHTML () {
10+
return [{ tag: 'div' }];
11+
},
12+
13+
renderHTML ({ HTMLAttributes }) {
14+
return ['div', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
15+
},
16+
17+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { DivParagraph } from './div';
2+
3+
export default DivParagraph;

packages/dialtone-vue2/components/rich_text_editor/rich_text_editor.stories.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,6 @@ export const WithCustomExtensions = {
156156
allowCode: false,
157157
allowCodeblock: false,
158158
link: false,
159+
useDivTags: false,
159160
},
160161
};

packages/dialtone-vue2/components/rich_text_editor/rich_text_editor.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import History from '@tiptap/extension-history';
7878
import Emoji from './extensions/emoji';
7979
import CustomLink from './extensions/custom_link';
8080
import ConfigurableImage from './extensions/image';
81+
import DivParagraph from './extensions/div';
8182
import { MentionPlugin } from './extensions/mentions/mention';
8283
import { ChannelPlugin } from './extensions/channels/channel';
8384
import { SlashCommandPlugin } from './extensions/slash_command/slash_command';
@@ -367,6 +368,14 @@ export default {
367368
type: Boolean,
368369
default: false,
369370
},
371+
372+
/**
373+
* Show text in HTML div tags instead of paragraph tags
374+
*/
375+
useDivTags: {
376+
type: Boolean,
377+
default: false,
378+
},
370379
},
371380
372381
emits: [
@@ -466,7 +475,8 @@ export default {
466475
// eslint-disable-next-line complexity
467476
extensions () {
468477
// These are the default extensions needed just for plain text.
469-
const extensions = [Document, Paragraph, Text, History, HardBreak];
478+
const extensions = [Document, Text, History, HardBreak];
479+
extensions.push(this.useDivTags ? DivParagraph : Paragraph);
470480
471481
if (this.allowBlockquote) {
472482
extensions.push(Blockquote);

packages/dialtone-vue2/components/rich_text_editor/rich_text_editor_default.story.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
:allow-underline="$attrs.allowUnderline"
2424
:additional-extensions="$attrs.additionalExtensions"
2525
:hide-link-bubble-menu="$attrs.hideLinkBubbleMenu"
26+
:use-div-tags="$attrs.useDivTags"
2627
@blur="$attrs.onBlur"
2728
@input="$attrs.onInput"
2829
@edit-link="$attrs.onEditLink"

packages/dialtone-vue2/recipes/conversation_view/editor/editor.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,5 +597,17 @@ describe('DtRecipeEditor tests', () => {
597597
expect('quick-replies-click' in wrapper.emitted()).toBeTruthy();
598598
});
599599
});
600+
601+
describe('When use div tags is enabled', () => {
602+
beforeEach(async () => {
603+
_mountWrapper();
604+
await wrapper.setProps({ useDivTags: true });
605+
await wrapper.vm.$nextTick();
606+
_setChildWrappers();
607+
});
608+
it('should contain the initial value in div tags', function () {
609+
expect(editor.html()).toContain(`<div>${testText}</div>`);
610+
});
611+
});
600612
});
601613
});

packages/dialtone-vue2/recipes/conversation_view/editor/editor.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
:link="true"
169169
:output-format="htmlOutputFormat"
170170
:placeholder="placeholder"
171+
:use-div-tags="useDivTags"
171172
data-qa="dt-rich-text-editor"
172173
v-bind="$attrs"
173174
@blur="onBlur"
@@ -462,6 +463,14 @@ export default {
462463
setLinkInputAriaLabel: 'Input field to add link',
463464
}),
464465
},
466+
467+
/**
468+
* Use div tags instead of paragraph tags to show text
469+
*/
470+
useDivTags: {
471+
type: Boolean,
472+
default: false,
473+
},
465474
},
466475
467476
emits: [

packages/dialtone-vue2/recipes/conversation_view/editor/editor_default.story.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
:cancel-set-link-button="$attrs.cancelSetLinkButton"
1616
:confirm-set-link-button="$attrs.confirmSetLinkButton"
1717
:remove-link-button="$attrs.removeLinkButton"
18+
:use-div-tags="$attrs.useDivTags"
1819
:show-bold-button="$attrs.showBoldButton"
1920
:show-italics-button="$attrs.showItalicsButton"
2021
:show-strike-button="$attrs.showStrikeButton"

0 commit comments

Comments
 (0)