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

Block code and Highlightjs #6309

Closed
castroCrea opened this issue Feb 22, 2020 · 11 comments
Closed

Block code and Highlightjs #6309

castroCrea opened this issue Feb 22, 2020 · 11 comments
Labels
resolution:invalid This issue is invalid (e.g. reports a non-existent bug or a by-design behavior). type:bug This issue reports a buggy (incorrect) behavior.

Comments

@castroCrea
Copy link
Contributor

📝 Provide detailed reproduction steps (if any)

  1. take an EditorBuild width Code Block Plugin
  2. import highlightjs on header
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/androidstudio.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
  1. Then check for code on every change
  BalloonEditor.create(document.querySelector("#editor"))
    .then(editor => {
    	editor.model.document.on( 'change:data', (event) => {
		console.log( 'The data has changed!', event );
		// hljs.highlight()
		document.querySelectorAll('pre code').forEach((block) => {
			hljs.highlightBlock(block);
		});
	} );
});

✔️ Expected result

What is the expected result of the above steps?
image

❌ Actual result

What is the actual result of the above steps?
image

If found out that it's work but ckeditor5 refresh the content just after hljs change the content. So when it's trigger there is a change form hljs and a reverse change form ckeditor5

📃 Other details

  • Browser: Chrome
  • OS:Mac OS
  • CKEditor version: 17.0.0
  • Installed CKEditor plugins: …

If you'd like to see this fixed sooner, add a 👍 reaction to this post.

@castroCrea castroCrea added the type:bug This issue reports a buggy (incorrect) behavior. label Feb 22, 2020
@Reinmar
Copy link
Member

Reinmar commented Feb 24, 2020

It's impossible to run an external highlighter on CKE5's content. CKE5 controls every smaller aspect of its DOM. External tools must not modify it.

This means that it's impossible to have code highlighting in the current code blocks feature. There's a separate feature request for more "code-oriented" feature: #5769.

@Reinmar Reinmar closed this as completed Feb 24, 2020
@Reinmar Reinmar added the resolution:invalid This issue is invalid (e.g. reports a non-existent bug or a by-design behavior). label Feb 24, 2020
@castroCrea
Copy link
Contributor Author

Ok I understand, can you make this part of the doc more clear

https://ckeditor.com/docs/ckeditor5/latest/features/code-blocks.html#integration-with-code-highlighters

We don't really see the "impossible", and the title make us thinks that it's is possible.

@Reinmar
Copy link
Member

Reinmar commented Feb 24, 2020

Although live code block highlighting is impossible when editing in CKEditor 5 (learn more), the content can be highlighted when displayed in the frontend (e.g. in blog posts, messages, etc.).

I'm sorry, but this is the very first sentence in that section. I understand how one could miss it when scanning the text but it's the first time we see this issue reported. If we'll see that more people have a problem with this, we'll definitely consider improving that section.

However, if you have an idea for how it could be written, a PR would be awesome.

@antoniotejada
Copy link

@Reinmar

It's impossible to run an external highlighter on CKE5's content. CKE5 controls every smaller aspect of its DOM. External tools must not modify it.

This means that it's impossible to have code highlighting in the current code blocks feature. There's a separate feature request for more "code-oriented" feature: #5769.

Actually, there's a quite simple solution, check https://github.com/antoniotejada/Trilium-SyntaxHighlightWidget (and thanks for all the CKEditor help you provide here and at stackoverflow!).

@zgpnuaa
Copy link

zgpnuaa commented Sep 16, 2022

I successfully configured this plug-in CKEditor5-CodeBlock-With-Syntax-Highlight in ckeditor5. It is great in edit mode, but it does not display correctly in preview mode.
image

@Badlapje
Copy link

Can we integrate the work by @zgpnuaa in the official plugin? I don't understand why it's not integrated already. Code blocks without highlighting suck. You can almost copy/paste the fix. Please make it happen.

@Witoso
Copy link
Member

Witoso commented Jul 3, 2023

@Badlapje please read the comment above. AFAIK we see such capability in a bit bigger scope and as a new feature, not necessarily implemented alongside the current code block.

Unfortunately, rarely, do we see things that are a copy/paste fix. The linked package has no tests and breaks in some scenarios. If you have the capability, we always look forward to contributions and PRs that will push some things further.

@antoniotejada
Copy link

@Witoso

This means that it's impossible to have code highlighting in the current code blocks feature.

That is not correct, see https://github.com/antoniotejada/Trilium-SyntaxHighlightWidget

@Witoso
Copy link
Member

Witoso commented Jul 3, 2023

Please @antoniotejada consider that we need to think about a much bigger landscape of use cases and integrations. This being able to work in one app's context, may not solve all edge cases and setups that we stumble upon. 

That being said, personally, I don't like the world impossible that is used in this discussion. Probably a better would be: taking into account all pros and cons, we see this as a separate feature, not an extension. I will try to dig around as the research was taking place a while ago.

@antoniotejada
Copy link

@Witoso

Please @antoniotejada consider that we need to think about a much bigger landscape of use cases and integrations. This being able to work in one app's context, may not solve all edge cases and setups that we stumble upon. 

If you "need to think about much bigger landscape of use cases and integrations" instead of using a simple and working implementation of syntax highlighting on a code block, then there's little else to add.

@Witoso
Copy link
Member

Witoso commented Jul 7, 2023

It's just a reality of an open-source project with a commercial twist. There's no bad ill on our side, we are truly happy that the community is engaging with us, and sharing their solutions. It's harder when you have more integrations and use cases to pick something and implement. As said I will try to take a look at this again from a new perspective.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
resolution:invalid This issue is invalid (e.g. reports a non-existent bug or a by-design behavior). type:bug This issue reports a buggy (incorrect) behavior.
Projects
None yet
Development

No branches or pull requests

6 participants