Skip to content

Fix text starting with numbers cut off in preview#14385

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/fix-text-cutoff-in-preview
Closed

Fix text starting with numbers cut off in preview#14385
Copilot wants to merge 2 commits intomainfrom
copilot/fix-text-cutoff-in-preview

Conversation

Copy link

Copilot AI commented Oct 25, 2025

Text starting with numbered list patterns (e.g., "1. hello", "2. world") was being stripped in DisplayText preview mode, showing only "hello" and "world".

Root Cause

sanitizeEditorHtml uses draftjs-filters's filterEditorState which applies default block text rules that:

  1. Detect patterns like ^1{0,1}\d\.[ \t] as ordered list markers
  2. Convert matching blocks to ordered-list-item type
  3. Strip the matched prefix from text

With blocks: [] in the filter config, these converted blocks are then filtered out, but the text has already lost the number prefix.

Changes

  • packages/rich-text/src/htmlManipulation.ts: Disable automatic list detection by passing blockTextRules: [] to filterEditorState
  • packages/rich-text/src/test/sanitizeEditorHtml.ts: Add test coverage for numbered text preservation
  filterEditorState(
    {
      blocks: [],
      styles,
      entities: [],
      maxNesting: 1,
      whitespacedCharacters: [],
+     blockTextRules: [],
    },
    editorState
  )

Fixes #14092

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.ampproject.org
    • Triggering command: curl --output-dir -O -f REDACTED (dns block)
  • googlechromelabs.github.io
  • https://storage.googleapis.com/chrome-for-testing-public/141.0.7390.54/linux64/chrome-headless-shell-linux64.zip
    • Triggering command: node install.mjs (http block)
  • https://storage.googleapis.com/chrome-for-testing-public/141.0.7390.54/linux64/chrome-linux64.zip

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Text starting with numbers cut off in preview</issue_title>
<issue_description>

Bug Description

See https://wordpress.org/support/topic/text-starting-with-a-number-and-dot-e-g-1-storm-gets-cut-in-preview/

This looks like a result of #13858

Expected Behaviour

Steps to Reproduce

Write something like

1. hello
2. world

and then exit edit mode.

The numbers disappear in the <DisplayText> component.

Screenshots

Additional Context

  • Plugin Version: 1.40.0
  • WordPress Version: 6.7
  • Operating System:
  • Browser:
    </issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@google-cla
Copy link

google-cla bot commented Oct 25, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

The issue was caused by `sanitizeEditorHtml` using `filterEditorState` from
`draftjs-filters` library with default block text rules. These rules
automatically detect text patterns like "1. hello" and convert them to
ordered-list-item blocks, stripping the prefix in the process.

Since the filter configuration has `blocks: []`, these list blocks are then
filtered out, but the text has already been stripped of the numbers.

The fix is to explicitly disable block text rules by passing an empty array
`blockTextRules: []` to `filterEditorState`, which prevents the automatic
list detection and preserves the original text content.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix text starting with numbers cut off in preview Fix text starting with numbers cut off in preview Oct 25, 2025
Copilot AI requested a review from swissspidy October 25, 2025 00:29
@swissspidy swissspidy closed this Oct 25, 2025
@swissspidy swissspidy deleted the copilot/fix-text-cutoff-in-preview branch October 31, 2025 09:51
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.

Text starting with numbers cut off in preview

2 participants