From e86dc72588f6a871b7cb883ce800486e580d41ba Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kim=20Nguy=E1=BB=85n?= Date: Tue, 23 Oct 2012 21:12:38 +0200 Subject: [PATCH] Initial version. --- tiki_of_html.cd | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tiki_of_html.cd diff --git a/tiki_of_html.cd b/tiki_of_html.cd new file mode 100644 index 0000000..b3dec8e --- /dev/null +++ b/tiki_of_html.cd @@ -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 */ + _ -> [] + + /* Le gras */ + | (l&[Any*]) -> "__" @ tiki_of_html l @ "__" + + /* Les liens */ + | (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 +
  • (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 -- 2.17.1