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

See if HLJS can work on generic (non-language specific) code blocks #16

Closed
budparr opened this issue Apr 29, 2017 · 7 comments
Closed

Comments

@budparr
Copy link

budparr commented Apr 29, 2017

Currently HLJS is cued off of the class language-html or other appropriate language. Code blocks only get that class if they're wrapped in a short-code, and handling of the shortcode is inconsistent through the docs, leaving many left without highlight.

So either we need to find a way to apply hljs to generic code that doesn't have that class or apply the shortcode uniformly to the code.

cc @digitalcraftsman @rdwatters

#13 (comment)

Initially made this issue in the wrong repo. Sorry!

@budparr
Copy link
Author

budparr commented Apr 29, 2017

Ryan said:

The language declaration doesn't require the shortcode. Hugo (Blackfriday) can take care of triple back ticks, which is all HLJS should need. If it's inconsistent, it just means I missed a few items 😄 The current site uses only the indented syntax (with no language declaration, if I recall), and things are still being highlighted. I'll add this to my list of cleanup this weekend; so, I'll standardize all the code blocks (some of them don't use the shortcode intentionally, since they don't benefit from a copy button, download button, or same file/file path), and also remove all the opinionated classes, IDs, etc....

@budparr
Copy link
Author

budparr commented Apr 29, 2017

Alright. So I may have been too aggressive with stripping out styles for things that were not Hugo. I see, too that there's Hugo stuff that is language-html as well language-golang which, the latter, I didn't account for.

@budparr
Copy link
Author

budparr commented Apr 29, 2017

since they don't benefit from a copy button, download button, or same file/file path),

Yeah, that makes sense. So things that don't need those features, shouldn't be wrapped in the shortcode, therefore I need to account for them in my styling. I'll take another look.

and, as you can see here I stripped out everything. https://github.com/budparr/gohugo-theme/blob/master/src/css/_hljs.css

But as far as I understood, HLJS is language specific, but I'll see if I can dig up something, if it's not just handled in the stylesheet.

JS:
https://github.com/budparr/gohugo-theme/blob/master/src/js/hljs.js

@budparr
Copy link
Author

budparr commented Apr 29, 2017

Trying to avoid this (https://hugodocs.info/templates/introduction/#2-use-to-access-the-global-context), where the HTML tags are highlighted, but not the Hugo tags (except in one case because the Hugo tag is part of the HTML:

screen shot 2017-04-29 at 3 16 20 pm

this is not a comment on @rdwatters work on this, but looking for cases to style around.

@rdwatters
Copy link
Contributor

Initially made this issue in the wrong repo. Sorry!

Ha, responded on my phone and didn't notice.

I think the example you put above is a good one since I remember trying tweak a lot of the HLJS (including, for example, hugo as an alias for a natively supported language in HLJS) so that I could get Hugo-specific keywords. For example, I added Site and Data and a few others:

https://github.com/rdwatters/hugo-docs-concept/blob/master/themes/hugo-docs-concept/pipeline/js/scripts/highlight.pack.js#L276-L277

In retrospect, kind of a myopic move on my part since everything would break with future packages. In the hopes of saving you a step, these are the following languages I have on the current site from https://highlightjs.org/download/:

  • HTML, XML
  • Go
  • Markdown
  • Handlebars
  • Apache
  • Ini (It's obnoxious that it's not the site, but the main alias for this is toml)
  • CSS
  • Asciidoc
  • Ruby
  • YAML
  • Powershell
  • SCSS
  • JSON
  • BASH
  • HTTP
  • JavaScript

@rdwatters
Copy link
Contributor

rdwatters commented Apr 29, 2017

Hmm. So I guess the HLJS "Handlebars" is a little better in that it recognizes the double curlies as a template variable, but it doesn't separate strings from templating logic, etc.

introduction_to_hugo_templating___hugo

Do you think we should write our own hljs.registerLanguage for hugo that we import as a module? Just copy and extend handlebars, since it's in many ways just an extension of HTML? This is mostly me spitballing 😄

@jmooring
Copy link
Member

jmooring commented Nov 9, 2023

HLJS was stripped out a long time ago.

@jmooring jmooring closed this as completed Nov 9, 2023
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

3 participants