Skip to content

Commit 3462f28

Browse files
zsparalleios
authored andcommitted
Fix C and C++ syntax highlighting, clean up codeblock indentation (#49)
* Fix C and C++ syntax highlighting * Unindent included codeblocks by default
1 parent 4125b6d commit 3462f28

File tree

12 files changed

+139
-128
lines changed

12 files changed

+139
-128
lines changed

book.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
"maxIndexSize": 1000000000
66
},
77
"pluginsConfig": {
8+
"include-codeblock": {
9+
"fixlang": true,
10+
"unindent": true
11+
},
812
"theme-api": {
913
"languages": [
1014
{

chapters/computational_mathematics/FFT/cooley_tukey.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,17 @@ For some reason, though, putting code to this transformation really helped me fi
9191

9292
{% method %}
9393
{% sample lang="jl" %}
94-
[import:2-11, unindent:"true", lang:"julia"](code/julia/fft.jl)
94+
[import:2-11, lang:"julia"](code/julia/fft.jl)
9595
{% sample lang="c" %}
96-
[import:2-11, unindent:"true", lang:"julia"](code/julia/fft.jl)
96+
[import:2-11, lang:"julia"](code/julia/fft.jl)
9797
{% sample lang="cpp" %}
98-
[import:2-11, unindent:"true", lang:"julia"](code/julia/fft.jl)
98+
[import:2-11, lang:"julia"](code/julia/fft.jl)
9999
{% sample lang="hs" %}
100-
[import:2-11, unindent:"true", lang:"julia"](code/julia/fft.jl)
100+
[import:2-11, lang:"julia"](code/julia/fft.jl)
101101
{% sample lang="py2" %}
102-
[import:2-11, unindent:"true", lang:"julia"](code/julia/fft.jl)
102+
[import:2-11, lang:"julia"](code/julia/fft.jl)
103103
{% sample lang="scratch" %}
104-
[import:2-11, unindent:"true", lang:"julia"](code/julia/fft.jl)
104+
[import:2-11, lang:"julia"](code/julia/fft.jl)
105105
{% endmethod %}
106106

107107
In this function, we define `n` to be a set of integers from $$0 \rightarrow N-1$$ and arrange them to be a column.
@@ -136,17 +136,17 @@ With recursion, we can reduce the complexity to $$\sim \mathcal{O}(n \log n)$$,
136136
In the end, the code looks like:
137137
{% method %}
138138
{% sample lang="jl" %}
139-
[import:14-31, unindent:"true", lang:"julia"](code/julia/fft.jl)
139+
[import:14-31, lang:"julia"](code/julia/fft.jl)
140140
{% sample lang="c" %}
141-
[import:13-35, unindent:"true", lang:"c_cpp"](code/c/fft.c)
141+
[import:13-35, lang:"c_cpp"](code/c/fft.c)
142142
{% sample lang="cpp" %}
143-
[import:19-44, unindent:"true", lang:"c_cpp"](code/c++/fft.cpp)
143+
[import:19-44, lang:"c_cpp"](code/c++/fft.cpp)
144144
{% sample lang="hs" %}
145-
[import:6-19, unindent:"true", lang:"haskell"](code/hs/fft.hs)
145+
[import:6-19, lang:"haskell"](code/hs/fft.hs)
146146
{% sample lang="py2" %}
147-
[import:5-16, unindent:"true", lang:"python"](code/python2/fft.py)
147+
[import:5-16, lang:"python"](code/python2/fft.py)
148148
{% sample lang="scratch" %}
149-
[import:14-31, unindent:"true", lang:"julia"](code/julia/fft.jl)
149+
[import:14-31, lang:"julia"](code/julia/fft.jl)
150150
{% endmethod %}
151151

152152
As a side note, we are enforcing that the array must be a power of 2 for the operation to work.
@@ -233,19 +233,19 @@ Note: I implemented this in Julia because the code seems more straightforward in
233233
{% method %}
234234
{% sample lang="jl" %}
235235
### Julia
236-
[import, unindent:"true", lang:"julia"](code/julia/fft.jl)
236+
[import, lang:"julia"](code/julia/fft.jl)
237237
{% sample lang="c" %}
238238
### C
239-
[import, unindent:"true", lang:"c_cpp"](code/c/fft.c)
239+
[import, lang:"c_cpp"](code/c/fft.c)
240240
{% sample lang="cpp" %}
241241
### C++
242-
[import, unindent:"true", lang:"c_cpp"](code/c++/fft.cpp)
242+
[import, lang:"c_cpp"](code/c++/fft.cpp)
243243
{% sample lang="hs" %}
244244
### Haskell
245-
[import, unindent:"true", lang:"haskell"](code/hs/fft.hs)
245+
[import, lang:"haskell"](code/hs/fft.hs)
246246
{% sample lang="py2" %}
247247
### Python
248-
[import, unindent:"true", lang:"python"](code/python2/fft.py)
248+
[import, lang:"python"](code/python2/fft.py)
249249
{% sample lang="scratch" %}
250250
### Scratch
251251
Some rather impressive scratch code was submitted by Jie and can be found here: https://scratch.mit.edu/projects/37759604/#editor

chapters/computational_mathematics/computational_geometry/gift_wrapping/graham_scan/graham_scan.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ We can find whether a rotation is counter-clockwise with trigonometric functions
3636

3737
{% method %}
3838
{% sample lang="pseudo" %}
39-
[import:1-7, unindent=true, lang:"julia"](code/pseudo/graham.pseudo)
39+
[import:1-7, lang:"julia"](code/pseudo/graham.pseudo)
4040
{% endmethod %}
4141

4242
If the output of this function is 0, the points are collinear.
@@ -52,7 +52,7 @@ In the end, the code should look something like this:
5252

5353
{% method %}
5454
{% sample lang="pseudo" %}
55-
[import:9-40, unindent=true, lang:"julia"](code/pseudo/graham.pseudo)
55+
[import:9-40, lang:"julia"](code/pseudo/graham.pseudo)
5656
{% endmethod %}
5757

5858
### Bibliography

chapters/computational_mathematics/computational_geometry/gift_wrapping/jarvis_march/jarvis_march.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Here is what this might look like in code:
3737

3838
{% method %}
3939
{% sample lang="pseudo" %}
40-
[import:1-32, unindent:"true", lang:"julia"](code/pseudo/jarvis.pseudo)
40+
[import:1-32, lang:"julia"](code/pseudo/jarvis.pseudo)
4141
{% endmethod %}
4242

4343
As we might expect, this algorithm is not incredibly efficient and has a runtime of $$\mathcal{O}(nh)$$, where $$n$$ is the number of points and $$h$$ is the size of the hull.

chapters/computational_mathematics/decision_problems/stable_marriage/stable_marriage.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ I am incredibly interested to see what you guys do and how you implement the alg
4444
{% method %}
4545
{% sample lang="jl" %}
4646
### Julia
47-
[import, unindent:"true", lang:"julia"](code/julia/stable_marriage.jl)
47+
[import, lang:"julia"](code/julia/stable_marriage.jl)
4848
{% sample lang="py" %}
4949
### Python
50-
[import, unindent:"true", lang:"python"](code/python/stable_marriage.py)
50+
[import, lang:"python"](code/python/stable_marriage.py)
5151
{% sample lang="hs" %}
5252
### Haskell
53-
[import, unindent:"true", lang:"haskell"](code/haskell/stableMarriage.hs)
53+
[import, lang:"haskell"](code/haskell/stableMarriage.hs)
5454
{% endmethod %}

chapters/computational_physics/verlet/verlet.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,33 +99,33 @@ Both of these methods work simply by iterating timestep-by-timestep and can be w
9999
{% method %}
100100
{% sample lang="cpp" %}
101101
### C++
102-
[import, unindent:"true", lang:"c_cpp"](code/c++/verlet.cpp)
102+
[import, lang:"c_cpp"](code/c++/verlet.cpp)
103103
{% sample lang="c" %}
104104
### C
105-
[import, unindent:"true", lang:"c_cpp"](code/c/verlet.c)
105+
[import, lang:"c_cpp"](code/c/verlet.c)
106106
{% sample lang="Java" %}
107107
### Java
108-
[import, unindent:"true", lang:"java"](code/java/verlet.java)
108+
[import, lang:"java"](code/java/verlet.java)
109109
{% sample lang="Python" %}
110110
### Python
111-
[import, unindent:"true", lang:"python"](code/python2/verlet.py)
111+
[import, lang:"python"](code/python2/verlet.py)
112112
{% sample lang="Haskell" %}
113113
### Haskell
114-
[import, unindent:"true", lang:"haskell"](code/haskell/verlet.hs)
114+
[import, lang:"haskell"](code/haskell/verlet.hs)
115115
{% sample lang="scratch" %}
116116
### Scratch
117117
Submitted by Jie
118118
![Scratch 2D implementation](code/scratch/verlet_scratch.png)
119119
Link: [https://scratch.mit.edu/projects/173039394/](https://scratch.mit.edu/projects/173039394/)
120120
{% sample lang="matlab" %}
121121
### Matlab
122-
[import, unindent:"true", lang:"matlab"](code/matlab/verlet.m)
122+
[import, lang:"matlab"](code/matlab/verlet.m)
123123
{% sample lang="LabVIEW" %}
124124
### LabVIEW
125125
Submitted by P. Mekhail
126126
![Verlet LabVIEW](code/labview/verlet_labview.png)
127127
{% sample lang="javascript" %}
128128
### JavaScript
129-
[import, unindent:"true", lang:"javascript"](code/javascript/verlet.js)
129+
[import, lang:"javascript"](code/javascript/verlet.js)
130130

131131
{% endmethod %}

chapters/fundamental_algorithms/euclidean_algorithm/euclidean.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@ The algorithm is a simple way to find the *greatest common divisor* (GCD) of two
2929

3030
{% method %}
3131
{% sample lang="c" %}
32-
[import:18-33, unindent:"true", lang="c_cpp"](code/c/euclidean_example.c)
32+
[import:18-33, lang="c_cpp"](code/c/euclidean_example.c)
3333
{% sample lang="cs" %}
34-
[import:6-17, unindent:"true", lang="csharp"](code/cs/EuclideanAlgorithmMdAdditional.cs)
34+
[import:6-17, lang="csharp"](code/cs/EuclideanAlgorithmMdAdditional.cs)
3535
{% sample lang="clj" %}
36-
[import:1-7, unindent:"true", lang="clojure"](code/clojure/euclidean_example.clj)
36+
[import:1-7, lang="clojure"](code/clojure/euclidean_example.clj)
3737
{% sample lang="cpp" %}
38-
[import:21-35, unindent:"true", lang="c_cpp"](code/c++/euclidean_example.cpp)
38+
[import:21-35, lang="c_cpp"](code/c++/euclidean_example.cpp)
3939
{% sample lang="js" %}
40-
[import:1-11, unindent:"true", lang="julia"](code/pseudo/euclidean.pseudo)
40+
[import:1-11, lang="julia"](code/pseudo/euclidean.pseudo)
4141
{% sample lang="py2" %}
42-
[import:1-11, unindent:"true", lang="julia"](code/pseudo/euclidean.pseudo)
42+
[import:1-11, lang="julia"](code/pseudo/euclidean.pseudo)
4343
{% sample lang="haskell" %}
44-
[import:1-11, unindent:"true", lang="julia"](code/pseudo/euclidean.pseudo)
44+
[import:1-11, lang="julia"](code/pseudo/euclidean.pseudo)
4545
{% sample lang="rs" %}
46-
[import:1-11, unindent:"true", lang="julia"](code/pseudo/euclidean.pseudo)
46+
[import:1-11, lang="julia"](code/pseudo/euclidean.pseudo)
4747
{% sample lang="ml" %}
48-
[import:1-11, unindent:"true", lang="julia"](code/pseudo/euclidean.pseudo)
48+
[import:1-11, lang="julia"](code/pseudo/euclidean.pseudo)
4949
{% sample lang="java" %}
50-
[import:1-11, unindent:"true", lang="julia"](code/pseudo/euclidean.pseudo)
50+
[import:1-11, lang="julia"](code/pseudo/euclidean.pseudo)
5151
{% endmethod %}
5252

5353
Here, we simply line the two numbers up every step and subtract the lower value from the higher one every timestep. Once the two values are equal, we call that value the greatest common divisor. A graph of `a` and `b` as they change every step would look something like this:
@@ -58,25 +58,25 @@ Modern implementations, though, often use the modulus operator (%) like so
5858

5959
{% method %}
6060
{% sample lang="c" %}
61-
[import:4-16, unindent:"true", lang="c_cpp"](code/c/euclidean_example.c)
61+
[import:4-16, lang="c_cpp"](code/c/euclidean_example.c)
6262
{% sample lang="cs" %}
63-
[import:19-29, unindent:"true", lang="csharp"](code/cs/EuclideanAlgorithmMdAdditional.cs)
63+
[import:19-29, lang="csharp"](code/cs/EuclideanAlgorithmMdAdditional.cs)
6464
{% sample lang="clj" %}
65-
[import:8-12, unindent:"true", lang="clojure"](code/clojure/euclidean_example.clj)
65+
[import:8-12, lang="clojure"](code/clojure/euclidean_example.clj)
6666
{% sample lang="cpp" %}
67-
[import:7-18, unindent:"true", lang="c_cpp"](code/c++/euclidean_example.cpp)
67+
[import:7-18, lang="c_cpp"](code/c++/euclidean_example.cpp)
6868
{% sample lang="js" %}
69-
[import:13-21, unindent:"true", lang="julia"](code/pseudo/euclidean.pseudo)
69+
[import:13-21, lang="julia"](code/pseudo/euclidean.pseudo)
7070
{% sample lang="py2" %}
71-
[import:13-21, unindent:"true", lang="julia"](code/pseudo/euclidean.pseudo)
71+
[import:13-21, lang="julia"](code/pseudo/euclidean.pseudo)
7272
{% sample lang="haskell" %}
73-
[import:13-21, unindent:"true", lang="julia"](code/pseudo/euclidean.pseudo)
73+
[import:13-21, lang="julia"](code/pseudo/euclidean.pseudo)
7474
{% sample lang="rs" %}
75-
[import:13-21, unindent:"true", lang="julia"](code/pseudo/euclidean.pseudo)
75+
[import:13-21, lang="julia"](code/pseudo/euclidean.pseudo)
7676
{% sample lang="ml" %}
77-
[import:13-21, unindent:"true", lang="julia"](code/pseudo/euclidean.pseudo)
77+
[import:13-21, lang="julia"](code/pseudo/euclidean.pseudo)
7878
{% sample lang="java" %}
79-
[import:13-21, unindent:"true", lang="julia"](code/pseudo/euclidean.pseudo)
79+
[import:13-21, lang="julia"](code/pseudo/euclidean.pseudo)
8080
{% endmethod %}
8181

8282
Here, we set `b` to be the remainder of `a%b` and `a` to be whatever `b` was last timestep. Because of how the modulus operator works, this will provide the same information as the subtraction-based implementation, but when we show `a` and `b` as they change with time, we can see that it might take many fewer steps:
@@ -90,32 +90,32 @@ The Euclidean Algorithm is truly fundamental to many other algorithms throughout
9090
{% method %}
9191
{% sample lang="c" %}
9292
### C
93-
[import, unindent:"true", lang="c_cpp"](code/c/euclidean_example.c)
93+
[import, lang="c_cpp"](code/c/euclidean_example.c)
9494
{% sample lang="cs" %}
9595
### C# #
96-
[import, unindent:"true", lang="csharp"](code/cs/EuclideanAlgorithmMdAdditional.cs)
96+
[import, lang="csharp"](code/cs/EuclideanAlgorithmMdAdditional.cs)
9797
{% sample lang="clj" %}
9898
### Clojure
99-
[import, unindent:"true", lang="clojure"](code/clojure/euclidean_example.clj)
99+
[import, lang="clojure"](code/clojure/euclidean_example.clj)
100100
{% sample lang="cpp" %}
101101
### Cpp
102-
[import, unindent:"true", lang="c_cpp"](code/c++/euclidean_example.cpp)
102+
[import, lang="c_cpp"](code/c++/euclidean_example.cpp)
103103
{% sample lang="js" %}
104104
### JavaScript
105-
[import, unindent:"true", lang="javascript"](code/javascript/euclidean_example.js)
105+
[import, lang="javascript"](code/javascript/euclidean_example.js)
106106
{% sample lang="py2" %}
107107
### Python
108-
[import, unindent:"true", lang="python"](code/python2/euclidean_example.py)
108+
[import, lang="python"](code/python2/euclidean_example.py)
109109
{% sample lang="haskell" %}
110110
### Haskell
111-
[import, unindent:"true", lang="haskell"](code/haskell/euclidean_example.hs)
111+
[import, lang="haskell"](code/haskell/euclidean_example.hs)
112112
{% sample lang="rs" %}
113113
### Rust
114-
[import, unindent:"true", lang="rust"](code/rust/euclidean_example.rs)
114+
[import, lang="rust"](code/rust/euclidean_example.rs)
115115
{% sample lang="ml" %}
116116
### Ocaml
117-
[import, unindent:"true", lang="ocaml"](code/ocaml/euclidean_example.ml)
117+
[import, lang="ocaml"](code/ocaml/euclidean_example.ml)
118118
{% sample lang="java" %}
119119
### Java
120-
[import, unindent:"true", lang="java"](code/java/euclidean_example.jar)
120+
[import, lang="java"](code/java/euclidean_example.jar)
121121
{% endmethod %}

chapters/fundamental_algorithms/sorting_searching/bogo/bogo_sort.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ function bogo_sort(Vector{Type} a)
4545
end
4646
```
4747
{% sample lang="cs" %}
48-
[import:29-35, unindent=true, lang:"csharp"](code/cs/bogo.cs)
48+
[import:29-35, lang:"csharp"](code/cs/bogo.cs)
4949
{% sample lang="clj" %}
50-
[import:6-10, unindent=true, lang:"clojure"](code/clojure/bogo.clj)
50+
[import:6-10, lang:"clojure"](code/clojure/bogo.clj)
5151
{% endmethod %}
5252

5353
That's it.

chapters/fundamental_algorithms/sorting_searching/bubble/bubble_sort.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function bubble_sort(Vector{Type} a)
4545
end
4646
```
4747
{% sample lang="cs" %}
48-
[import:9-27, unindent:"true", lang:"csharp"](code/cs/Sorting.cs)
48+
[import:9-27, lang:"csharp"](code/cs/Sorting.cs)
4949
{% endmethod %}
5050

5151
... And that's it for the simplest bubble sort method.

0 commit comments

Comments
 (0)