1
$\begingroup$

Context

So @rsmenon's pygments-mathematica looks awesome. Admittedly I still use minted for $\LaTeX$ documents...

Anyway, I would like to add some Mathematica syntax highlighting for a few static webpages (built without Jekyll, Octopress, or whatever else there is).

At first I looked at and tried, highlightjs.org. However the syntax highlighting for Mathematica is clearly worse than that of @rsmenon's (nor are there any css files that resemble the Mathematica Notebook).

So following the instructions on the GitHub page:

pip install pygments-mathematica

for installation and then:

pygmentize -O full,style=mathematica -f html -l wl -o package.html package.m

for conversion.

While this did run without any errors, the results were not as expected.

Using the liquid tags method to see if I could just convert the code already in an html file, I got:

enter image description here

which would not be so bad, if it didn't also convert the entire html file into static text.

I then also tried code in a plain text file, from a notebook, and from a .m file. The plain text file just spat out what I expected, which works, the notebook did not fair too well, and the package came out all commented...

Question

I was just curious as to if there was a more verbose explanation as to how to use this page for webpages. Should I just copy-paste the code into a text file, run pygments and then copy paste the result into the html? Is there a way to run pygments on html without having the html affected, and only the liquid tagged code translated?

Update

Following @R. M.♦ suggestion:

I downloaded the master branch from google/code-prettify and halirutan's Mathematica-Source-Highlighting.

Following the instructions on halirutan's readme, I added the file lang-mms.min.js to google-code-prettify/src and prettify-mms.min.css to the styles folder.

Following google's demonstration, I source code-prettify:

<script src="../../../../source/code-prettify-master/loader/run_prettify.js"></script>

and then use the appropriate tags:

<pre class="prettyprint lang-mma">
  GetSampleRecord[dataset_Dataset] := First@Normal@First@dataset
  GetSampleRecord[dataset_List] := First@First@Rest@dataset
  (*Assumes the the first sublist is a list of column headers*)
</pre>

However the color highlighting does not match that which is rendered by Mathematica Stack-exchange. What am I doing wrong?

$\endgroup$

closed as off-topic by SumNeuron, MarcoB, m_goldberg, happy fish, ciao Feb 13 '17 at 10:43

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "The question is out of scope for this site. The answer to this question requires either advice from Wolfram support or the services of a professional consultant." – SumNeuron, MarcoB, m_goldberg, happy fish, ciao
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ If you only have HTML, then you don't need to use pygments. You can use halirutan's Javascript syntax highlighter for Mathematica that is based on the Prettify framework. That should work well right out of the box and you should have almost the same output. $\endgroup$ – rm -rf Feb 12 '17 at 1:21
  • $\begingroup$ @R.M. please see update. $\endgroup$ – SumNeuron Feb 12 '17 at 9:59
  • $\begingroup$ I don't know what's wrong. You haven't shown your setup, your site structure, etc. so it's possible that you're sourcing incorrectly or something with JQuery not firing... either way, I think that this is out of scope for this site because it is not really about Mathematica (coming to think of it, it was off-topic to begin with, since pygments is not applicable here). You could probably ping halirutan in chat. He is very helpful and responsive, so you could probably resolve it quicker in there :) $\endgroup$ – rm -rf Feb 12 '17 at 21:50
  • $\begingroup$ @R.M. will do and Ill close this thread $\endgroup$ – SumNeuron Feb 13 '17 at 4:17