git @ Cat's Eye Technologies Falderal / b8bfd5e
Add vanilla Markdown formatter. --HG-- rename : Test/Falderal/Formatter/Identity.hs => Test/Falderal/Formatter/Markdown.hs catseye 10 years ago
4 changed file(s) with 70 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
00 module Test.Falderal.Formatter.Identity where
1
2 -- TODO: export a more restricted interface
31
42 --
53 -- Test.Falderal.Formatter.Identity -- Identity formatter for Falderal format
5452 (prefixEachLine "> " text)
5553 formatLine (SectionHeading text) =
5654 text ++ "\n" ++ (take (length text) (repeat '-')) ++ "\n"
57
58 -- Fix lines so that it acts on "" appropriately
59
60 allLines x =
61 case (lines x) of
62 [] -> [""]
63 other -> other
64
65 prefixEachLine prefix text =
66 foldl (++) "" (map (\x -> prefix ++ x ++ "\n") (allLines text))
0 module Test.Falderal.Formatter.Markdown where
1
2 --
3 -- Test.Falderal.Formatter.Identity -- Markdown formatter for Falderal format
4 -- Copyright (c)2011 Cat's Eye Technologies. All rights reserved.
5 --
6 -- Redistribution and use in source and binary forms, with or without
7 -- modification, are permitted provided that the following conditions
8 -- are met:
9 --
10 -- 1. Redistributions of source code must retain the above copyright
11 -- notices, this list of conditions and the following disclaimer.
12 -- 2. Redistributions in binary form must reproduce the above copyright
13 -- notices, this list of conditions, and the following disclaimer in
14 -- the documentation and/or other materials provided with the
15 -- distribution.
16 -- 3. Neither the names of the copyright holders nor the names of their
17 -- contributors may be used to endorse or promote products derived
18 -- from this software without specific prior written permission.
19 --
20 -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 -- ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 -- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 -- COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 -- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 -- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 -- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 -- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 -- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 -- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 -- POSSIBILITY OF SUCH DAMAGE.
32 --
33
34 import System
35
36 import Test.Falderal.Loader
37
38 --
39 -- Formatting function which formats a Falderal file to vanilla Markdown
40 -- file. Falderal-specific sections (test input, expected results) are still
41 -- presented with Falderal syntax.
42 --
43
44 formatLine (TestInput text) =
45 (prefixEachLine " | " text)
46 formatLine (ExpectedResult text) =
47 (prefixEachLine " = " text)
48 formatLine (ExpectedError text) =
49 (prefixEachLine " ? " text)
50 formatLine (LiteralText text) =
51 (prefixEachLine "" text)
52 formatLine (QuotedCode text) =
53 (prefixEachLine " " text)
54 formatLine (SectionHeading text) =
55 text ++ "\n" ++ (take (length text) (repeat '-')) ++ "\n"
3737
3838 import Test.Falderal.Loader
3939 import qualified Test.Falderal.Formatter.Identity as Identity
40 import qualified Test.Falderal.Formatter.Markdown as Markdown
4041
4142 --
4243 -- Driver for Falderal file formatting.
4748 --
4849
4950 getFormatter "identity" = Identity.formatLine
51 getFormatter "markdown" = Markdown.formatLine
5052 getFormatter "dump" = \x -> (show x) ++ "\n"
5153
5254 --
202202
203203 stripTrailing y str = reverse (stripLeading y (reverse str))
204204
205 --
206 -- A version of `lines` that always considers the input "" to
207 -- represent a single, blank line.
208 --
209
210 allLines x =
211 case (lines x) of
212 [] -> [""]
213 other -> other
214
215 prefixEachLine prefix text =
216 foldl (++) "" (map (\x -> prefix ++ x ++ "\n") (allLines text))