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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions components/prism-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

callback.call(o, i, o[i]);
if (o.hasOwnProperty(i)) {
callback.call(o, i, o[i], type || i);

if (_.util.type(o) === 'Object') {
_.languages.DFS(o[i], callback);
if (_.util.type(o[i]) === 'Object') {
_.languages.DFS(o[i], callback);
} else if (_.util.type(o[i]) === 'Array') {
_.languages.DFS(o[i], callback, i);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/prism-core.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions plugins/autolinker/prism-autolinker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ var url = /\b([a-z]{3,7}:\/\/|tel:)[\w-+%~/.:#=?&]+/,
for (var language in Prism.languages) {
var tokens = Prism.languages[language];

Prism.languages.DFS(tokens, function (type, def) {
if (candidates.indexOf(type) > -1) {
Prism.languages.DFS(tokens, function (key, def, type) {
if (candidates.indexOf(type) > -1 && Prism.util.type(def) !== 'Array') {
if (!def.pattern) {
def = this[type] = {
def = this[key] = {
pattern: def
};
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/autolinker/prism-autolinker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,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) {
callback.call(o, i, o[i]);
if (o.hasOwnProperty(i)) {
callback.call(o, i, o[i], type || i);

if (_.util.type(o) === 'Object') {
_.languages.DFS(o[i], callback);
if (_.util.type(o[i]) === 'Object') {
_.languages.DFS(o[i], callback);
} else if (_.util.type(o[i]) === 'Array') {
_.languages.DFS(o[i], callback, i);
}
}
}
}
Expand Down