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

Autolinker not functioning (on prismjs.com) #359

Closed
adaminfinitum opened this issue Sep 5, 2014 · 7 comments
Closed

Autolinker not functioning (on prismjs.com) #359

adaminfinitum opened this issue Sep 5, 2014 · 7 comments

Comments

@adaminfinitum
Copy link

On http://prismjs.com/plugins/autolinker/ the examples aren't working (and it's a weird white text on white background that is only visible due to text shadow--okaida theme, default looks fine).

The console reads Uncaught TypeError: undefined is not a function at /prism.js:249

@uranusjr
Copy link
Contributor

uranusjr commented Sep 5, 2014

Which is exactly the same statement with #358. I did a quick debugging and the problem seems to be in prism-core.js, around these lines:

var patterns = grammar[token];
patterns = (_.util.type(patterns) === "Array") ? patterns : [patterns];

in which grammar[token] is not an Array but a wrapper for it. The relevant lines should be

var patterns = grammar[token].tokens;
patterns = (_.util.type(patterns) === "Array") ? patterns : [patterns];

I don’t know enough about Prism’s internals to determine whether this should be fixed here or where things are fed into grammar instead.

@adaminfinitum
Copy link
Author

@uranusjr It looks like you have a pretty good idea of the problem, why not submit a pull request?

@uranusjr
Copy link
Contributor

uranusjr commented Sep 5, 2014

As I said in the last paragraph, I don’t know enough about Prism’s internals. I’m not even confident that my “fix” is correct.

@adaminfinitum
Copy link
Author

Right, but the author can decide if it is or not. In the 'contributing' section the author asks people to submit small patches that address single issues. Yours is perfect and even if it isn't correct it probably provides a better starting place than my issue which was basically just "it's broken."

I encourage you to submit a pull request with a commit message explaining your doubts.

@dkanicki
Copy link

dkanicki commented Sep 5, 2014

If the fix would be to replace just the one line

var patterns = grammar[token];
with
var patterns = grammar[token].tokens;

I tried it in my local environment and ... it doesn't work :(

@zeitgeist87
Copy link
Collaborator

There is a new feature, where you can add multiple patterns in the form of an array to one token type. This causes the problem, because autolinker uses Prism.languages.DFS to traverse the language and Prism.languages.DFS doesn't account for the new feature. The best fix would be to fix DFS. Since I implemented the array feature I will fix this and make a PR.

@LeaVerou
Copy link
Member

Closing, see #425

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

No branches or pull requests

5 participants