Skip to content

fix(block): constrain line-number gutter width on the frontend - #308

Open
faisalahammad wants to merge 1 commit into
Automattic:masterfrom
faisalahammad:fix/287-gutter-width
Open

fix(block): constrain line-number gutter width on the frontend#308
faisalahammad wants to merge 1 commit into
Automattic:masterfrom
faisalahammad:fix/287-gutter-width

Conversation

@faisalahammad

Copy link
Copy Markdown

Fixes #287

Changes proposed in this Pull Request

  • The Gutenberg block output (.wp-block-syntaxhighlighter-code) uses the v3 highlighter table, where table-layout: auto + width: 100% on the table and td.code stretches the td.gutter cell, so line numbers sit far from the code. On narrow screens the gutter and code cells also split onto separate rows.
  • Adds two block-scoped CSS rules in src/code-block/style.scss (built into dist/blocks.style.build.css): max-width: fit-content on the gutter cell, and display: inline-table on the row so the number stays on the same line as its code.
  • The file dist/blocks.style.build.css was built but never loaded before. It is now registered as syntaxhighlighter-blocks-css and injected on the frontend only when the page contains a syntaxhighlighter/code block (or a reusable block), using the same JS link-injection pattern maybe_output_scripts() already uses for the core/theme styles.
  • Shortcode output ([sourcecode] etc.) has no block wrapper, so it is untouched.

Testing instructions

  • On a site running Twenty Twenty-Four, add a SyntaxHighlighter Code block, paste some code, and turn "Line numbers" on. Publish.
  • On the frontend, the line-number column hugs the numbers instead of stretching toward the center.
  • Resize the window narrow (under ~640px). Each line number stays on the same row as its code line.
  • Add a classic [sourcecode php] shortcode on another post. Its gutter/layout looks unchanged.
  • Tested manually on WordPress 6.7.2, Twenty Twenty-Four, Chrome/Firefox/Safari, with the plugin built from this branch (npm run build).

- Add block-scoped CSS capping gutter width at fit-content
- Keep gutter and code cells on one row via inline-table display
- Register and inject dist/blocks.style.build.css on block pages only

Fixes Automattic#287
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.

CSS for Line Number, displays too wide

1 participant