6

There's insufficient documentation on which code language identifier to use for the terraform language.

The expected values (tf, hcl, or terraform) do not work.

Is this supported, and if so, what is the correct language identifier?

9
  • The canonical list is here (also linked from the Help Center). When in doubt, "lang-tagName" always works. In this case, there does not appear to be any syntax highlighting for HCL. The [hcl] tag has its associated syntax highlighting set to "<none>", so any highlighting you're seeing is just coming from "default" (i.e., Prettify's language-neutral best-guess attempt). Apr 23, 2020 at 17:10
  • @CodyGray- What would be the steps then of getting the hcl tag to match lang-hcl? I get that hcl might not have a perfect highlighter but if the default is better than none, should the hcl be aligned with default, thereby getting the improved behavior of lang-hcl? Apr 23, 2020 at 17:26
  • added the bug tag because the intentional behavior of using no formatting on hcl code hint seems worse than applying the default (which we get via lang-hcl). Apr 23, 2020 at 17:28
  • Yes, I can update the [hcl] tag to force the "default" formatting to be used. Done now. See if that makes a difference on the posts without explicit formatting hints. Apr 23, 2020 at 17:29
  • Awesome! I added a sample below in my answer. Will refresh periodically and post back shortly when it's had time to replicate. Apr 23, 2020 at 17:33
  • The default hinting won't ever work on Meta. You'll have to check the main site. The default hinting is set per-tag, and Meta uses different tags. Apr 23, 2020 at 17:40
  • Got it. Thanks. I've put three versions of the code block on my related Answer on the main site: stackoverflow.com/questions/52628749/… The first block is hcl, second block is lang-hcl, third block is default (no tag). As of right now, just the middle block (lang-hcl) is formatting as expected. Apr 23, 2020 at 17:53
  • Ah, okay. That's because that question has the [terraform] tag, not the [hcl] tag. I will update the default syntax highlighting for the [terraform] tag, too. This can sometimes confuse the syntax highlighter, which is why we don't make "default" the actual default. That mostly happens in cases where questions have multiple tags, and each of their default syntax highlighting rules conflict with each other. So let me know if you see any issues with this, and it can be reversed. Apr 23, 2020 at 18:06
  • It works now - awesome! I actually did not realize at all that the tag on the question could affect the default code formatter. Although in hindsight now it seems obvious. :) Anyway, THANK YOU for your help! Very much appreciated. Apr 23, 2020 at 19:17

1 Answer 1

7

By performing a browser inspect on one correctly-formatted answer, we can see that lang-hcl is the identifier which works properly.

Using lang-hcl (works):

provider "aws" {
  # Sample
  region = "us-east-1"
}

For reference:

Using hcl (doesn't work):

provider "aws" {
  # Sample
  region = "us-east-1"
}

Using no hint (doesn't work):

provider "aws" {
  # Sample
  region = "us-east-1"
}
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .