X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=tiki_of_html.cd;fp=tiki_of_html.cd;h=ff79a69d1c63cfdc02661eaac08442c80effe809;hb=c77951ba16a25e0c1ffa12b3eb92e687a83529a6;hp=b3dec8ed97bbd0b21be036e06baf20c774f0d540;hpb=820b5ffb83d832a864e825437922d417cd6ac9c6;p=hacks%2Ftiki_of_html.git diff --git a/tiki_of_html.cd b/tiki_of_html.cd index b3dec8e..ff79a69 100644 --- a/tiki_of_html.cd +++ b/tiki_of_html.cd @@ -4,52 +4,88 @@ cduce --run tiki_of_html.cdo --arg http://digicosme.lri.fr/innovation.html */ +type html_element = <_ ..>html_content +type html_content = [ (Byte | html_element)* ] +type space = ' ' | '\t' | '\n' +type content = (Byte| html_element) \ space -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 +let repeat (s : Latin1) (n : Int) : Latin1 = + if n = 0 then s else s @ repeat s (n - 1) + +let remove_spaces (l : html_content) : html_content = + match l with + | [ (x :: content | _ )* ] -> x + +let trim_spaces (l : html_content) : html_content = + match l with + [ space* (x::(Byte|html_element))*? space* ] -> x + +let tiki_of_html (level : Int) (h : html_content) : Latin1 = +(* 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 */ -
_ -> [] + (* on ignore le header et les balises de script *) + <(`script|`head) ..>_ -> [] + + (* Le gras *) + | <(`b|`strong) ..>l -> "__" @ tiki_of_html level l @ "__" + + (* L''italique *) + | <(`em|`i) ..>l -> "''" @ tiki_of_html level l @ "''" + + (* Les tableaux *) + |