Skip to content
Snippets Groups Projects
Commit 18069bd1 authored by rhenck's avatar rhenck
Browse files

[editor] Fix TextEditor fontSize extension

Was broken after previous refactoring.
The renderHTML method only works with a proper return. Don't know why. 
Therefore disregard the linter warning for now.
parent 83c8c404
No related branches found
No related tags found
No related merge requests found
import { Command } from '@tiptap/core'; import { Extension } from '@tiptap/core';
import { TextStyle } from '@tiptap/extension-text-style'; import '@tiptap/extension-text-style';
declare module '@tiptap/core' { declare module '@tiptap/core' {
interface Commands<> { interface Commands<ReturnType> {
fontSizeExtension: { fontSize: {
setFontSize: (fontSize: string) => Command setFontSize: (fontSize: string) => ReturnType
}; };
} }
} }
export const FontSizeExtension = TextStyle.extend({ export const FontSize = Extension.create({
name: 'FontSizeExtension', name: 'fontSize',
addAttributes() { addOptions() {
return { return {
fontSize: { types: ['textStyle']
default: '20px',
parseHTML: element => element.style.fontSize,
renderHTML: attributes => ({
style: `font-size: ${attributes.fontSize}`
})
}
}; };
}, },
addGlobalAttributes() {
return [{
types: this.options.types,
attributes: {
fontSize: {
default: '20px',
parseHTML: element => element.style.fontSize,
renderHTML: attributes => {
return { style: `font-size: ${attributes.fontSize}` };
}
}
}
}];
},
addCommands() { addCommands() {
return { return {
setFontSize: fontSize => ({ chain }) => chain().setMark('textStyle', { fontSize }).run() setFontSize: fontSize => ({ chain }) => chain().setMark('textStyle', { fontSize }).run()
......
...@@ -17,7 +17,7 @@ import { Blockquote } from '@tiptap/extension-blockquote'; ...@@ -17,7 +17,7 @@ import { Blockquote } from '@tiptap/extension-blockquote';
import { Indent } from './extensions/indent'; import { Indent } from './extensions/indent';
import { HangingIndent } from './extensions/hanging-indent'; import { HangingIndent } from './extensions/hanging-indent';
import { ParagraphExtension } from './extensions/paragraph-extension'; import { ParagraphExtension } from './extensions/paragraph-extension';
import { FontSizeExtension } from './extensions/font-size'; import { FontSize } from './extensions/font-size';
import { BulletListExtension } from './extensions/bullet-list'; import { BulletListExtension } from './extensions/bullet-list';
import { OrderedListExtension } from './extensions/orderedList-extension'; import { OrderedListExtension } from './extensions/orderedList-extension';
...@@ -65,7 +65,7 @@ export class RichTextEditorComponent implements AfterViewInit { ...@@ -65,7 +65,7 @@ export class RichTextEditorComponent implements AfterViewInit {
levels: [1, 2, 3, 4] levels: [1, 2, 3, 4]
}), }),
ParagraphExtension, ParagraphExtension,
FontSizeExtension, FontSize,
BulletListExtension, BulletListExtension,
OrderedListExtension, OrderedListExtension,
HangingIndent, HangingIndent,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment