Add .gitignore with a rule for .cdo files.
[hacks/tiki_of_html.git] / tiki_of_html.cd
1 /*
2
3   cduce --compile tiki_of_html.cd
4   cduce --run tiki_of_html.cdo --arg http://digicosme.lri.fr/innovation.html
5
6 */
7
8
9 let tiki_of_html (h : [ Any* ]) : [Byte*] =
10 /* Applique le pattern a chaque element de la liste.
11    l'expression de droite doit etre une liste, et le tout
12    est reconcaténé:
13    Équivalent de List.concat (List.map f l) où f est la transformation
14    faite par le pattern
15  */  
16   transform h with
17
18   /* on ignore le header */
19     <head ..>_ -> []
20
21   /* Le gras */
22   | <b ..>(l&[Any*]) -> "__" @ tiki_of_html l @ "__"
23
24   /* Les liens */
25   | <a href=(url & Latin1) ..>(l&[Any*]) ->
26       "[" @ url @ "|" @ tiki_of_html l @ "]"
27
28   /* Les listes non */ 
29   | <((`ul|`ol)&tag) ..>(l&[Any*]) ->
30       let sym = if tag = `ol then "# " else "* " in
31       let res =
32         transform "\n" @ l with
33           <li ..>(l&[Any*]) -> sym @ tiki_of_html l @"\n"
34         | x -> tiki_of_html [ x ]
35       in
36       res
37
38   /* Un tag qu'on ne connait pas, on se rapplique récursivement */
39   | <_ ..>(l&[Any*]) -> " "@tiki_of_html l@" "
40
41   /* Un charactère, on le copie dans la sortie */
42   | Byte & c -> [ c ]
43   /* Autre chose ? on l'ignore */
44   | _ -> []
45 ;;
46
47
48
49 let [] =
50   match argv [] with
51     [ (url & Latin1) ] ->
52       print (tiki_of_html (load_html url))
53
54
55   | _ -> print "Nombre d'arguments invalides\n"; exit 1