Initial version.
authorKim Nguyễn <kn@lri.fr>
Tue, 23 Oct 2012 19:12:38 +0000 (21:12 +0200)
committerKim Nguyễn <kn@lri.fr>
Tue, 23 Oct 2012 19:12:38 +0000 (21:12 +0200)
tiki_of_html.cd [new file with mode: 0644]

diff --git a/tiki_of_html.cd b/tiki_of_html.cd
new file mode 100644 (file)
index 0000000..b3dec8e
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+
+  cduce --compile tiki_of_html.cd
+  cduce --run tiki_of_html.cdo --arg http://digicosme.lri.fr/innovation.html
+
+*/
+
+
+let tiki_of_html (h : [ Any* ]) : [Byte*] =
+/* Applique le pattern a chaque element de la liste.
+   l'expression de droite doit etre une liste, et le tout
+   est reconcaténé:
+   Équivalent de List.concat (List.map f l) où f est la transformation
+   faite par le pattern
+ */  
+  transform h with
+
+  /* on ignore le header */
+    <head ..>_ -> []
+
+  /* Le gras */
+  | <b ..>(l&[Any*]) -> "__" @ tiki_of_html l @ "__"
+
+  /* Les liens */
+  | <a href=(url & Latin1) ..>(l&[Any*]) ->
+      "[" @ url @ "|" @ tiki_of_html l @ "]"
+
+  /* Les listes non */ 
+  | <((`ul|`ol)&tag) ..>(l&[Any*]) ->
+      let sym = if tag = `ol then "# " else "* " in
+      let res =
+        transform "\n" @ l with
+          <li ..>(l&[Any*]) -> sym @ tiki_of_html l @"\n"
+        | x -> tiki_of_html [ x ]
+      in
+      res
+
+  /* Un tag qu'on ne connait pas, on se rapplique récursivement */
+  | <_ ..>(l&[Any*]) -> " "@tiki_of_html l@" "
+
+  /* Un charactère, on le copie dans la sortie */
+  | Byte & c -> [ c ]
+  /* Autre chose ? on l'ignore */
+  | _ -> []
+;;
+
+
+
+let [] =
+  match argv [] with
+    [ (url & Latin1) ] ->
+      print (tiki_of_html (load_html url))
+
+
+  | _ -> print "Nombre d'arguments invalides\n"; exit 1