-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix for DFS bug with new pattern array feature #360
Conversation
This patch implements support for the new pattern array feature in the Prism.languages.DFS function and fixes a bug in the autolinker plugin. It adds an optional parameter to the callback of Prism.languages.DFS, which contains the type of the current object as oposed to the key in the parent. In most cases both key and type are exactly the same. Only if the parent is an array the key will contain the index number and the type will contain the attribute name of the array in the parent object. The key can be used to replace the object in the parent and the type can be used to provide the necessary context.
c9d853b
to
08037e5
Compare
@@ -96,12 +96,16 @@ var _ = self.Prism = { | |||
}, | |||
|
|||
// Traverse a language definition with Depth First Search | |||
DFS: function(o, callback) { | |||
DFS: function(o, callback, type) { | |||
for (var i in o) { |
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.
I know it's not part of this PR, but could we please update the internal variable names to something more meaningful than i
and o
. We now have automatic minification, so no need to make our life hard here. 😉
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.
PS: didn't know that hasOwnProperty
also works for array indexes...
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.
I'm generally all for descriptive names, but I believe those are established convention for this kind of thing. No?
Sent from my iPhone. Please excuse weird typos and/or terseness.
On 22 Sep 2014, at 09:00, Jannik Zschiesche [email protected] wrote:
In components/prism-core.js:
@@ -96,12 +96,16 @@ var _ = self.Prism = {
},// Traverse a language definition with Depth First Search
DFS: function(o, callback) {
I know it's not part of this PR, but could we please update the internal variable names to something more meaningful than i and o. We now have automatic minification, so no need to make our life hard here.DFS: function(o, callback, type) { for (var i in o) {
—
Reply to this email directly or view it on GitHub.
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.
Yes, but at least for me i
always is an array index, although o
doesn't have to be an array...
for (var rule in ruleset)
would probably make it more readable? But it might very well be that this is just me personal preference. 😉
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.
I agree the use of i
is a bit confusing. But the more important issue is if you like the solution to the problem. It is a bit tricky and I am not sure if that is the best solution, but it is quite urgent. Because of this bug the autolinker plugin is completely broken and a lot of people have complained already (#359, #363). Apparantly a common Wordpress plugin automatically packages the autolinker plugin and so Prism is broken on Wordpress...
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.
It looks fine for now, but I need to take a closer look. Will try to do it tomorrow.
The code could be a bit more elegant (e.g. by using a ternary operator in the 3rd arg) but LGTM for now, especially given that this bug is pressing! Merging. Thanks @zeitgeist87 for working on this! |
Fix for DFS bug with new pattern array feature
This patch implements support for the new pattern array feature in the
Prism.languages.DFS function and fixes a bug in the autolinker plugin #359.
It adds an optional parameter to the callback of Prism.languages.DFS,
which contains the type of the current object as oposed to the key in
the parent. In most cases both key and type are exactly the same. Only
if the parent is an array the key will contain the index number and the
type will contain the attribute name of the array in the parent object.
The key can be used to replace the object in the parent and the type can
be used to provide the necessary context.