Skip to content

Syntax Highlighting for HTML block/ Code block and HTML editor #10423

Open

Description

@youknowriad

Syntax highlighting as implemented today is not great. We should aim to provide a consistent behavior across blocks while keeping the bundle size as small as possible:

  • It should be lazy-loadable
  • It should be generic enough to be used as an npm dependency
  • It should be consistent.

Also, nowadays, alternative editors like "Monaco Editor" do a better job than CodeMirror, we should try to explore it and see how it fits.

Activity

  1. added this to the Future: 5.1 Onwards milestone on Oct 12, 2018
  2. mor10 commented on Oct 12, 2018

    @mor10
    Contributor

    Just for clarity: There is no syntax highlighting at all in 4.0 RC1, correct? I remember there used to be, but now both the code and html blocks show plain unformatted text.

  3. chrisvanpatten commented on Oct 12, 2018

    @chrisvanpatten
    Contributor

    @mor10 it had to be removed due for technical reasons but the hope is to bring it back at some point. I forget the ticket number but I’m sure someone else can dig it up!

  4. youknowriad commented on Oct 12, 2018

    @youknowriad
    ContributorAuthor

    @mor10 yes, that's true. The html block used to have it, but we removed it for the moment. We were not satisfied with the implementation and it was not consistent. This will be back at some point though.

  5. Clorith commented on Oct 16, 2018

    @Clorith
    Member

    Looking forward to the return :)

    I would like to interject that it was mentioned that we might use something other than CodeMirror in Gutenberg, this seems like a poor choice, given that core comes bundled with CodeMirror. This means the package size doesn't affect us at the very least, it's not the smallest library, so it would be a shame to not use it when it's bundled and "always there" for us. Hopefully we can come up with an implementation that is workable with it.

  6. xy0 commented on Oct 26, 2018

    @xy0

    Please bring it back, I found it really useful and didn't experience any issues except for unwanted end tags being created sometimes. The plain text box that exists now is pretty much exactly the same as the shortcode and code blocks.

  7. PeterBooker commented on Nov 17, 2018

    @PeterBooker

    The Monaco editor is not supported in mobile browsers or mobile web frameworks. microsoft.github.io/monaco-editor/

    CodeMirror is currently being rewritten, as CodeMirror 6 (sponsored by Automattic too), which looks like it might meet the OP requirements. It might be worth reaching out/contributing to ensure that it does.

  8. willdelphia commented on Nov 21, 2018

    @willdelphia

    any chance this will be fixed by the 5.0 release?

  9. noisysocks commented on Nov 21, 2018

    @noisysocks
    Member

    @willdelphia: No, this will not be in the 5.0 release.

  10. willdelphia commented on Jan 9, 2019

    @willdelphia

    Is there a place where people can vote for upcoming features to take priority over others? If so, this has my vote.

  11. willdelphia commented on Mar 8, 2019

    @willdelphia
  12. added
    [Focus] Accessibility (a11y)Changes that impact accessibility and need corresponding review (e.g. markup changes).
    on Mar 8, 2019
  13. removed this from the WordPress 5.x milestone on Mar 25, 2019
  14. 5 remaining items

  15. dingo-d commented on May 17, 2019

    @dingo-d
    Member

    So any news on the syntax highlight feature for the default code block? This is a must have for technical blogs.

    Syntax highlighting available in REST API responses

    Isn't REST API response plain JSON? Not sure where syntax highlighting comes into play here 🤷‍♂

  16. earnjam commented on Aug 15, 2019

    @earnjam
    Contributor

    Isn't REST API response plain JSON? Not sure where syntax highlighting comes into play here

    It is, but in the content rendered value of the response, it would return the content of the post or block with the additional required markup to allow just CSS on the front-end to style the various code portions, instead of doing the parsing/modifying via JS.

  17. afercia commented on Aug 23, 2019

    @afercia
    Contributor

    For some design exploration on the Code Editor, see #17017

  18. sudip358 commented on Sep 15, 2020

    @sudip358

    Could you please inline editing system?

  19. melroy89 commented on Dec 16, 2021

    @melroy89

    Maybe see also Monaco editor: https://github.com/microsoft/monaco-editor, which could be used by Gutenberg.

  20. porg commented on Jul 18, 2023

    @porg

    Until that feature gets implemented (if ever)

    Block Editor Syntax Highlighting from plugin EditorsKit

  21. okmttdhr commented on Mar 26, 2024

    @okmttdhr
    Contributor

    I'm proposing #60155.
    For lazy-loading, I'm utilizing Webpack's import() for now (c.f., #53380 (comment)).

  22. self-assigned this
    on Mar 23, 2026
  23. carolinan commented on Mar 24, 2026

    @carolinan
    Contributor

    With "HTML editor" do we mean the block editor and site editor "Code editor mode" ?

  24. westonruter commented on Mar 24, 2026

    @westonruter
    Member

    @carolinan yes, any interface that exposes code editing should have syntax highlighting.

  25. removed their assignment
    on Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Block] CodeAffects the Code Block[Block] HTMLAffects the the HTML Block[Feature] BlocksOverall functionality of blocks[Focus] Accessibility (a11y)Changes that impact accessibility and need corresponding review (e.g. markup changes).

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions