highlightjs / highlight.js

JavaScript syntax highlighter with language auto-detection and zero dependencies.
https://highlightjs.org/
BSD 3-Clause "New" or "Revised" License
23.52k stars 3.57k forks source link

Support HCL / Terraform #1879

Closed cryptiklemur closed 4 years ago

cryptiklemur commented 5 years ago

https://github.com/hashicorp/hcl

marcoscaceres commented 5 years ago

Hi, we accept language contributions from the community, but don’t generally write them ourselves. Would this be something the hcl community would be willing to create and maintain?

raphink commented 5 years ago

So far, I've been using the Ruby highlighter for HCL, but a dedicated language would be better of course.

qubyte commented 5 years ago

I recently opened a PR (#2076) with a language file for github workflows, which I've just learnt are based upon HCL. I've found a vim syntax file here for HCL, and it seems relatively simple. I could update my PR to cover HCL with workflow as an alternative name.

If languages are now being split into their own repositories, I'd be happy to maintain this one. Thoughts?

marcoscaceres commented 5 years ago

@qubyte, sorry for the delay. That would be amazing. I'll set a repo for gh-workflow for you. We have a terraform language definition in a repo already... is it the same language as this one?

marcoscaceres commented 5 years ago

Here is the link to the terraform one: http://github.com/highlightjs/highlight-terraform/ if it's the same, I can add you as a collaborator to that one.

qubyte commented 5 years ago

It appears to be the same! I didn't realise this existed :D

marcoscaceres commented 5 years ago

heh, that's my fault for not keeping docs up to date 🤪 Added you to that one too. The nice thing about the terraform repo is that is has tests already. You can probably copy/paste what's there and adapt it.

qubyte commented 5 years ago

It may be that these can be added as aliases. The terraform one should probably (though I'd need to take a closer look) be called HCL, since HCL is the language whereas terraform, github workflow etc. are use cases.

marcoscaceres commented 5 years ago

Could be... I honestly don't know as I've not looked at the languages.

qubyte commented 5 years ago

Is the terraform definition currently bundled with highlight.js? How does that work?

marcoscaceres commented 5 years ago

Is the terraform definition currently bundled with highlight.js?

No, a consumer needs to npm install it.

How does that work?

Then they can, for example:

hljs.registerLanguage('customLanguage', customLanguage);

Then they can create a custom build, for example: https://github.com/w3c/respec-hljs

The bundle is great, because it only includes the the languages the project needs.

qubyte commented 5 years ago

I see! Is the long-term plan to split all the languages out and always manually include them, or something midway with a set of default languages bundled (just asking out of curiosity now)?

marcoscaceres commented 5 years ago

I see! Is the long-term plan to split all the languages out and always manually include them, or something midway with a set of default languages bundled (just asking out of curiosity now)?

We will keep the current "core" set as to not break existing functionality, and split out all new ones.

joshgoebel commented 4 years ago

We will keep the current "core" set as to not break existing functionality, and split out all new ones.

Actually if we thought of a way to package multiple languages you could do something like separate the whole Highlight.js codebase from the languages... and then you just install "highlightjs-core-languages"... and then the core languages are "just another language pack".

Something to think about perhaps once we figure out tooling for all this. :)

In regard to "don't break existing functionality" I think the key concerns are (correct me if I'm mistaken):

I don't think any of those goals necessarily 100% requires the languages live in the same repo as the highlighter itself forever. Just food for thought.

joshgoebel commented 4 years ago

Is HCL still separate and this is still and open request or can this be closed now that we have the teraform repo?

dbrennand commented 4 years ago

It would be helpful to provide a usage example in the repo on how to apply the syntax.

dbrennand commented 4 years ago
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Test</title>
    <script type="text/javascript" src="highlight.pack.js"></script>
    <script type="text/javascript" src="highlightjs-terraform/terraform.js"></script>
    <script type="text/javascript">
        hljs.registerLanguage('terraform', window.hljsDefineTerraform);
        hljs.initHighlightingOnLoad();
    </script>
</head>
<body>
    <pre><code class="tf">provider "azure" {
        arm_endpoint    = ""
        subscription_id = ""
        client_id       = ""
        client_secret   = ""
        tenant_id       = ""
      }
      </code></pre>
</body>
</html>

The highlighting doesn't work. Can anybody spot the mistake I am making?

joshgoebel commented 4 years ago

Looks decent to me, any errors in console log?

dbrennand commented 4 years ago

Looks decent to me, any errors in console log?

Not that I can see, I have tried in Firefox and Chrome.

image

It looks like hightlightjs is working but there is no colour on the html page. 😞

EDIT: I am going to try the process here: https://highlightjs.readthedocs.io/en/latest/building-testing.html#building

joshgoebel commented 4 years ago

Sounds like a css issue.

dbrennand commented 4 years ago

Sounds like a css issue.

Wow I feel pretty stupid... Added a style.css file and it's working 😆. Thanks!

marcellino-ornelas commented 6 months ago

Any reason why https://github.com/highlightjs/highlightjs-terraform is not available on npm/yarn/etc ?

joshgoebel commented 6 months ago

This project is currently in need of a maintainer.

No one to do it?