Navigation Menu

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

Code Annotations and Terraform #3696

Closed
5 tasks done
azbpa opened this issue Mar 11, 2022 · 2 comments
Closed
5 tasks done

Code Annotations and Terraform #3696

azbpa opened this issue Mar 11, 2022 · 2 comments
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@azbpa
Copy link

azbpa commented Mar 11, 2022

Contribution guidelines

I've found a bug and checked that ...

  • ... the problem doesn't occur with the mkdocs or readthedocs themes
  • ... the problem persists when all overrides are removed, i.e. custom_dir, extra_javascript and extra_css
  • ... the documentation does not mention anything about my problem
  • ... there are no open or closed issues that are related to my problem

Description

I tried to use Code Annotations with Terraform syntax highlighting as the following:

index.md

# Problem 1

``` terraform
terraform { # (1)
    required_version = ">= 1.1.0" 
} 

provider "azurerm" { # (2)
    features {} 
}
```

1.  Hello World 1
2.  Hello World 2

# Problem 2

``` terraform
terraform { # (1)
    required_version = ">= 1.1.0" 
} 

provider "azurerm" { 
    features {} 
}

# (2)
module "hello_world" {
    source "../.."
    foo = "bar"
}
```

1.  Hello World 1
2.  Hello World 2

Expected behaviour

Code Annotations should render correctly for both code blocks.

Actual behaviour

HTLM output looks like this:
image

Problem 1
It looks like # (2) is not treated as a comment. At least it isn't highlighted the same way as the other comment.

Problem 2
Browser is throwing the following exception:

index.ts:77 Uncaught TypeError: Cannot read properties of null (reading 'textContent')
    at cs (index.ts:77:43)
    at Zo (index.ts:120:24)
    at index.ts:193:30
    at e._subscribe (defer.ts:55:15)
    at e._trySubscribe (Observable.ts:245:19)
    at Observable.ts:235:18
    at nt (errorContext.ts:29:5)
    at e.subscribe (Observable.ts:221:5)
    at switchMap.ts:109:49
    at t.s._next (OperatorSubscriber.ts:70:13)

It seems like that there are empty c/c1/cm elements in code block which force this exception. Further, for any other code block after this one, annotations don't get rendered at all.

Steps to reproduce

  1. Create project with mkdocs.yaml and index.md as provided
  2. Run mkdocs serve with provided versions

Package versions

  • Python: Python 3.9.10
  • MkDocs: 1.2.3
  • Material: 8.2.5

Configuration

site_name: Code Annotations with Terraform
theme:
  name: material
  features:
  - content.code.annotate
markdown_extensions:
  - pymdownx.highlight:
      anchor_linenums: true
  - pymdownx.inlinehilite
  - pymdownx.snippets
  - pymdownx.superfences

System information

  • Operating system: Windows 10
  • Browser:
    • Firefox 91.7.0esr (64-bit)
    • Chrome 99.0.4844.51 (Official Build) (64-bit)
@squidfunk
Copy link
Owner

squidfunk commented Mar 22, 2022

Thanks for reporting.

Problem 1

terraform { # (1)
    required_version = ">= 1.1.0" 
} 

provider "azurerm" { # (2)
    features {} 
}

This seems to be an issue with the Pygments Terraform lexer, as the second comment is a syntax error, and not correctly detected as a comment. Please report this issue upstream. The resulting HTML is:

<span class="err"> # (2)</span>

Problem 2

terraform { # (1)
    required_version = ">= 1.1.0" 
} 

provider "azurerm" { 
    features {} 
}

# (2)
module "hello_world" {
    source "../.."
    foo = "bar"
}

Again, it appears that this is weird behavior by the Pygments Terraform lexer, but something we can workaround. The lexer seems to generate empty comment nodes, which we did not intercept. This is fixed in 104c8c8. It would be great if you could report the empty comment nodes upstream. The generated nodes are:

<span class="c1"></span>

@squidfunk squidfunk added bug Issue reports a bug resolved Issue is resolved, yet unreleased if open labels Mar 22, 2022
@squidfunk
Copy link
Owner

Released as part of 8.2.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

2 participants