mobilizon/js/src/components/Editor/Autodir.ts
Thomas Citharel a46372094c
Add dir="auto" to most user generated content
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2021-11-07 18:12:22 +01:00

31 lines
658 B
TypeScript

import { Extension } from "@tiptap/core";
/**
* Allows to set dir="auto" on top nodes
* Taken from https://github.com/ueberdosis/tiptap/issues/1621#issuecomment-918990408
*/
export const AutoDir = Extension.create({
name: "AutoDir",
addGlobalAttributes() {
return [
{
types: [
"heading",
"paragraph",
"bulletList",
"orderedList",
"blockquote",
],
attributes: {
autoDir: {
renderHTML: () => ({
dir: "auto",
}),
parseHTML: (element) => element.dir || "auto",
},
},
},
];
},
});