Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 7, 2026

Command documentation generator was double-escaping HTML entities and not decoding them inside backtick-enclosed code spans, causing incorrect rendering in generated files.

Changes

Generator fixes (bin/Handbook_Command.php)

  1. Prevent double escaping (lines 649-650):
    • Converts < back to < and > back to >
    • Placed after word wrapping logic to prevent double escaping when htmlspecialchars() processes content that already contains entities
// Prevent double escaping of HTML entities.
$docs = preg_replace( '/</', '<', $docs );
$docs = preg_replace( '/>/', '>', $docs );
  1. Decode HTML entities inside backticks (lines 653-659):
    • Uses preg_replace_callback to find backtick-enclosed code spans
    • Decodes HTML entities within them using html_entity_decode()
    • Ensures inline code like `--theme=<theme>` renders correctly instead of `--theme=&lt;theme&gt;`
// Decode HTML entities inside backticks.
$docs = preg_replace_callback(
    '/`([^`]*)`/',
    function ( $matches ) {
        return '`' . html_entity_decode( $matches[1], ENT_QUOTES | ENT_HTML401 ) . '`';
    },
    $docs
);

Problem

  1. When source docblocks contain &lt;slug&gt; (HTML entities), the htmlspecialchars() call on line 609 converts the & in &lt; to &amp;, resulting in &amp;lt;slug&amp;gt; (double-escaped) in the output.
  2. HTML entities inside backtick-enclosed code spans were not being decoded, causing parameter placeholders to display as &lt;theme&gt; instead of <theme> in inline code.

Impact

Future documentation generations will:

  • No longer produce double-escaped HTML entities
  • Correctly render parameter placeholders in inline code with angle brackets instead of HTML entities
  • Display `--theme=<theme>` instead of `--theme=&lt;theme&gt;` on the website
Original prompt

This section details on the original issue you should resolve

<issue_title>scaffold taxonomy docs have incorrect rendering</issue_title>
<issue_description>On https://developer.wordpress.org/cli/commands/scaffold/taxonomy/, the docs display &lt; and &gt; instead of the respective glyphs:

screen shot 2018-02-19 at 6 14 23 pm

--theme and --plugin should probably have identical formatting with regards to whether the =<name> is included inside the square brackets.</issue_description>

<agent_instructions>Don't turn those glyphs such as backticks into HTML entities</agent_instructions>

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.

Copilot AI and others added 2 commits January 7, 2026 17:45
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
…d files

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix incorrect rendering of taxonomy documentation Fix HTML entity rendering in command documentation parameter placeholders Jan 7, 2026
Copilot AI requested a review from swissspidy January 7, 2026 17:53
@swissspidy
Copy link
Member

@copilot I think the issue is actually some double escaping.

Revert your changes.

Then, make sure &amp;lt; is turned into &lt; and &amp;gt; into &gt;

Per @swissspidy's feedback, the issue is double escaping. Changed the generator to convert &amp;lt; back to &lt; and &amp;gt; back to &gt; to prevent double escaping.

- Reverted all markdown files to original state with &lt;slug&gt;
- Added fix to prevent &amp;lt; from being created by converting it back to &lt;
- Removed previous fix that was converting &lt; to <

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 7, 2026

@copilot I think the issue is actually some double escaping.

Revert your changes.
...

Done. Reverted all changes and added fix to prevent double escaping by converting &amp;lt; to &lt; and &amp;gt; to &gt; in the generator. Commit: 81e126b

Copilot AI changed the title Fix HTML entity rendering in command documentation parameter placeholders Fix double escaping of HTML entities in command documentation generator Jan 7, 2026
@swissspidy
Copy link
Member

@copilot I think what we need to do is to decode HTML entities inside backticks. So that we for example have ``--theme=instead of--theme=<theme>`.

Per @swissspidy's feedback, HTML entities inside backticks should be decoded so that `--theme=&lt;theme&gt;` becomes `--theme=<theme>`.

Added preg_replace_callback to decode HTML entities within backtick-enclosed code spans using html_entity_decode().

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 8, 2026

@copilot I think what we need to do is to decode HTML entities inside backticks. So that we for example have ``--theme=instead of--theme=<theme>`.

Done. Added regex to decode HTML entities inside backticks using html_entity_decode(). Now `--theme=&lt;theme&gt;` will become `--theme=<theme>` in generated documentation. Commit: 676a107

Copilot AI changed the title Fix double escaping of HTML entities in command documentation generator Fix double escaping and decode HTML entities in backticks for command documentation Jan 8, 2026
@swissspidy swissspidy marked this pull request as ready for review January 8, 2026 11:15
@swissspidy swissspidy requested a review from a team as a code owner January 8, 2026 11:15
@swissspidy swissspidy merged commit 882a3de into main Jan 8, 2026
6 checks passed
@swissspidy swissspidy deleted the copilot/fix-taxonomy-docs-rendering branch January 8, 2026 11:20
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.

scaffold taxonomy docs have incorrect rendering

2 participants