Skip to content

Add configurable highlight support - #2

Open
shved270189 wants to merge 1 commit into
mainfrom
configurable-highlight
Open

Add configurable highlight support#2
shved270189 wants to merge 1 commit into
mainfrom
configurable-highlight

Conversation

@shved270189

Copy link
Copy Markdown
Collaborator

What

Make color highlighting disablable via Lexxy.configure or a highlight element 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.

// all editors
Lexxy.configure({ default: { highlight: { enabled: false } } })

// or per editor
<lexxy-editor highlight='{"enabled":false}'></lexxy-editor>

Both the object form ({ enabled: false }) and a bare highlight: false are accepted.

How it works when disabled

  • HighlightExtension is not registered — the toggle/remove commands, the <mark> import converter, and the paste canonicalizers are all absent.
  • The toolbar highlight dropdown is hidden via a data-highlight attribute + CSS (mirroring data-attachments), and the dropdown setup is guarded.
  • Highlight markup is reduced to plain text on import, across both representations:
    • <mark> — the conversion is dropped from editor._htmlConversions.
    • legacy Trix styled elements (<em> / <strong> / <span> / <del> carrying color) — the bold/italic/strikethrough formatting is kept, only the highlight color is stripped.
  • #resolvedHighlightColors and the highlight selection-state flag report nothing/false when disabled, so host adapters don't surface a dead control.

Testing

  • Playwright (test/browser/tests/formatting/highlight_disabled.test.js + fixtures): dropdown hidden, toggleHighlight inert, <mark> and Trix styled-element highlights stripped (formats preserved), bare highlight="false" disables without crashing, no console errors. Default behavior covered by a regression baseline.
  • System (test/system/highlight_disabled_test.rb): Action Text round-trip (load → strip → save → render → re-edit) for both <mark> and Trix-styled highlights.
  • Full yarn test:browser (chromium/firefox/webkit) green; yarn lint clean; existing color_highlighter / trix_html (the enabled path) still pass.

@shved270189
shved270189 requested a review from Copilot June 10, 2026 14:43
@shved270189
shved270189 marked this pull request as ready for review June 10, 2026 14:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 supportsHighlight and 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.

Comment thread src/elements/editor.js
Comment on lines 781 to 783
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 },

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread docs/configuration.md Outdated
- `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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — documented the bare false shorthand alongside { enabled: false }.

Comment thread docs/highlighting.md
Comment on lines +38 to +48
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>`.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — added a note that the scalar form (highlight: false in a preset, or highlight="false" as an attribute) is also accepted.

@shved270189
shved270189 force-pushed the configurable-highlight branch from 4296248 to 33dbd64 Compare June 10, 2026 15:18
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants