How to tell tumblr to stop making changes to the markdown and/or HTML code?
Asked Answered
C

1

7

tl;dr: tumblr makes changes to the markdown and HTML code. If you write &lt; into the markdown code and reload it, it will be replaced by < and break things. If you use however the HTML editor and place something like an &, which you might need with mathjax, it will be replaced by &amp; and eventually break your tables/matrices.

How can this be avoided?


I am starting to use tumblr and I added

    <!-- Syntax highlighting -->
    <link rel="stylesheet" href="http://yandex.st/highlightjs/7.2/styles/default.min.css">

    <script src="http://yandex.st/highlightjs/7.2/highlight.min.js">
    </script>

    <script>
        hljs.initHighlightingOnLoad();
    </script>

    <!-- Mathjax LaTeX Mode -->
    <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
    </script>

to be able to use Mathjax and highlightjs. However, the problem is if I use the HTML editor of tumblr and enter this:

$$
\left[
  \begin{array}{cc|c}
    1 & 2 & 3<br>
    4 & 5 & 6
  \end{array}
\right]
$$

</p><pre><code>public class Main {
    public static void main(String[] args) {
        System.out.println(”Hello World!”);
    }       
}
</code></pre></p>

tumblr will always replace the & with &amp; which does not work and results in the matrix being rendered not as I intended it:

enter image description here

Is it somehow possible to get syntax highlighting and mathjax to work?

Another problem appears to be something like:

$$ 
\begin{bmatrix}a & b \\\\\ c & d\end{bmatrix}
$$

If I use this for the markdown editor the matrix gets correctly rendered. However, switching to the HTML editor and editing and saving changes there will remove some backslashes and leave just \\\ which then breaks again the matrix.

Also if I write

<pre><code>
for(x = 0; x &lt; myString.length; x++) {
    // Do stuff
}
</code></pre>

in markdown, save it and reload it.. the &lt; gets replaced by <. Saving it again will break the markdown because < is then interpreted as the opening bracket for another HTML tag.

Can I somehow tell tumblr to not do this?

Criticize answered 11/4, 2016 at 12:39 Comment(5)
I am trying to set up my blog in tumblr as well and having a similar problem right now. &'s and \\'s which are fundamental in writing math and as you mention tumblr just interferes with that. Have you come across a solution on this issue yet? Also I think the same issue with &'s and \\'s persist in markdown in tumblr as well, right?Liston
@YBE No sorry, I haven't found a solution for this issue unfortunately :/Criticize
@YBE I just sent an issue report to tumblr - not sure if the will consider it though.Criticize
HTML? Are you sure it's not something else? Like XHTML, or a different UTF?Divisibility
Note from the future: cdn.mathjax.org is nearing its end-of-life, check mathjax.org/cdn-shutting-down for migration tips.Valonia
H
1

In your head (right before </head>), put this:

<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']],
                           displayMath: [['\\[','\\]'], ['$$','$$']]}});
</script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>

Then, instead of \\, write \\\. For example:

$$
\left[
  \begin{array}{cc|c}
    1 & 2 & 3
    \\\4 & 5 & 6
  \end{array}
\right]
$$

Ultimately, I think you should stop doing your editing in Tumblr itself, as the editor will continue to modify your text and there is no real way to stop this. You could make it change it back (as the header above does to some extent) but within the actual editor it will still be messed up.

I would recommend using an external embeddable editor with custom language-specific syntax highlighting. My personal favorite is hilite.me. I have tested this on Tumblr and can confirm that it works.

There are alternatives to MathJax that may work better on Tumblr. But that was not your question.

I think you are probably going to find yourself very limited by the Tumblr text editor, particularly if you plan to switch between modes (Markdown, HTML, RichText). You can find more discussion here. My best guess is that Tumblr takes control away from the user for LangSec reasons (the keynote talk at Blackhat 2016 was in part about how apparently MySpace got pwnd through LangSec problems because they didn't parse or strip html in posts), and I think at a certain point you just hit a wall that can't be overcome. Since I'm a snarky internet person, I'd recommend you check out platforms which are nicer to coders, such as SVBTL. Or just use GitHub pages and build your own website, like I did (link to site).

I would absolutely recommend considering alternatives to MathJax. See more here. You may be able to embed from Mathematica. In a worst case scenario, you could use MathURL.

Sorry I don't have a solution for you. I really don't think there is a conclusive solution at this point in time. Math editing in Tumblr appears to be intrinsically broken, and you can hack your way around different specific issues but it will still break itself when you switch editors. Good luck.

Hipbone answered 12/11, 2016 at 19:13 Comment(4)
thanks for the answer. Yeah, it looks like tumblr is not the best fit here. I am already using html for my own website but just using tumblr for general blogging purposes seemed to be the most practical way to me. But if writing math is going to be impractical, there is no reason pursuing tumblr any further. I will check out your recommendations as well. Best - ybeListon
Making a website from scratch with GitHub pages is far easier than it sounds, and inexpensive or free depending on domain name requirements. I would definitely recommend looking into that avenue if you're not already too invested in Tumblr. I'm just coding in raw HTML from scratch, but there are plenty of tutorials on how to generate your website dynamically using Jackyl Markdown, and I think that could be a really good route for you. Good luck!Hipbone
You could also edit everything offline in an editor like Sublime Text or Macdown, and save local copies. Then if you want to edit a post after your post it, edit it from the local copy, and replace all the text in the post with your new locally saved markdown. That way you don't have to worry about things getting wacky when you return to edit them.Hipbone
Note from the future: cdn.mathjax.org is nearing its end-of-life, check mathjax.org/cdn-shutting-down for migration tips.Valonia

© 2022 - 2024 — McMap. All rights reserved.