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

Adding syntax highlight element #14425

Closed
caraya opened this issue Apr 4, 2018 · 10 comments
Closed

Adding syntax highlight element #14425

caraya opened this issue Apr 4, 2018 · 10 comments

Comments

@caraya
Copy link

caraya commented Apr 4, 2018

I am using AMP via Wordpress and the wp-amp plugin. I use Prism.js (via plugin) to do syntax highlight. This works in the regular Wordpress render but not when used through AMP.

In amphtml/#2412 @cramforce mentions that this should be done server side. We still need the tool to do so, either in the amp cache or via an element that caches the JS and CSS for the fences.

Using amp-gist (amphtml/#8580) is not an option as some of my posts have 15 or more code examples. The plugin website closed an issue requesting syntax highlighting (amp-wp/#972)

@westonruter
Copy link
Member

The solution is to use a WordPress plugin that does server-side highlighting via PHP instead of client-side highlighting via JS. I don't see there being anything required on the AMP side. See ampproject/amp-wp#972 (comment)

@caraya
Copy link
Author

caraya commented Apr 4, 2018

Not all cases use Wordpress. I'm asking if there is a way to create such an element.

@cramforce
Copy link
Member

I wouldn't be opposed to adding this if the highlighting does nothing but add color.

@KENNYSOFT
Copy link
Member

Anyone can approve me to develop <amp-hljs> or something like that? Similar to Prism.js, highlight.js provides syntax highlighting as well. I want to develop the new extension.

@watilde
Copy link

watilde commented Apr 17, 2019

As some people mentioned that there are some workarounds, but I was wondering the same idea.

@aghassemi
Copy link
Contributor

doing this client-side is borderline against AMP UX principles. I don't think we would develop such extension. SSR is the right, performant approach.

@caraya
Copy link
Author

caraya commented Jun 25, 2019

If that's the case, @aghassemi, can you provide a solution or pointers to such a solution?

@aghassemi
Copy link
Contributor

aghassemi commented Jun 25, 2019

@caraya any syntax highlighting tool that can run server-side would do. Actually Prism.js can do that and they even mention AMP as one of the cases where SSR is needed

from: https://prismjs.com/

If you want to use Prism on the server or through the command line, Prism can be used with Node.js as well. This might be useful if you're trying to generate static HTML pages with highlighted code for environments that don't support browser-side JS, like AMP pages

@westonruter
Copy link
Member

If using PHP on your site, you can use highlight.php: https://github.com/scrivo/highlight.php

@caraya
Copy link
Author

caraya commented Jul 2, 2019

@aghassemi OK. It says it can't be done but not how. I'll keep looking and work trying to figure out how.

@westonruter This is not for PHP or WordPress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants