fix: dockerfile tooltips should match only keywords

Before this change, the Dockerfile tooltip script marked all occurences
of keywords, as defined by the lexer, as Dockerfile instructions in a
`dockerfile` code block. This meant some tokens parsed from heredocs
would be included. The matched keyword token is now compared against a
hard-coded list of actual Dockerfile instructions before they're
annotated.

Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
This commit is contained in:
David Karlsson 2024-01-12 12:14:18 +01:00
parent dbd27bd7c8
commit 91a2200a11
1 changed files with 22 additions and 1 deletions

View File

@ -1,4 +1,25 @@
const cmds = document.querySelectorAll(".language-dockerfile span.k"); const keywords = [
"ADD",
"ARG",
"CMD",
"COPY",
"ENTRYPOINT",
"ENV",
"EXPOSE",
"FROM",
"HEALTHCHECK",
"LABEL",
// "MAINTAINER",
"ONBUILD",
"RUN",
"SHELL",
"STOPSIGNAL",
"USER",
"VOLUME",
"WORKDIR",
]
const cmds = Array.from(document.querySelectorAll(".language-dockerfile span.k"))
.filter((el) => keywords.some(kwd => el.textContent.includes(kwd)));
for (const cmd of cmds) { for (const cmd of cmds) {
const name = cmd.textContent; const name = cmd.textContent;