Add configurable highlight support - #2
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a configuration-controlled toggle for color highlighting (globally via Lexxy.configure and per-editor via the highlight attribute), keeping default behavior unchanged while disabling highlight-related UI, commands, and HTML import behavior when turned off.
Changes:
- Introduces
supportsHighlightand wires it through extensions, toolbar UI, and selection-state reporting. - Drops highlight-related HTML import/conversion paths when disabled (notably
<mark>and legacy Trix styled-element highlight colors). - Adds Playwright + system tests and fixture pages to validate “highlight disabled” behavior and round-trip stripping.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/elements/editor.js |
Adds supportsHighlight, hides toolbar control via data-highlight, removes <mark> import conversion when disabled, and gates highlight state/colors. |
src/extensions/highlight_extension.js |
Enables the highlight extension only when supportsHighlight is true. |
src/extensions/trix_content_extension.js |
Ensances legacy Trix highlight-style import to no-op when highlight is disabled (preserving basic formats). |
src/elements/dropdown/highlight.js |
Guards dropdown setup when highlight is disabled and handles missing button config. |
src/config/lexxy.js |
Adds highlight.enabled: true default to make the toggle explicit. |
app/assets/stylesheets/lexxy-editor.css |
Hides the highlight dropdown when data-highlight="false" is present. |
docs/highlighting.md |
Documents how to disable highlighting. |
docs/configuration.md |
Documents the new highlight editor option. |
test/browser/tests/formatting/highlight_disabled.test.js |
Adds Playwright coverage for disabled highlight behavior. |
test/browser/fixtures/highlight-false.html |
Fixture page with highlight disabled via JSON attribute. |
test/browser/fixtures/highlight-false-bare.html |
Fixture page with highlight disabled via highlight="false". |
test/system/highlight_disabled_test.rb |
Adds system test ensuring highlight is stripped and round-trips in Action Text. |
test/dummy/app/views/posts/_form.html.erb |
Adds a dummy-app parameter switch to set highlight='{"enabled":false}'. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| code: { active: format.isInCode, enabled: true }, | ||
| highlight: { active: format.isHighlight, enabled: true }, | ||
| highlight: { active: format.isHighlight, enabled: this.supportsHighlight }, | ||
| link: { active: format.isInLink, enabled: true }, |
There was a problem hiding this comment.
Good catch — done. Gated both active and the separate highlight detail on supportsHighlight (not just enabled), so a disabled editor reports no highlight selection state to adapters regardless of any pre-existing or injected format.
| - `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: `<lexxy-editor permitted-attachment-types="application/vnd.basecamp.mention application/vnd.basecamp.opengraph-embed"></lexxy-editor>`. | ||
| - `richText`: Pass `false` to disable rich text editing. | ||
| - `highlight`: Color highlighting configuration. Pass `{ enabled: false }` to disable highlighting entirely (it is enabled by default). See [Highlighting](highlighting.md) for configuring the available colors. |
There was a problem hiding this comment.
Done — documented the bare false shorthand alongside { enabled: false }.
| Pass `highlight.enabled: false` to disable color highlighting entirely. The toolbar control is hidden, the commands become inert, and existing highlight markup is reduced to plain text on load. | ||
|
|
||
| ```javascript | ||
| Lexxy.configure({ | ||
| default: { | ||
| highlight: { enabled: false } | ||
| } | ||
| }) | ||
| ``` | ||
|
|
||
| Or per editor: `<lexxy-editor highlight='{"enabled":false}'></lexxy-editor>`. |
There was a problem hiding this comment.
Done — added a note that the scalar form (highlight: false in a preset, or highlight="false" as an attribute) is also accepted.
4296248 to
33dbd64
Compare
Make color highlighting disablable via Lexxy.configure (highlight: { enabled: false }) or a highlight element attribute. The default stays enabled, preserving current behavior. Both the object form { enabled: false } and a bare highlight: false are accepted.
When disabled: the HighlightExtension (toggle/remove commands, the <mark> import converter, paste canonicalizers) is not registered, the toolbar highlight dropdown is hidden via a data-highlight attribute, the dropdown setup is guarded, and highlight markup is reduced to plain text on import — both <mark> (by dropping the conversion) and legacy Trix styled elements (em/strong/span/del keep their bold/italic/strikethrough but lose the highlight color).
33dbd64 to
a84ca24
Compare
What
Make color highlighting disablable via
Lexxy.configureor ahighlightelement attribute. The default is enabled, so current behavior is unchanged. Part of the per-feature configurability effort (see basecamp#1097); held from upstream until the shape is confirmed there.Both the object form (
{ enabled: false }) and a barehighlight: falseare accepted.How it works when disabled
HighlightExtensionis not registered — the toggle/remove commands, the<mark>import converter, and the paste canonicalizers are all absent.data-highlightattribute + CSS (mirroringdata-attachments), and the dropdown setup is guarded.<mark>— the conversion is dropped fromeditor._htmlConversions.<em>/<strong>/<span>/<del>carrying color) — the bold/italic/strikethrough formatting is kept, only the highlight color is stripped.#resolvedHighlightColorsand thehighlightselection-state flag report nothing/false when disabled, so host adapters don't surface a dead control.Testing
test/browser/tests/formatting/highlight_disabled.test.js+ fixtures): dropdown hidden,toggleHighlightinert,<mark>and Trix styled-element highlights stripped (formats preserved), barehighlight="false"disables without crashing, no console errors. Default behavior covered by a regression baseline.test/system/highlight_disabled_test.rb): Action Text round-trip (load → strip → save → render → re-edit) for both<mark>and Trix-styled highlights.yarn test:browser(chromium/firefox/webkit) green;yarn lintclean; existingcolor_highlighter/trix_html(the enabled path) still pass.