Skip to content

Commit

Permalink
feat!: move to new/improved metadata parser, change highlight queries
Browse files Browse the repository at this point in the history
  • Loading branch information
vhyrro committed May 28, 2023
1 parent 360f8d6 commit 962e45a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
1 change: 1 addition & 0 deletions lua/neorg/modules/core/highlights/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ module.config.public = {
document_meta = {
key = "+@field",
value = "+@string",
number = "+@number",
trailing = "+@repeat",
title = "+@text.title",
description = "+@label",
Expand Down
8 changes: 6 additions & 2 deletions lua/neorg/modules/core/integrations/treesitter/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ module.config.public = {
url = "https://github.com/nvim-neorg/tree-sitter-norg-meta",
files = { "src/parser.c" },
branch = "main",
revision = "e93dcbc56a472649547cfc288f10ae4a93ef8795",
revision = "a479d1ca05848d0b51dd25bc9f71a17e0108b240",
},
},
}
Expand Down Expand Up @@ -562,6 +562,7 @@ module.public = {

return descendant
end,

get_document_metadata = function(buf, no_trim)
buf = buf or 0

Expand Down Expand Up @@ -601,9 +602,12 @@ module.public = {

local function parse_data(node)
return neorg.lib.match(node:type())({
value = function()
string = function()
return trim(module.public.get_node_text(node, buf))
end,
number = function()
return tonumber(module.public.get_node_text(node, buf))
end,
array = function()
local resulting_array = {}

Expand Down
27 changes: 11 additions & 16 deletions queries/norg_meta/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
; Regular keys and values
(key) @neorg.tags.ranged_verbatim.document_meta.key
(value) @neorg.tags.ranged_verbatim.document_meta.value

; Values within arrays
(array
(value) @neorg.tags.ranged_verbatim.document_meta.array.value
)
(string) @neorg.tags.ranged_verbatim.document_meta.string
(number) @neorg.tags.ranged_verbatim.document_meta.number

; Literals
"{" @neorg.tags.ranged_verbatim.document_meta.object.bracket
"}" @neorg.tags.ranged_verbatim.document_meta.object.bracket
"[" @neorg.tags.ranged_verbatim.document_meta.array.bracket
"]" @neorg.tags.ranged_verbatim.document_meta.array.bracket
"~\n" @neorg.tags.ranged_verbatim.document_meta.trailing

; Special Highlights
(pair
(key) @_key
(value) @neorg.tags.ranged_verbatim.document_meta.title
(string) @neorg.tags.ranged_verbatim.document_meta.title
(#eq? @_key "title")
)

(pair
(key) @_key
(value) @neorg.tags.ranged_verbatim.document_meta.description
(string) @neorg.tags.ranged_verbatim.document_meta.description
(#eq? @_key "description")
)

(pair
(key) @_key
[
(value) @neorg.tags.ranged_verbatim.document_meta.authors
(string) @neorg.tags.ranged_verbatim.document_meta.authors
(array
(value) @neorg.tags.ranged_verbatim.document_meta.authors
(string) @neorg.tags.ranged_verbatim.document_meta.authors
)
]
(#eq? @_key "authors")
Expand All @@ -41,28 +36,28 @@
(pair
(key) @_key
[
(value) @neorg.tags.ranged_verbatim.document_meta.categories
(string) @neorg.tags.ranged_verbatim.document_meta.categories
(array
(value) @neorg.tags.ranged_verbatim.document_meta.categories
(string) @neorg.tags.ranged_verbatim.document_meta.categories
)
]
(#eq? @_key "categories")
)

(pair
(key) @_key
(value) @neorg.tags.ranged_verbatim.document_meta.created
(string) @neorg.tags.ranged_verbatim.document_meta.created
(#eq? @_key "created")
)

(pair
(key) @_key
(value) @neorg.tags.ranged_verbatim.document_meta.updated
(string) @neorg.tags.ranged_verbatim.document_meta.updated
(#eq? @_key "updated")
)

(pair
(key) @_key
(value) @neorg.tags.ranged_verbatim.document_meta.version
(string) @neorg.tags.ranged_verbatim.document_meta.version
(#eq? @_key "version")
)

0 comments on commit 962e45a

Please sign in to comment.