Skip to content
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

Merged
merged 1 commit into from
Sep 22, 2014

Conversation

zeitgeist87
Copy link
Collaborator

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.

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.
@@ -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) {
Copy link
Contributor

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. 😉

Copy link
Contributor

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...

Copy link
Member

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) {
    
  •   DFS: function(o, callback, type) {
        for (var i in o) {
    
    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.


Reply to this email directly or view it on GitHub.

Copy link
Contributor

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. 😉

Copy link
Collaborator Author

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...

Copy link
Contributor

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.

@LeaVerou
Copy link
Member

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!

LeaVerou added a commit that referenced this pull request Sep 22, 2014
Fix for DFS bug with new pattern array feature
@LeaVerou LeaVerou merged commit 6a004cb into PrismJS:gh-pages Sep 22, 2014
@Golmote Golmote mentioned this pull request Dec 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants