-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run before-highlight and after-highlight hooks even when no grammar i…
…s found. Fix #1134
- Loading branch information
Showing
3 changed files
with
5 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70cb472
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Golmote This causes a bug in the show-invisibles plugin when used with the autoloader. The grammar is
undefined
, so attempting to add tokens to it fails. I can add a check in show-invisibles to make sure the grammar exists, but wondering if that's part of the "contract" of the hook. Should we able to rely on the existence ofenv.grammar
in plugins?70cb472
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mAAdhaTTah Currently,
element
is the only key inenv
that should always be properly set...code
andlanguage
might be empty strings (though still strings !), andgrammar
can indeed beundefined
.What are our options here? We could set
grammar
to the empty object instead, and use another special key to indicate the grammar does not exist in Prism... Or we could officially decidegrammar
is not safe to use in hooks without checking it's defined first...EDIT: Maybe we don't need another key... The Autoloader plugin could probably directly check
Prism.languages[language]
instead of relying ongrammar
.70cb472
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My PR (#1195) assumes that's the case for the show-invisibles plugin. However, there are a couple other plugins that assume
env.grammar
. If we're going to set that as the "contract" for hooks, then there are a few others to update.