[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: TRansformation von HTML in XHTML



Michael Hierweck <team@edv-serviceteam.net> writes:

Hallo Michael,

du bist doch von Hostsharing oder?

> gibt es ein Tool, ähnlich wie tidy, welche HTML in XHMTL transformiert
> und alle Formatierung verwirft, so dass wirklich nur "Struktur"-Tags
> übrig bleiben?

Mir ist keine bekannt, aber ich hatte ein ähnliches Problem. Ich bekomme
oft Word-Dokumente, die ins Netz sollen. Ich wandle sie mit wvHtml um,
aber dabei kommt schrecklicher code raus. 

Das ganze behandle ich dann mit "tidy -imc" wobei das -c dazu führt:

| -clean or -c    replace FONT, NOBR and CENTER tags by CSS

Die Styles aus dem Head der html Datei lassen sich dann einfach
rauslöschen. 

Sodann schicke ich das ganze noch durch sed um die Klassen loszuwerden
und Tabellenformatierungen zu entfernen. Übrig bleibt das logische
Markup. 

sed -f sedscript input.html > output html

Hier das Sed-Skript (oder wie nennt man sowas?). 

ACHTUNG: keine Garantie für Funktion! Bei mir funktioniert es, aber ich
verstehe weder von sed noch von Regex etwas. Verbesserungsvorschläge
sind sehr wilkommen. :-)

# sed-script for cleaning up html that was converted from Word-Documents
# with wvHtml, OpenOffice, Abiword or similar
#
# (tidy -c is not rigorous enough for me)
# 
#   # What happens if we have a missing ">" ?
#   # will everything until the next ">" be deleted?  

# delete all class attributes leftover from tidy -c
s/\ class\="[a-z,A-Z,\ ,0-9]*"//g
s/^class\="[a-z,A-Z,\ 0-9]*"//g

# take off all the nasty formatting done on table-cells
s/<td[^>]*>/<td>/g

# take off the strange list values that wvHtml generates  
s/<li[^>]*>/<li>/g

# delete all style expressions in tags
s/\ [Ss][Tt][Yy][Ll][Ee]\="[a-z,A-Z,\ 0-9\;\,:]*"//g

# delete all opening div-tags and span-tags
s/<div[^>]*>//g
s/<span[^>]*>//g

# delete all closing div-tags and span-tags
s/<\/div>//g
s/<\/span>//g

# delete those nasty  lang="de-DE" stuff
s/ lang\="de-DE"//g

###############################################################
##                                                           ##
##        now we try to fix broken German umlauts            ##
##                                                           ##
###############################################################

# "ü" that is "ue" seems to appear as: ü,
s/ü/ü/g

# "ö" that is "oe" seems to appear as: ö,
s/ö/ö/g

# "ä" that is "ae" seems to appear as: ä,
s/ä/ä/g


# "Ü" that is "UE" seems to appear as: ý,
s/ý/Ü/g


###############################################################
##                                                           ##
##    now we try to fix some more broken German umlauts      ##
##                                                           ##
###############################################################

# "ä" that is "ae" seems to appear as:  &Atilde;&curren;,
s/\&Atilde;\&curren;/\&auml;/g

# "ö" that is "oe" seems to appear as: &Atilde;&para;,
s/\&Atilde;\&para;/\&ouml;/g

# "ü" that is "ue" seems to appear as:  &Atilde;&frac14;
s/\&Atilde;\&frac14;/\&uuml;/g

# "ß" that is "ss" seems to appear as: &szlig;,
s/\&szlig;/\&szlig;/g

# "Ä" that is "AE" seems to appear as: &Atilde;",
s/\&Atilde;"/\&Auml;/g

# "Ö" that is "OE" seems to appear as:  &Atilde;-,
s/\&Atilde;-/\&Ouml;/g

# "Ü" that is "UE" seems to appear as: &Atilde;&oelig;,
s/\&Atilde;\&oelig;/\&Uuml;/g

# (END) 


Gruß,
        Berny

-- 
bernhard.marx@gmx.net



Reply to: