badboy / mdbook-mermaid

A preprocessor for mdbook to add mermaid support
Mozilla Public License 2.0
306 stars 32 forks source link

Preprocessor alters the markdown in ways it shouldn't #13

Closed arg3t closed 2 years ago

arg3t commented 2 years ago

When trying to integrate this preprocessor into my workflow, I ran into an important issue. The preprocessor removes the <> characters and does some more changes, while it shouldn't do any changes to the file since no mermaid code blocks exist. Here is an example:

Before preprocessing:

## Big-Oh Notation

Big-Oh notation is a way of calculating the maximum time an algorithm can take relative to its input size. The two ways to calculate big-oh notation is:

#### The easy way
Basically, if you have a function that consists of different versions of the **7 important functions** the one with the highest order/the one that changes with the highest values have the highest precedence. So, for example, the function <span class="katex-inline">f(n) = 2n + n^2 + 3nlog_2(n) + 2^n + 6</span> has the Big-Oh <span class="katex-inline">O(2^n)</span> since exponential functions have the highest order. 

#### The big-boy mathematical way
The formal definition of Big-Oh is:
 <span class="katex-inline">f(n)</span> and <span class="katex-inline">g(n)</span> are both functions <span class="katex-inline">\mathbb{Z}^+ \mapsto \mathbb{R}^+</span>. <span class="katex-inline">f(n)</span> is <span class="katex-inline">O(g(n))</span> if there is a real constant <span class="katex-inline">c > 0</span> and an integer constant <span class="katex-inline">n_0 \geq 1</span> that makes <span class="katex-inline">f(n)</span> less than or equal to <span class="katex-inline">c \times g(n)</span> for all values <span class="katex-inline">n \geq n_0</span>. This can be written in predicate logic as such:[^1]

  <span class="katex-display">\exists c,n_0(\forall x(x \geq n_0 g \implies cg(x) \geq f(x))) \implies f(n) \in O(g(n))</span>

 ![Big-Oh Graph](/Images/Pastedimage20211112111455.png)

[^1]:$f(n) \in O(g(n))$ is a more mathematical way of saying $f(n)$ is $O(g(n))$.

<div class="datetime" style="text-align: center; color: gray; font-style: italic; font-size: 90%;">21:07 Tuesday 16 November 2021</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.13.18/dist/katex.min.css" integrity="sha384-zTROYFVGOfTw7JV7KUu8udsvW2fx4lWOsCEDqhBreBwlHI4ioVRtmIvEThzJHGET" crossorigin="anonymous">

<script defer src="https://cdn.jsdelivr.net/npm/katex@0.13.20/dist/katex.min.js" integrity="sha384-ov99pRO2tAc0JuxTVzf63RHHeQTJ0CIawbDZFiFTzB07aqFZwEu2pz4uzqL+5OPG" crossorigin="anonymous"></script>

<script>
document.addEventListener('DOMContentLoaded', function() {
    var math = document.querySelectorAll("[class^=katex]");
    for (var i = 0; i < math.length; i++) {
      // Convert escaped ampersands before rendering
      var toRender = math[i].textContent.replace(/&amp;/g, '&');
      katex.render(toRender, math[i]);
    }
}, false)
</script>

---

> - [7 Important Functions](<7 Important Functions.md>)
> - [Big Omega Notation](<Big-Omega Notation.md>)
> - [Big-Theta Notation](<Big-Theta Notation.md>)
> - [Heap](<Heap.md>)
> - [String Concatantion in Java](<String Concatanation in Java.md>)
> - [Tree Traversal](<Tree Traversal.md>)

After preprocessing:

## Big-Oh Notation

Big-Oh notation is a way of calculating the maximum time an algorithm can take relative to its input size. The two ways to calculate big-oh notation is:

#### The easy way

Basically, if you have a function that consists of different versions of the **7 important functions** the one with the highest order/the one that changes with the highest values have the highest precedence. So, for example, the function <span class=\"katex-inline\">f(n) = 2n + n^2 + 3nlog_2(n) + 2^n + 6</span> has the Big-Oh <span class=\"katex-inline\">O(2^n)</span> since exponential functions have the highest order. 

#### The big-boy mathematical way

The formal definition of Big-Oh is:
<span class=\"katex-inline\">f(n)</span> and <span class=\"katex-inline\">g(n)</span> are both functions <span class=\"katex-inline\">\\mathbb{Z}^+ \mapsto \mathbb{R}^+</span>. <span class=\"katex-inline\">f(n)</span> is <span class=\"katex-inline\">O(g(n))</span> if there is a real constant <span class=\"katex-inline\">c > 0</span> and an integer constant <span class=\"katex-inline\">n_0 \geq 1</span> that makes <span class=\"katex-inline\">f(n)</span> less than or equal to <span class=\"katex-inline\">c \times g(n)</span> for all values <span class=\"katex-inline\">n \geq n_0</span>. This can be written in predicate logic as such:[^1]

<span class=\"katex-display\">\\exists c,n_0(\forall x(x \geq n_0 g \implies cg(x) \geq f(x))) \implies f(n) \in O(g(n))</span>

![Big-Oh Graph](/Images/Pastedimage20211112111455.png)

[^1]: $f(n) \in O(g(n))$ is a more mathematical way of saying $f(n)$ is $O(g(n))$.

<div class=\"datetime\" style=\"text-align: center; color: gray; font-style: italic; font-size: 90%;\">21:07 Tuesday 16 November 2021</div>
<link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/katex@0.13.18/dist/katex.min.css\" integrity=\"sha384-zTROYFVGOfTw7JV7KUu8udsvW2fx4lWOsCEDqhBreBwlHI4ioVRtmIvEThzJHGET\" crossorigin=\"anonymous\">
<script defer src=\"https://cdn.jsdelivr.net/npm/katex@0.13.20/dist/katex.min.js\" integrity=\"sha384-ov99pRO2tAc0JuxTVzf63RHHeQTJ0CIawbDZFiFTzB07aqFZwEu2pz4uzqL+5OPG\" crossorigin=\"anonymous\"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
    var math = document.querySelectorAll(\"[class^=katex]\");
    for (var i = 0; i < math.length; i++) {
      // Convert escaped ampersands before rendering
      var toRender = math[i].textContent.replace(/&amp;/g, '&');
      katex.render(toRender, math[i]);
    }
}, false)
</script>

---

 > 
 > * [7 Important Functions](7 Important Functions.md)
 > * [Big Omega Notation](Big-Omega Notation.md)
 > * [Big-Theta Notation](Big-Theta Notation.md)
 > * [Heap](Heap.md)
 > * [String Concatantion in Java](String Concatanation in Java.md)
 > * [Tree Traversal](Tree Traversal.md)
badboy commented 2 years ago

There's a couple roundtripping issues with pulldown-cmark-to-cmark

It might indeed be easier to switch away from it and do the markdown modifications "manually".