Skip to content

Commit 36c5332

Browse files
author
Gregory Cox
committed
Post-process pandoc output to add chapters class to chapter list
1 parent 3f12006 commit 36c5332

18 files changed

+255
-247
lines changed

markdown/generate.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ do
5454
--metadata title="${title[$i]}$titlesuffix" \
5555
-V prev_title="$prev_title" -V prev_filename=$prev_filename \
5656
-V next_title="$next_title" -V next_filename=$next_filename \
57-
-o generated_html/${filename[$i]}.html source_md/${filename[$i]}.md
57+
-o generated_html/${filename[$i]}.html source_md/${filename[$i]}.md
58+
59+
sed '/<p><img/ { N; N; N; s#<p>\(<img[^>]*\) /></p>#\1># }
60+
s# />#>#' -i generated_html/${filename[$i]}.html
5861
done
5962

6063
cat source_md/chapters_foot.md >>$chapterfile
@@ -63,6 +66,11 @@ pandoc -d config/pandoc-defaults.yml --template=config/template.html \
6366
-V title="Chapters" --metadata title="${title[$i]}$titlesuffix" \
6467
-o generated_html/chapters.html $chapterfile
6568

69+
sed 's/<ol/<ol class="chapters"/' -i generated_html/chapters.html
70+
6671
pandoc -d config/pandoc-defaults.yml --template=config/template.html \
6772
-V faq=true -V title="FAQ" --metadata title="${title[$i]}$titlesuffix" \
6873
-o generated_html/faq.html source_md/faq.md
74+
75+
sed '/<p><img/ { N; N; N; s#<p>\(<img[^>]*\) /></p>#\1># }
76+
s# />#>#' -i generated_html/faq.html

markdown/generated_html/a-fistful-of-monads.html

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ <h1 id="a-fistful-of-monads">A Fistful of Monads</h1>
4141
<p>In this chapter, we’ll learn about monads, which are just beefed up
4242
applicative functors, much like applicative functors are only beefed up
4343
functors.</p>
44-
<p><img src="assets/images/a-fistful-of-monads/smugpig.png"
45-
class="right" width="307" height="186" alt="more cool than u" /></p>
44+
<img src="assets/images/a-fistful-of-monads/smugpig.png"
45+
class="right" width="307" height="186" alt="more cool than u">
4646
<p>When we started off with functors, we saw that it’s possible to map
4747
functions over various data types. We saw that for this purpose, the
4848
<code>Functor</code> type class was introduced and it had us asking the
@@ -119,8 +119,8 @@ <h1 id="a-fistful-of-monads">A Fistful of Monads</h1>
119119
that it’s easy as one two three.</p>
120120
<h2 id="getting-our-feet-wet-with-maybe">Getting our feet wet with
121121
Maybe</h2>
122-
<p><img src="assets/images/a-fistful-of-monads/buddha.png" class="left"
123-
width="302" height="387" alt="monads, grasshoppa" /></p>
122+
<img src="assets/images/a-fistful-of-monads/buddha.png" class="left"
123+
width="302" height="387" alt="monads, grasshoppa">
124124
<p>Now that we have a vague idea of what monads are about, let’s see if
125125
we can make that idea a bit less vague.</p>
126126
<p>Much to no one’s surprise, <code>Maybe</code> is a monad, so let’s
@@ -264,8 +264,8 @@ <h2 id="the-monad-type-class">The Monad type class</h2>
264264

