mirror of
https://github.com/xoofx/markdig.git
synced 2026-02-08 13:54:54 +00:00
Syntax highlighting for fenced code #299
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @LukeTOBrien on GitHub (Jun 4, 2019).
Hello there,
I saw (Any chance of getting syntax highlighting?) #1 and I have been looking for the same thing for my project, so I thought I would open a new issue.
In my project I am basically creating a product that will help teach programming, so syntax highlighting is very important.
In the old days I used to copy n paste from Visual Studio into PowerPoint to get the highlighting, then I move to web presentations using HighlightJs.
When I type a peice of fenced code I would like to be able to specify the language and for CSS classes to be added that would change the style of the code.
For eg:
Would be something like this (using Highligh.js):
Then I could init Higlight.js on the client-side
...
I was previously using Markdown-it that has a highlight function this is I guess using the highlight.js API.
I was going to experiment using EdgeJs to run a Node function and do the highlighting server-side in a custom renderer.
Whatya think?
@xoofx commented on GitHub (Jun 4, 2019):
Markdig is generating the following (see on babelmark):
If you want to generate something different, you just need to write a simple extension that will replace
FencedCodeBlockParserwith your own, by inheriting from it and set in the constructorInfoPrefix = string.EmptyI don't remember why the prefix was part of the parser though (should have been more a renderer thing)
@MihaZupan commented on GitHub (Jun 20, 2019):
Looks like it is also exposed as a property on the parser
@LukeTOBrien commented on GitHub (Jun 20, 2019):
Ahh okay thanks, I will try this out.
Highlight.js will run on the client-side to do the syntax highlighting... I
don't suppose there's a way to do syntax highlighting on the server-side?
I will experiment with Edge.js to see if I can.
On Thu, Jun 20, 2019 at 3:48 PM Miha Zupan notifications@github.com wrote:
@rclabo commented on GitHub (Jun 20, 2019):
I looked into doing syntax highlighting server-side a few months ago by using the https://www.nuget.org/packages/Pek.Markdig.HighlightJs/ Markdig plugin and eventually got it working kind of. But it relies on Jurassic, and Jurassic kept throwing exceptions when my tests were running. So, finally I abandoned that approach and switched to doing the syntax coloring totally front-side in the javascript after markdig returned the html. And for that I ultimately used https://github.com/google/code-prettify which I found to be very easy to implement. I hope sharing my experience in this area is helpful to you as you figure out the approach you want to take.
@LukeTOBrien commented on GitHub (Jun 29, 2019):
Yep I've come to the same conclusion... Perhaps oneday I will work on a dependany free extension using Highlight.js for now though I will just do it client-side.
I did try using Edge.js however the project is old and doesn't support .Net Core.
Thanks I'll close the issue... Although I think this would make a lovely enhancement for sometime in the future.
@ahmedkamalio commented on GitHub (Feb 25, 2020):
Hi @LukeTOBrien, referring to the highlighjs repo
which means that it should work just fine with the default output of
markdig