1 module henhouse.translator.markdown;
2 
3 import file = std.file;
4 import uni  = std.uni;
5 
6 import hhc   = henhouse.converter;
7 import hht_t = henhouse.translator.text;
8 
9 
10 /**
11  * Markdown Translator.
12  */
13 class Translator : hht_t.Translator
14 {
15     override string translateText(string original)
16     {
17         char   current;
18         string chicken;
19         string buffer;
20 
21         for (int i = 0; i < original.length; i++) {
22             current = original[i];
23 
24             if ('[' == current) {
25                 do {
26                     chicken ~= original[i];
27                     i++;
28                 }
29                 while (']' != original[i]);
30 
31                 chicken ~= ']';
32 
33                 if ('(' == original[i + 1]) {
34                     i++;
35 
36                     do {
37                         chicken ~= original[i];
38                         i++;
39                     }
40                     while (')' != original[i]);
41 
42                     chicken ~= ')';
43                 }
44 
45                 continue;
46             }
47 
48             if (uni.isAlpha(current)) {
49                 buffer ~= current;
50                 continue;
51             }
52 
53             if (0 < buffer.length) {
54                 chicken ~= hhc.wordToChicken(buffer);
55                 buffer   = "";
56             }
57 
58             chicken ~= current;
59         }
60 
61         return chicken;
62     }
63 
64     unittest
65     {
66         Translator trans = new Translator();
67         string original  = "Very Markdown! [uncoverted](link)";
68         string chicken   = "Chicken Chicken! [uncoverted](link)";
69 
70         assert(chicken == trans.translateText(original));
71     }
72 }