diff --git a/app/assets/stylesheets/lexxy-editor.css b/app/assets/stylesheets/lexxy-editor.css
index 8b1f88966..d57288a1f 100644
--- a/app/assets/stylesheets/lexxy-editor.css
+++ b/app/assets/stylesheets/lexxy-editor.css
@@ -479,6 +479,10 @@
display: none;
}
+ &[data-tables="false"] button[name="table"] {
+ display: none;
+ }
+
&[data-upload="file"] button[name="image"] {
display: none;
}
diff --git a/home/docs/configuration.md b/home/docs/configuration.md
index 47797d860..d4cba78fe 100644
--- a/home/docs/configuration.md
+++ b/home/docs/configuration.md
@@ -71,6 +71,7 @@ Editors support the following options, configurable using presets and element at
- `multiLine`: Pass `false` to force single line editing.
- `permittedAttachmentTypes`: Restrict the editor to a specific allowlist of attachment content types. Unset (the default) permits any content type. Example: ``.
- `richText`: Pass `false` to disable rich text editing.
+- `tables`: Pass `false` to disable tables entirely. Table insertion is removed, and any existing `
` markup is reduced to plain text (cell text preserved) when loaded. By default, tables are enabled.
- `headings`: Pass an array of heading tags to configure which heading levels are available in the toolbar dropdown. Defaults to `["h2", "h3", "h4"]`. Pass an empty array to remove all heading options; the formatting dropdown still offers "Normal" and "Clear formatting".
```js
diff --git a/src/config/lexxy.js b/src/config/lexxy.js
index 1056f3669..88f26c849 100644
--- a/src/config/lexxy.js
+++ b/src/config/lexxy.js
@@ -15,6 +15,7 @@ const presets = new Configuration({
multiLine: true,
permittedAttachmentTypes: null,
richText: true,
+ tables: true,
toolbar: {
upload: "both"
},
diff --git a/src/editor/command_dispatcher.js b/src/editor/command_dispatcher.js
index 96f6abc00..54779c880 100644
--- a/src/editor/command_dispatcher.js
+++ b/src/editor/command_dispatcher.js
@@ -285,6 +285,8 @@ export class CommandDispatcher {
}
dispatchInsertTable() {
+ if (!this.editorElement.supportsTables) return
+
this.editor.dispatchCommand(INSERT_TABLE_COMMAND, { "rows": 3, "columns": 3, "includeHeaders": true })
}
diff --git a/src/elements/editor.js b/src/elements/editor.js
index 69a1aa05e..e5decc367 100644
--- a/src/elements/editor.js
+++ b/src/elements/editor.js
@@ -279,6 +279,10 @@ export class LexicalEditorElement extends HTMLElement {
return this.config.get("richText")
}
+ get supportsTables() {
+ return this.supportsRichText && this.config.get("tables")
+ }
+
registerAdapter(adapter) {
this.adapter = adapter
@@ -604,7 +608,7 @@ export class LexicalEditorElement extends HTMLElement {
registerRichText(this.editor),
registerList(this.editor)
)
- this.#registerTableComponents()
+ if (this.supportsTables) this.#registerTableComponents()
this.#registerCodeLanguagePicker()
if (this.supportsMarkdown) {
const transformers = [ ...TRANSFORMERS, HORIZONTAL_DIVIDER ]
@@ -743,6 +747,7 @@ export class LexicalEditorElement extends HTMLElement {
const toolbar = createElement("lexxy-toolbar")
toolbar.innerHTML = LexicalToolbar.defaultTemplate
toolbar.setAttribute("data-attachments", this.supportsAttachments) // Drives toolbar CSS styles
+ toolbar.setAttribute("data-tables", this.supportsTables) // Drives toolbar CSS styles
toolbar.configure(this.config.get("toolbar"))
this.prepend(toolbar)
return toolbar
diff --git a/src/extensions/tables_extension.js b/src/extensions/tables_extension.js
index 076f27566..f4128bc01 100644
--- a/src/extensions/tables_extension.js
+++ b/src/extensions/tables_extension.js
@@ -21,7 +21,7 @@ import { mergeRegister } from "@lexical/utils"
export class TablesExtension extends LexxyExtension {
get enabled() {
- return this.editorElement.supportsRichText
+ return this.editorElement.supportsTables
}
get allowedElements() {
diff --git a/test/browser/fixtures/tables-false.html b/test/browser/fixtures/tables-false.html
new file mode 100644
index 000000000..b1e973fb3
--- /dev/null
+++ b/test/browser/fixtures/tables-false.html
@@ -0,0 +1,24 @@
+
+
+
+
+
+ Lexxy Test — Tables Disabled
+
+
+
+
+
+
+
+
diff --git a/test/browser/tests/tables/disabled.test.js b/test/browser/tests/tables/disabled.test.js
new file mode 100644
index 000000000..bc8368378
--- /dev/null
+++ b/test/browser/tests/tables/disabled.test.js
@@ -0,0 +1,73 @@
+import { test } from "../../test_helper.js"
+import { expect } from "@playwright/test"
+import { startMonitoringConsole } from "../../helpers/assertions.js"
+
+const TABLE_HTML =
+ '