All pastes #226729 Raw Edit

Sans nom

public ruby v1 · immutable
#226729 ·published 2006-10-28 20:19 UTC
rendered paste body
#!/usr/bin/env rubyHeader  = %Q(\<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />    <link href="../cours.css" rel="stylesheet" type="text/css" /></head><body>).split("\n")Footer = %Q(\</body></html>).split("\n")Source      = '/home/kik/documents/cours/brut/'Destination = '/home/kik/documents/cours/html/'def parser_ligne(ligne, jour)    balise = case ligne                when /^ *TITRE/ then "h#{$'[0,1]}"                when /^ *EM/    then "em"                else "p"             end    ligne.gsub!(/TITRE./, "")    ligne.gsub!(/EM/, "")    ligne.gsub!(/<</, "«")    ligne.gsub!(/>>/, "»")    # traitement des notes    while ligne[/ \(\d\) /]        ligne = $` + " <a name=#{jour}_#{$&[2,1]}_texte href=##{jour}_#{$&[2,1]}_note>[" + $&[2,1] + "]</a> " + $'     end    if ligne[/^ *NOTE/]        ligne = "<a name=#{jour}_#{$'[0,1]}_note href=##{jour}_#{$'[0,1]}_texte>" + "#{$'[0,1]}</a>"+ $'.gsub(/^./, "")    end    # traitement des autres liens    while ligne[/HREF=\S+/]        match, pre, post = $&, $`, $'        reste = post.split('/A')        ligne = pre + "<a href=#{match[5,200]}>" + reste[0] + "</a>" + reste[1]    end    return (ligne[/^ *\n$/] ? "" : ligne.gsub(/^/, "<#{balise}>").gsub(/\n$/, "</#{balise}>\n") )enddef parser_fichier(flux)    jour        = File.basename(flux.path)    texte_html  = ["<p><a name=#{jour}><em>(#{jour})</em></a></p>"]        while (ligne = flux.gets)        texte_html << parser_ligne(ligne, jour)    end    return texte_htmlendDir.new(Source).each { |dossier|    unless dossier == '.' or dossier == '..'        liens_dates = []        matiere     = Source + '/' + dossier        fichiers    = Dir.new(matiere).entries.delete_if { |f| f[/\./] }.delete_if { |f| f[/\.html$/] }.sort        puts fichiers.inspect # debug        texte_html  = []        fichiers.each { |f|             flux       = File.new( matiere + '/' + f )            texte_html += parser_fichier(flux)            liens_dates.push(File.basename(flux.path))            flux.close        }        texte_href = [""]        liens_dates.each { |nom|            texte_href[0] += " | <a href='##{nom}'>#{nom}</a>"        }        %x(mkdir -p #{Destination}) unless File.exist?(Destination)        texte_html       = Header + texte_href + texte_html + texte_href + Footer        fichier_html     = File.new(Destination + dossier + ".html", "w")        texte_html.each { |ligne| fichier_html.puts(ligne) }        fichier_html.close    end}puts "terminé."