265265
fail :: String -&gt; m a
266266
fail msg = error msg</code></pre>
267-
<p><img src="assets/images/a-fistful-of-monads/kid.png" class="right"
268-
width="363" height="451" alt="this is you on monads" /></p>
267+
<img src="assets/images/a-fistful-of-monads/kid.png" class="right"
268+
width="363" height="451" alt="this is you on monads">
269269
<p>Let’s start with the first line. It says
270270
<code>class Monad m where</code>. But wait, didn’t we say that monads
271271
are just beefed up applicative functors? Shouldn’t there be a class
@@ -294,8 +294,8 @@ <h2 id="the-monad-type-class">The Monad type class</h2>
294294
function execution or anything, it just takes a normal value and puts it
295295
in a context.</p>
296296
</div>
297-
<p><img src="assets/images/a-fistful-of-monads/tur2.png" class="left"
298-
width="169" height="145" alt="hmmm yaes" /></p>
297+
<img src="assets/images/a-fistful-of-monads/tur2.png" class="left"
298+
width="169" height="145" alt="hmmm yaes">
299299
<p>The next function is <code>&gt;&gt;=</code>, or bind. It’s like
300300
function application, only instead of taking a normal value and feeding
301301
it to a normal function, it takes a monadic value (that is, a value with
@@ -348,8 +348,8 @@ <h2 id="the-monad-type-class">The Monad type class</h2>
348348
result of using <code>&gt;&gt;=</code> will be <code>Nothing</code> as
349349
well.</p>
350350
<h2 id="walk-the-line">Walk the line</h2>
351-
<p><img src="assets/images/a-fistful-of-monads/pierre.png" class="left"
352-
width="374" height="405" alt="pierre" /></p>
351+
<img src="assets/images/a-fistful-of-monads/pierre.png" class="left"
352+
width="374" height="405" alt="pierre">
353353
<p>Now that we know how to feed a <code>Maybe a</code> value to a
354354
function of type <code>a -&gt; Maybe b</code> while taking into account
355355
the context of possible failure, let’s see how we can use
@@ -518,8 +518,8 @@ <h2 id="walk-the-line">Walk the line</h2>
518518
(<code>&gt;&gt;=</code>) instead of normal application:</p>
519519
<pre class="haskell:hs"><code>ghci&gt; return (0,0) &gt;&gt;= landLeft 1 &gt;&gt;= landRight 4 &gt;&gt;= landLeft (-1) &gt;&gt;= landRight (-2)
520520
Nothing</code></pre>
521-
<p><img src="assets/images/a-fistful-of-monads/banana.png" class="right"
522-
width="262" height="130" alt="iama banana" /></p>
521+
<img src="assets/images/a-fistful-of-monads/banana.png" class="right"
522+
width="262" height="130" alt="iama banana">
523523
<p>Awesome. The final result represents failure, which is what we
524524
expected. Let’s see how this result was obtained. First,
525525
<code>return</code> puts <code>(0,0)</code> into a default context,
@@ -600,8 +600,8 @@ <h2 id="walk-the-line">Walk the line</h2>
600600
Just pole2 -&gt; case landLeft 2 pole2 of
601601
Nothing -&gt; Nothing
602602
Just pole3 -&gt; landLeft 1 pole3</code></pre>
603-
<p><img src="assets/images/a-fistful-of-monads/centaur.png"
604-
class="right" width="297" height="331" alt="john joe glanton" /></p>
603+
<img src="assets/images/a-fistful-of-monads/centaur.png"
604+
class="right" width="297" height="331" alt="john joe glanton">
605605
<p>We land a bird on the left and then we examine the possibility of
606606
failure and the possibility of success. In the case of failure, we
607607
return a <code>Nothing</code>. In the case of success, we land birds on
@@ -684,8 +684,8 @@ <h2 id="do-notation">do notation</h2>
684684
x &lt;- Just 3
685685
y &lt;- Just &quot;!&quot;
686686
Just (show x ++ y)</code></pre>
687-
<p><img src="assets/images/a-fistful-of-monads/owld.png" class="right"
688-
width="269" height="348" alt="90s owl" /></p>
687+
<img src="assets/images/a-fistful-of-monads/owld.png" class="right"
688+
width="269" height="348" alt="90s owl">
689689
<p>It would seem as though we’ve gained the ability to temporarily
690690
extract things from <code>Maybe</code> values without having to check if
691691
the <code>Maybe</code> values are <code>Just</code> values or
@@ -841,8 +841,8 @@ <h2 id="do-notation">do notation</h2>
841841
of our monad instead of causing a program-wide failure, which is pretty
842842
neat.</p>
843843
<h2 id="the-list-monad">The list monad</h2>
844-
<p><img src="assets/images/a-fistful-of-monads/deadcat.png" class="left"
845-
width="235" height="230" alt="dead cat" /></p>
844+
<img src="assets/images/a-fistful-of-monads/deadcat.png" class="left"
845+
width="235" height="230" alt="dead cat">
846846
<p>So far, we’ve seen how <code>Maybe</code> values can be viewed as
847847
values with a failure context and how we can incorporate failure
848848
handling into our code by using <code>&gt;&gt;=</code> to feed them to
@@ -925,8 +925,8 @@ <h2 id="the-list-monad">The list monad</h2>
925925
with <code>&gt;&gt;=</code>, propagating the non-determinism:</p>
926926
<pre class="haskell:hs"><code>ghci&gt; [1,2] &gt;&gt;= \n -&gt; [&#39;a&#39;,&#39;b&#39;] &gt;&gt;= \ch -&gt; return (n,ch)
927927
[(1,&#39;a&#39;),(1,&#39;b&#39;),(2,&#39;a&#39;),(2,&#39;b&#39;)]</code></pre>
928-
<p><img src="assets/images/a-fistful-of-monads/concatmap.png"
929-
class="left" width="399" height="340" alt="concatmap" /></p>
928+
<img src="assets/images/a-fistful-of-monads/concatmap.png"
929+
class="left" width="399" height="340" alt="concatmap">
930930
<p>The list <code>[1,2]</code> gets bound to <code>n</code> and
931931
<code>['a','b']</code> gets bound to <code>ch</code>. Then, we do
932932
<code>return (n,ch)</code> (or <code>[(n,ch)]</code>), which means
@@ -1061,8 +1061,8 @@ <h3 id="a-knights-quest">A knight’s quest</h3>
10611061
three moves. We’ll just use a pair of numbers to represent the knight’s
10621062
position on the chess board. The first number will determine the column
10631063
he’s in and the second number will determine the row.</p>
1064-
<p><img src="assets/images/a-fistful-of-monads/chess.png" class="center"
1065-
width="760" height="447" alt="hee haw im a horse" /></p>
1064+
<img src="assets/images/a-fistful-of-monads/chess.png" class="center"
1065+
width="760" height="447" alt="hee haw im a horse">
10661066
<p>Let’s make a type synonym for the knight’s current position on the
10671067
chess board:</p>
10681068
<pre class="haskell:hs"><code>type KnightPos = (Int,Int)</code></pre>
@@ -1144,9 +1144,9 @@ <h3 id="a-knights-quest">A knight’s quest</h3>
11441144
the number of moves to take instead of that number being hardcoded like
11451145
it is now.</p>
11461146
<h2 id="monad-laws">Monad laws</h2>
1147-
<p><img src="assets/images/a-fistful-of-monads/judgedog.png"
1147+
<img src="assets/images/a-fistful-of-monads/judgedog.png"
11481148
class="right" width="343" height="170"
1149-
alt="the court finds you guilty of peeing all over everything" /></p>
1149+
alt="the court finds you guilty of peeing all over everything">
11501150
<p>Just like applicative functors, and functors before them, monads come
11511151
with a few laws that all monad instances must abide by. Just because
11521152
something is made an instance of the <code>Monad</code> type class

markdown/generated_html/chapters.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<div id="content">
1919
<h1 id="learn-you-a-haskell-for-great-good">Learn You a Haskell for
2020
Great Good!</h1>
21-
<ol type="1">
21+
<ol class="chapters" type="1">
2222
<li><a href="introduction.html">Introduction</a>
2323
<ul>
2424
<li><a href="introduction.html#about-this-tutorial">About this

markdown/generated_html/faq.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
<div class="bgwrapper">
1818
<div id="content">
1919
<h1 id="faq">FAQ</h1>
20-
<p><img src="assets/images/faq/turtle.png" class="right" width="349"
21-
height="204" alt="turtle???" /></p>
20+
<img src="assets/images/faq/turtle.png" class="right" width="349"
21+
height="204" alt="turtle???">
2222
<h2 id="can-i-put-this-tutorial-on-my-site-or-change-it-or-whatever">Can
2323
I put this tutorial on my site or change it or whatever?</h2>
2424
<p>Sure, it’s licensed under a <a

markdown/generated_html/for-a-few-monads-more.html

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
</ul>
3333
</div>
3434
<h1 id="for-a-few-monads-more">For a Few Monads More</h1>
35-
<p><img src="assets/images/for-a-few-monads-more/clint.png"
35+
<img src="assets/images/for-a-few-monads-more/clint.png"
3636
class="right" width="189" height="400"
37-
alt="there are two kinds of people in the world, my friend. those who learn them a haskell and those who have the job of coding java" /></p>
37+
alt="there are two kinds of people in the world, my friend. those who learn them a haskell and those who have the job of coding java">
3838
<p>We’ve seen how monads can be used to take values with contexts and
3939
apply them to functions and how using <code>&gt;&gt;=</code> or
4040
<code>do</code> notation allows us to focus on the values themselves
@@ -86,9 +86,9 @@ <h2 id="writer">Writer? I hardly know her!</h2>
8686
(False,&quot;Compared gang size to 9.&quot;)
8787
ghci&gt; isBigGang 30
8888
(True,&quot;Compared gang size to 9.&quot;)</code></pre>
89-
<p><img src="assets/images/for-a-few-monads-more/tuco.png" class="left"
89+
<img src="assets/images/for-a-few-monads-more/tuco.png" class="left"
9090
width="196" height="280"
91-
alt="when you have to poop, poop, don’t talk" /></p>
91+
alt="when you have to poop, poop, don’t talk">
9292
<p>So far so good. <code>isBigGang</code> takes a normal value and
9393
returns a value with a context. As we’ve just seen, feeding it a normal
9494
value is not a problem. Now what if we already have a value that has a
@@ -255,9 +255,9 @@ <h3 id="the-writer-type">The Writer type</h3>
255255
<pre class="haskell:hs"><code>instance (Monoid w) =&gt; Monad (Writer w) where
256256
return x = Writer (x, mempty)
257257
(Writer (x,v)) &gt;&gt;= f = let (Writer (y, v&#39;)) = f x in Writer (y, v `mappend` v&#39;)</code></pre>
258-
<p><img src="assets/images/for-a-few-monads-more/angeleyes.png"
258+
<img src="assets/images/for-a-few-monads-more/angeleyes.png"
259259
class="right" width="383" height="248"
260-
alt="when you have to poop, poop, don’t talk" /></p>
260+
alt="when you have to poop, poop, don’t talk">
261261
<p>First off, let’s examine <code>&gt;&gt;=</code>. Its implementation
262262
is essentially the same as <code>applyLog</code>, only now that our
263263
tuple is wrapped in the <code>Writer</code> <code>newtype</code>, we
@@ -492,8 +492,8 @@ <h3 id="inefficient-list-construction">Inefficient list
492492
<p>It’s inefficient because it ends up associating the use of
493493
<code>++</code> to the left instead of to the right.</p>
494494
<h3 id="difference-lists">Difference lists</h3>
495-
<p><img src="assets/images/for-a-few-monads-more/cactus.png"
496-
class="left" width="147" height="300" alt="cactuses" /></p>
495+
<img src="assets/images/for-a-few-monads-more/cactus.png"
496+
class="left" width="147" height="300" alt="cactuses">
497497
<p>Because lists can sometimes be inefficient when repeatedly appended
498498
in this manner, it’s best to use a data structure that always supports
499499
efficient appending. One such data structure is the difference list. A
@@ -617,8 +617,8 @@ <h3 id="comparing-performance">Comparing Performance</h3>
617617
<p>Oh, by the way, the song Final Countdown by Europe is now stuck in
618618
your head. Enjoy!</p>
619619
<h2 id="reader">Reader? Ugh, not this joke again.</h2>
620-
<p><img src="assets/images/for-a-few-monads-more/revolver.png"
621-
class="left" width="280" height="106" alt="bang youre dead" /></p>
620+
<img src="assets/images/for-a-few-monads-more/revolver.png"
621+
class="left" width="280" height="106" alt="bang youre dead">
622622
<p>In the <a
623623
href="functors-applicative-functors-and-monoids.html">chapter about
624624
applicatives</a>, we saw that the function type, <code>(-&gt;) r</code>
@@ -725,8 +725,8 @@ <h2 id="reader">Reader? Ugh, not this joke again.</h2>
725725
results and the <code>&gt;&gt;=</code> implementation will make sure
726726
that it all works out.</p>
727727
<h2 id="state">Tasteful stateful computations</h2>
728-
<p><img src="assets/images/for-a-few-monads-more/texas.png" class="left"
729-
width="244" height="230" alt="don’t jest with texas" /></p>
728+
<img src="assets/images/for-a-few-monads-more/texas.png" class="left"
729+
width="244" height="230" alt="don’t jest with texas">
730730
<p>Haskell is a pure language and because of that, our programs are made
731731
of functions that can’t change any global state or variables, they can
732732
only do some computations and return them results. This restriction
@@ -876,8 +876,8 @@ <h3 id="the-state-monad">The State monad</h3>
876876
because <code>return</code> has to put a value in a minimal context. So
877877
<code>return</code> will make a stateful computation that presents a
878878
certain value as the result and keeps the state unchanged.</p>
879-
<p><img src="assets/images/for-a-few-monads-more/badge.png"
880-
class="right" width="182" height="160" alt="im a cop" /></p>
879+
<img src="assets/images/for-a-few-monads-more/badge.png"
880+
class="right" width="182" height="160" alt="im a cop">
881881
<p>What about <code>&gt;&gt;=</code>? Well, the result of feeding a
882882
stateful computation to a function with <code>&gt;&gt;=</code> has to be
883883
a stateful computation, right? So we start off with the
@@ -1146,8 +1146,8 @@ <h2 id="useful-monadic-functions">Some useful monadic functions</h2>
11461146
counterparts of functions that we already know, like <code>filter</code>
11471147
and <code>foldl</code>. Let’s see what they are then!</p>
11481148
<h3 id="liftm-and-friends">liftM and friends</h3>
1149-
<p><img src="assets/images/for-a-few-monads-more/wolf.png" class="right"
1150-
width="394" height="222" alt="im a cop too" /></p>
1149+
<img src="assets/images/for-a-few-monads-more/wolf.png" class="right"
1150+
width="394" height="222" alt="im a cop too">
11511151
<p>When we started our journey to the top of Monad Mountain, we first
11521152
looked at functors, which are for things that can be mapped over. Then,
11531153
we learned about improved functors called applicative functors, which
@@ -1363,8 +1363,8 @@ <h3 id="the-join-function">The join function</h3>
13631363
joinedMaybes = do
13641364
m &lt;- Just (Just 8)
13651365
m</code></pre>
1366-
<p><img src="assets/images/for-a-few-monads-more/tipi.png" class="right"
1367-
width="253" height="379" alt="im a cop too as well also" /></p>
1366+
<img src="assets/images/for-a-few-monads-more/tipi.png" class="right"
1367+
width="253" height="379" alt="im a cop too as well also">
13681368
<p>Perhaps the most interesting thing about <code>join</code> is that
13691369
for every monad, feeding a monadic value to a function with
13701370
<code>&gt;&gt;=</code> is the same thing as just mapping that function
@@ -1532,8 +1532,8 @@ <h3 id="foldm">foldM</h3>
15321532
is cool as well because then you log whatever you want as your fold goes
15331533
along its way.</p>
15341534
<h3 id="making-a-safe-rpn-calculator">Making a safe RPN calculator</h3>
1535-
<p><img src="assets/images/for-a-few-monads-more/miner.png" class="left"
1536-
width="280" height="396" alt="i’ve found yellow!" /></p>
1535+
<img src="assets/images/for-a-few-monads-more/miner.png" class="left"
1536+
width="280" height="396" alt="i’ve found yellow!">
15371537
<p>When we were solving the problem of <a
15381538
href="http://learnyouahaskell.com/reverse-polish-notation-calculator">implementing
15391539
a RPN calculator</a>, we noted that it worked fine as long as the input
@@ -1717,8 +1717,8 @@ <h3 id="composing-monadic-functions">Composing monadic functions</h3>
17171717
<pre class="haskell:hs"><code>canReachIn :: Int -&gt; KnightPos -&gt; KnightPos -&gt; Bool
17181718
canReachIn x start end = end `elem` inMany x start</code></pre>
17191719
<h2 id="making-monads">Making monads</h2>
1720-
<p><img src="assets/images/for-a-few-monads-more/spearhead.png"
1721-
class="center" width="780" height="244" alt="kewl" /></p>
1720+
<img src="assets/images/for-a-few-monads-more/spearhead.png"
1721+
class="center" width="780" height="244" alt="kewl">
17221722
<p>In this section, we’re going to look at an example of how a type gets
17231723
made, identified as a monad and then given the appropriate
17241724
<code>Monad</code> instance. We don’t usually set out to make a monad
@@ -1817,8 +1817,8 @@ <h2 id="making-monads">Making monads</h2>
18171817
happen. <code>'c'</code> and <code>'d'</code> are also equally likely to
18181818
happen. Here’s a picture of a probability list that models this
18191819
scenario:</p>
1820-
<p><img src="assets/images/for-a-few-monads-more/prob.png" class="left"
1821-
width="456" height="142" alt="probs" /></p>
1820+
<img src="assets/images/for-a-few-monads-more/prob.png" class="left"
1821+
width="456" height="142" alt="probs">
18221822
<p>What are the chances for each of these letters to occur? If we were
18231823
to draw this as just four boxes, each with a probability, what would
18241824
those probabilities be? To find out, all we have to do is multiply each
@@ -1856,8 +1856,8 @@ <h2 id="making-monads">Making monads</h2>
18561856
return x = Prob [(x,1%1)]
18571857
m &gt;&gt;= f = flatten (fmap f m)
18581858
fail _ = Prob []</code></pre>
1859-
<p><img src="assets/images/for-a-few-monads-more/ride.png" class="right"
1860-
width="177" height="406" alt="ride em cowboy" /></p>
1859+
<img src="assets/images/for-a-few-monads-more/ride.png" class="right"
1860+
width="177" height="406" alt="ride em cowboy">
18611861
<p>Because we already did all the hard work, the instance is very
18621862
simple. We also defined the <code>fail</code> function, which is the
18631863
same as it is for lists, so if there’s a pattern match failure in a

0 commit comments

Comments
 (0)