47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import { Extension } from '@tiptap/core'
|
|
|
|
/** Préserve dir/lang sur les blocs HTML (contenus clippés persan/arabe). */
|
|
export const RtlPreserveExtension = Extension.create({
|
|
name: 'rtlPreserve',
|
|
addGlobalAttributes() {
|
|
return [
|
|
{
|
|
types: [
|
|
'paragraph',
|
|
'heading',
|
|
'blockquote',
|
|
'listItem',
|
|
'bulletList',
|
|
'orderedList',
|
|
],
|
|
attributes: {
|
|
dir: {
|
|
default: null,
|
|
parseHTML: (element) => element.getAttribute('dir'),
|
|
renderHTML: (attributes) => {
|
|
if (!attributes.dir) return {}
|
|
return { dir: attributes.dir }
|
|
},
|
|
},
|
|
lang: {
|
|
default: null,
|
|
parseHTML: (element) => element.getAttribute('lang'),
|
|
renderHTML: (attributes) => {
|
|
if (!attributes.lang) return {}
|
|
return { lang: attributes.lang }
|
|
},
|
|
},
|
|
class: {
|
|
default: null,
|
|
parseHTML: (element) => element.getAttribute('class'),
|
|
renderHTML: (attributes) => {
|
|
if (!attributes.class) return {}
|
|
return { class: attributes.class }
|
|
},
|
|
},
|
|
},
|
|
},
|
|
]
|
|
},
|
|
})
|