# Moduledoc attribute elp tree-sitter highlights - are there any options that could fix/improve -moduledoc highlighting / spell checking?

**URL:** <https://erlangforums.com/t/moduledoc-attribute-elp-tree-sitter-highlights-are-there-any-options-that-could-fix-improve-moduledoc-highlighting-spell-checking/5238>\
**Category:** Questions / Help\
**Tags:** tree-sitter, elp\
**Created:** [November 14, 2025, 12:57pm UTC](https://erlangforums.com/t/moduledoc-attribute-elp-tree-sitter-highlights-are-there-any-options-that-could-fix-improve-moduledoc-highlighting-spell-checking/5238 "2025-11-14T12:57:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrzej-mag](https://erlangforums.com/user_avatar/erlangforums.com/andrzej-mag/32/2601_2.png) [@andrzej-mag](https://erlangforums.com/u/andrzej-mag)\
**Post date:** [November 14, 2025, 12:57pm UTC](https://erlangforums.com/t/moduledoc-attribute-elp-tree-sitter-highlights-are-there-any-options-that-could-fix-improve-moduledoc-highlighting-spell-checking/5238/1 "2025-11-14T12:57:23Z")

</div>

Define Erlang `-moduledoc`:

```erlang
-moduledoc "Test: `12345`".

```

Similarly define Elixir `@moduledoc`:

```elixir
  @moduledoc "Test: `12345`"

```

Inspecting `12345` embedded code snippet gives the following highlight groups:  
Erlang:

```erlang
  - @attribute.erlang links to Macro priority: 100 language: erlang
  - @string.erlang links to String priority: 100 language: erlang

```

Elixir:

```erlang
  - @constant.elixir links to Constant priority: 100 language: elixir
  - @comment.documentation.elixir links to Documentation priority: 100 language: elixir
  - @constant.elixir links to Constant priority: 100 language: elixir
  - @string.elixir links to String priority: 100 language: elixir
  - @comment.documentation.elixir links to Documentation priority: 100 language: elixir
  - @spell.markdown links to @spell priority: 100 language: markdown
  - @markup.raw.markdown_inline links to Special priority: 100 language: markdown_inline
  - @nospell.markdown_inline links to @nospell priority: 100 language: markdown_inline

```

Erlang `moduledoc` is highlighted as a plain `Macro` / `String` which has two consequences:

1. Spell checking is not enabled as it doesn’t link to `@spell`.
2. No syntax highlighting for the embedded code - everything is highlighted as a plain flat string.

Writing Erlang documentation under such restrictions is not easy.

I am using neovim with elp `Version: 1.1.0+build-2025-11-04` installed with Mason more or less as described in the [elp documentation](https://whatsapp.github.io/erlang-language-platform/docs/get-started/editors/neovim/). Additionally I am installing Erlang treesitter (it doesn’t help much in this case):

```lua
require("nvim-treesitter.configs").setup({
	ensure_installed = {
		"erlang"
...

```

Are there any options available that could fix/improve `-moduledoc` highlighting / spell checking?

---

<div class="post-metadata">

**Author:** ![belltoy](https://erlangforums.com/user_avatar/erlangforums.com/belltoy/32/2838_2.png) [@belltoy](https://erlangforums.com/u/belltoy)\
**Post date:** [December 15, 2025, 5:00am UTC](https://erlangforums.com/t/moduledoc-attribute-elp-tree-sitter-highlights-are-there-any-options-that-could-fix-improve-moduledoc-highlighting-spell-checking/5238/2 "2025-12-15T05:00:39Z")

</div>

Try the following query in your `after/queries/erlang/highlights.scm`:

```query
(wild_attribute
  name: (attr_name
          name: (atom) @_doc)
  value: [
          (string) @doc.markdown @comment
          (paren_expr expr: (string) @doc.markdown @comment)
         ]
    (#any-of? @_doc "moduledoc" "doc")
    (#set! "priority" 100))

```

---

<div class="post-metadata">

**Author:** ![andrzej-mag](https://erlangforums.com/user_avatar/erlangforums.com/andrzej-mag/32/2601_2.png) [@andrzej-mag](https://erlangforums.com/u/andrzej-mag)\
**Post date:** [December 15, 2025, 12:01pm UTC](https://erlangforums.com/t/moduledoc-attribute-elp-tree-sitter-highlights-are-there-any-options-that-could-fix-improve-moduledoc-highlighting-spell-checking/5238/3 "2025-12-15T12:01:21Z")

</div>

Thanks @belltoy.  
Adding `after/queries/erlang/highlights.scm` has no effect in my case.  
After adding `queries/erlang/highlights.scm`, the module documentation highlight groups change to:

```erlang
  - @doc.markdown.erlang links to @doc priority: 100 language: erlang
  - @comment.erlang links to Comment priority: 100 language: erlang

```

Documentation is highlighted as a `@doc`, but it still lacks spell checking and embedded code highlighting. Additionally, the highlighting of standard Erlang comments (`% comment`) becomes corrupted.

I don’t use triple quoted documentation strings anymore - I solved problem by placing documentation in external markdown files. The advantages are that the code is no longer polluted with tons of annoying inline documentation, can use robust linting/formatting/viewing/… markdown utilities and can share md docs with Elixir if necessary.

---

<div class="post-metadata">

**Author:** ![belltoy](https://erlangforums.com/user_avatar/erlangforums.com/belltoy/32/2838_2.png) [@belltoy](https://erlangforums.com/u/belltoy)\
**Post date:** [December 15, 2025, 4:29pm UTC](https://erlangforums.com/t/moduledoc-attribute-elp-tree-sitter-highlights-are-there-any-options-that-could-fix-improve-moduledoc-highlighting-spell-checking/5238/4 "2025-12-15T16:29:45Z")

</div>

Sorry, I forgot the `injections.scm`:

```query
(wild_attribute
  name: (attr_name
          name: (atom) @_doc)
          value: (string) @injection.content
            (#any-of? @_doc "moduledoc" "doc")
            (#match? @injection.content "^\"\"\"")
            (#offset! @injection.content 0 3 0 -3)
            (#set! "priority" 105)
            (#set! injection.language "markdown"))

(wild_attribute
  name: (attr_name
          name: (atom) @_doc)
          value: (paren_expr
                   expr: (string) @injection.content)
            (#any-of? @_doc "moduledoc" "doc")
            (#match? @injection.content "^\"\"\"")
            (#offset! @injection.content 0 3 0 -3)
            (#set! "priority" 105)
            (#set! injection.language "markdown"))

(wild_attribute
  name: (attr_name
          name: (atom) @_doc)
          value: (string) @injection.content
            (#any-of? @_doc "moduledoc" "doc")
            (#match? @injection.content "^\"[^\"]")
            (#offset! @injection.content 0 1 0 -1)
            (#set! "priority" 105)
            (#set! injection.language "markdown"))

```

That should give you markdown highlight in your `-moduledoc` and `-doc` strings.

For the spell check in the doc string, it is the query in markdown `highlights.scm`, there should be a `(inline) @spell` query in your `~/.local/share/nvim/site/markdown/highlights.scm`. So as long as the above `injections` query matches, the markdown highlight and the spell check should work for you.
