diff options
author | Benjamin Barenblat <bbaren@mit.edu> | 2015-02-12 22:29:13 -0500 |
---|---|---|
committer | Benjamin Barenblat <bbaren@mit.edu> | 2015-02-12 22:36:34 -0500 |
commit | 26bd4deb3b0a9b1a1aef3bf22539926241772bbf (patch) | |
tree | b5a2b0b1fe59de9d4bf3fc7e91388325c5d30e4f /src | |
parent | 8090cd7bd9c9a80e189b381e63a7ce10f8c9f3ac (diff) |
Remove leading spaces and/or one newline from code blocks
listings is space-sensitive, so the common idiom
<<block name>>=
block body
@
gets typeset as
⟨block name⟩≡
block body
This is ugly, so remove all leading spaces up to the first newline (and
that newline itself, if appropriate) in each code block.
Diffstat (limited to 'src')
-rw-r--r-- | src/Weave.hs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/Weave.hs b/src/Weave.hs index f10617f..f2d7836 100644 --- a/src/Weave.hs +++ b/src/Weave.hs @@ -23,9 +23,19 @@ weaveFragment :: Fragment -> String weaveFragment (Documentation text) = text weaveFragment (BlockCode name body) = "\\begin{LytBlockCode}{" ++ name ++ "}\n" - ++ concatMap weaveCodeOrReference body + ++ weaveBlockBody body ++ "\\end{LytBlockCode}\n" +weaveBlockBody :: [CodeOrReference] -> String +weaveBlockBody ((Code first):rest) = + {- The first block is code. To make sure it gets typeset correctly, drop + everything up to the first newline or non-space character. -} + (case dropWhile (==' ') first of + '\n' : first' -> first' + first' -> first') + ++ concatMap weaveCodeOrReference rest +weaveBlockBody blocks = concatMap weaveCodeOrReference blocks + weaveCodeOrReference :: CodeOrReference -> String weaveCodeOrReference (Code text) = text weaveCodeOrReference (Reference name) = "\\LytFragmentReference{" ++ name ++ "}" |