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 code snippets. #9

Closed
aadrian opened this issue Nov 29, 2016 · 10 comments
Closed

Syntax highlighting for code snippets. #9

aadrian opened this issue Nov 29, 2016 · 10 comments

Comments

@aadrian
Copy link
Contributor

aadrian commented Nov 29, 2016

Please add syntax highlighting for the code snippets too, depending on the used language: in the editor but also in the output.

Thank you.

@JFormDesigner
Copy link
Owner

Thanks, good idea. I'm missing this too...

Any recommendation for a good syntax highlighting library (written in Java)?

@aadrian
Copy link
Contributor Author

aadrian commented Nov 29, 2016

Any recommendation for a good syntax highlighting library (written in Java)?

Isn't RichTextFX capable of that (since it does for for markdown) ?

For the parsing and AST part, ANTLR https://github.com/antlr/antlr4 seems to have the most and detailed ready grammars: https://github.com/antlr/grammars-v4

@JFormDesigner
Copy link
Owner

Any recommendation for a good syntax highlighting library (written in Java)?

Isn't RichTextFX capable of that (since it does for for markdown) ?

Sure, for displaying 😉
My questions was regarding a library that parses code and outputs "highlighted" code

ANTLR seems to be overkill for syntax highlighting...

Did a quick search and found:

Another alternative would be to use highlight.js, which is written in JavaScript. For the preview, this would be probably easy because the preview is a WebKit component that natively supports JavaScript. For the editor, I could try to use Java Nashorn...

@aadrian
Copy link
Contributor Author

aadrian commented Nov 29, 2016

Another alternative would be to use highlight.js,

There are many JS based highlighters. E.g.
https://webdesign.tutsplus.com/articles/25-syntax-highlighters-tried-and-tested--cms-23931

this would be probably easy because the preview is a WebKit component that natively supports JavaScript. For the editor, I could try to use Java Nashorn...

Well, in that case maybe for a first version, having only for the preview would be a good start :) .

JFormDesigner pushed a commit that referenced this issue Dec 10, 2016
uses Prism v1.6.0 syntax highlighter (https://github.com/PrismJS/prism)

downloaded Prism v1.6.0 source code ZIP from https://github.com/PrismJS/prism/releases and simply copied needed files
@JFormDesigner
Copy link
Owner

@aadrian thanks for the link to the 25 JS highlighters. This was really helpful. Tried some of them and decided to use Prism. For the preview only. The code is now in the master branch. Give it a try 😉

I'll keep this issue open for the syntax highlighting in the editor.

@aadrian
Copy link
Contributor Author

aadrian commented Dec 11, 2016

Tried some of them and decided to use Prism.

Good choice.

Even if https://github.com/PrismJS/prism does not have so many languages supported (yet), the project is active and there's also "plug-in" support for further extensions.

The code is now in the master branch. Give it a try

The integration looks very good :) .
Can't imagine now using without without this feature, so when this version is released, the screenshots https://github.com/JFormDesigner/markdown-writer-fx/blob/master/images/screenshot.png could show that feature too :) .

For the preview only.

Now that it works so nicely for preview, it could be interesting to try to apply it to HTML Source and Markdown AST too, since those are also read only :) ?

@JFormDesigner
Copy link
Owner

Now that it works so nicely for preview, it could be interesting to try to apply it to HTML Source and Markdown AST too, since those are also read only :) ?

Yes, had this in mind too. Now implemented in master 😉

I've also implemented "range highlighting" in the Markdown AST view, which makes it much easier to find the AST that is at the caret in the editor.

Now that we have syntax highlighting in HTML Source view, I think I should also implement it for HTML blocks/inlines in the editor (before releasing a new version)...

@aadrian
Copy link
Contributor Author

aadrian commented Dec 13, 2016

Now that it works so nicely for preview, it could be interesting to try to apply it to HTML Source and Markdown AST too, since those are also read only :) ?

Now implemented in master

It looks very good :) .
Now it's much easier to spot possible problems too :) , e.g. #17

@JFormDesigner
Copy link
Owner

Syntax highlighting for HTML/XML/SVG/MathML in editor is now implemented in master

@aadrian
Copy link
Contributor Author

aadrian commented May 4, 2017

The editor is simply fantastic with syntax highlighting !

It needs however a shorter name that is more SEO friendly :)

@aadrian aadrian closed this as completed May 4, 2017
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

No branches or pull requests

2 participants