Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
youknowriad opened this issue Oct 9, 2018 · 20 comments
Open

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

youknowriad opened this issue Oct 9, 2018 · 20 comments
Labels
[Block] Code Affects the Code Block [Block] HTML Affects the the HTML Block [Feature] Blocks Overall functionality of blocks [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes).
Milestone

Comments

@youknowriad
Copy link
Contributor

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.

@mor10
Copy link
Contributor

mor10 commented Oct 12, 2018

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.

@chrisvanpatten
Copy link
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!

@youknowriad
Copy link
Contributor Author

youknowriad commented Oct 12, 2018

@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.

@Clorith
Copy link
Member

Clorith commented Oct 16, 2018

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.

@xy0
Copy link

xy0 commented Oct 26, 2018

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.

@PeterBooker
Copy link

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.

@willdelphia
Copy link

willdelphia commented Nov 21, 2018

any chance this will be fixed by the 5.0 release?

@noisysocks
Copy link
Member

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

@willdelphia
Copy link

willdelphia commented Jan 9, 2019

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

@willdelphia
Copy link

https://wordpress.org/plugins/ace-html-block/

@afercia afercia added the [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). label Mar 8, 2019
@youknowriad youknowriad modified the milestones: WordPress 5.x, Future Mar 25, 2019
@ashwin-pc
Copy link
Contributor

I see that the desired implementation of the code block is something similar to codemirror. but reverting back to a block that does nothing but preformat the bock is pretty bare. Cant the code block until that use something similar to this project https://github.com/mkaz/code-syntax-block. All it does is add the option to choose the language and then use prism.js to perform syntax highlighting. This is much more useful than the current implementation and pretty light weight in terms of package size.

@mkaz
Copy link
Member

mkaz commented Apr 15, 2019

Thanks @ashwin-pc I like my solution too, though I'm not sure if it should be included in Core. Likewise I don't think the CodeMirror or Monaco Editor should be included either. To me, they are too heavy and seems like a niche case that people want a full code editor in their publishing tool. I personally do not.

As far as syntax highlighting it is definitely useful and would be nice to have it out of the box that people could extend - though I'm not sure Prism would be the best choice, since it requires additional JS/CSS files to be loaded on the front-end.

I like Prism for ease of use, but a better core solution might be what @westonruter created forking my plugin, and making it server-side which ends up being lighter-weight for the end users. See his repo at: westonruter/code-syntax-block

@ataylorme
Copy link

I would prefer a server-side solution as well for a few reasons:

  • No client-side JS needed
  • Syntax highlighting available in REST API responses
  • Server-side responses can be cached (e.g. Varnish)
  • AMP compatibility

@dingo-d
Copy link
Member

dingo-d commented May 17, 2019

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 🤷‍♂

@earnjam
Copy link
Contributor

earnjam commented Aug 15, 2019

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.

@afercia
Copy link
Contributor

afercia commented Aug 23, 2019

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

@sudip358
Copy link

sudip358 commented Sep 15, 2020

Could you please inline editing system?

@melroy89
Copy link

melroy89 commented Dec 16, 2021

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

@porg
Copy link

porg commented Jul 18, 2023

Until that feature gets implemented (if ever)

Block Editor Syntax Highlighting from plugin EditorsKit

@okmttdhr
Copy link
Contributor

okmttdhr commented Mar 26, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Code Affects the Code Block [Block] HTML Affects the the HTML Block [Feature] Blocks Overall functionality of blocks [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes).
Projects
None yet
Development

No branches or pull requests