Skip to content

Conversation

@sammarshallou
Copy link
Contributor

Adds an 'extensions' option to config which takes a comma-separated
list of extensions to add to the default set. Then adds --extensions
parameter to each command-line tool to specify this value.

This allows use of MathJax features such as displaying invalid TeX
instead of failing to render (--extensions TeX/noUndefined), and
stripping out dangerous links from MathML (--extensions Safe).

@sammarshallou
Copy link
Contributor Author

This follows on from #72. Here are some examples of usage with the 'noUndefined' TeX extension:

$ bin/tex2svg 'a^\frog'
TeX parse error: Undefined control sequence \frog

$ bin/tex2svg 'a^\frog' --extensions=TeX/noUndefined
<svg xmlns:xlink="http://www.w3.org/1999/xlink" ...

Or with the 'Safe' extension, for example with MathML:

$ bin/mml2svg '<math><mtext href="javascript:alert()">X</mtext></math>'
...
<a class="mjx-svg-href" href="javascript:alert()">
...

$ bin/mml2svg '<math><mtext href="javascript:alert()">X</mtext></math>' --extensions Safe
... (SVG code with no link) ...

lib/mj-single.js Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified as

window.MathJax.extensions.push(name+'.js');

@dpvc
Copy link
Member

dpvc commented Feb 15, 2015

This looks good, but I did make a couple of comments in the code.

Adds an 'extensions' option to config which takes a comma-separated
list of extensions to add to the default set. Then adds --extensions
parameter to each command-line tool to specify this value.

This allows use of MathJax features such as displaying invalid TeX
instead of failing to render (--extensions TeX/noUndefined), and
stripping out dangerous links from MathML (--extensions Safe).
@sammarshallou
Copy link
Contributor Author

Thanks for comments! I've amended my commit to include the 3 requested changes:

  1. array.push (don't understand why I wasn't doing that in the first place)
  2. I hadn't realised you could specify the extensions at top level, that does make the code an awful lot simpler!
  3. I made it allow .js

I retested it only using the examples I gave above (except I also tried adding .js this time), which is a bit less thorough than the testing I did last time but probably okay. Seems to still work...

dpvc added a commit that referenced this pull request Mar 20, 2015
Allow extensions to be specified on command line
@dpvc dpvc merged commit 209e09d into mathjax:develop Mar 20, 2015
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.

2 participants