Pogčedajte punu verziju : clean up word html
ivanhoe
28. 03. 2007., 13:31
jel zna neko neku pouzdanu skriptu koja moze da izadje na kraj sa textom paste-ovanim iz Worda u FCKEditor (ili vec neki drugi html editor). Ti editori prime html, ali Wordov html je uzas, i naravno kad se to prikaze u sred moje strane napravi mi potpuni haos... a korisnici bas vole da paste-uju iz worda...
Znaci moze php skript, a moze i javascript, i treba da ume da primi html od Worda i da izbaci sve osim headera, paragrafa, bold, italic, lista i slika, ali da se pritom ne skrlja kad mu Word podmetne ona njegova chuda...
Zar to nije standardna mogucnost FCKEditora, ima dugme Paste from Word?
Ilija Studen
28. 03. 2007., 14:15
Dve zgodne alatke:
- KSES (http://sourceforge.net/projects/kses) - Koristim ga unutar jednog agregatora. Kakvo god đubre da mu proslediš vrati samo ono što valja.
- HTML Purifier (http://hp.jpsband.org/) - Mnogo više kontrole, "konta" HTML, ali je i glomazniji. Više za content orijentisane projekte.
ivanhoe
28. 03. 2007., 16:00
Zar to nije standardna mogucnost FCKEditora, ima dugme Paste from Word?
pa jeste, ima to dugme, ima i opciju da automatski detektuje da li je paste iz Worda.....samo sto to ne radi kako treba... odnosno ponekad radi, ponekad ne, ne znam tacno kako i zasto posto textove unose sluzbenici pred penzijom svasta je moguce... a onda mene zovu: e ovo tvoje ne radi... :mad:
zato bih radje da ja preuzmem kontrolu nad tim sta se tacno od html-a stavlja u bazu...
@Ilija: thanx, overicu ova dva projekta.. ovo je funkcija koja ide na admin deo, tako da brzina ili velicina nisu preterano bitni, samo da se resim bede... :)
Imam isti problem ... aj javi koje resenje se pokazalo kao bolje i u kojim situacijama.
Probao sam KSES i odlicno radi posao, nije glomazan i jednostavan je za konfiguraciju. HTML Purifier mi je previse "glomazan" (mozda je bolji ali nisam imao vremena da testiram detaljnije).
ivanhoe
03. 04. 2007., 22:04
ja sam se na kraju odlucio za hack varijantu: prebudzio sam funkciju iz FCKEditora koja cisti Word da ga malo lepse cisti, a na server strani dodao par caka koje poprave liste koje Word genijalno prikaze kao ·
za sada radi posao...
Jel moze da se dobije source tog "haknutog" FCK-a ? :)
ivanhoe
04. 04. 2007., 00:58
u fajlu editor/dialog/fck_paste.html :
function CleanWord( html )
{
var bIgnoreFont = document.getElementById('chkRemoveFont').checked ;
var bRemoveStyles = document.getElementById('chkRemoveStyles').checked ;
html = html.replace(/<o:p>\s*<\/o:p>/g, "") ;
html = html.replace(/<o:p>.*?<\/o:p>/g, " ") ;
// Remove mso-xxx styles.
html = html.replace( /\s*mso-[^:]+:[^;"]+;?/gi, "" ) ;
// Remove margin styles.
html = html.replace( /\s*MARGIN: 0cm 0cm 0pt\s*;/gi, "" ) ;
html = html.replace( /\s*MARGIN: 0cm 0cm 0pt\s*"/gi, "\"" ) ;
html = html.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, "" ) ;
html = html.replace( /\s*TEXT-INDENT: 0cm\s*"/gi, "\"" ) ;
html = html.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" ) ;
html = html.replace( /\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi, "\"" ) ;
html = html.replace( /\s*FONT-VARIANT: [^\s;]+;?"/gi, "\"" ) ;
html = html.replace( /\s*tab-stops:[^;"]*;?/gi, "" ) ;
html = html.replace( /\s*tab-stops:[^"]*/gi, "" ) ;
// Remove FONT face attributes.
// if ( bIgnoreFont )
// {
html = html.replace( /\s*face="[^"]*"/gi, "" ) ;
html = html.replace( /\s*face=[^ >]*/gi, "" ) ;
html = html.replace( /\s*FONT-FAMILY:[^;"]*;?/gi, "" ) ;
// }
// Remove Class attributes
html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
// Remove styles.
// if ( bRemoveStyles )
html = html.replace( /<(\w[^>]*) style="([^\"]*)"([^>]*)/gi, "<$1$3" ) ;
// Remove empty styles.
html = html.replace( /\s*style="\s*"/gi, '' ) ;
html = html.replace( /<SPAN\s*[^>]*>\s* \s*<\/SPAN>/gi, ' ' ) ;
html = html.replace( /<SPAN\s*[^>]*><\/SPAN>/gi, '' ) ;
// Remove Lang attributes
html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
// Promenio da brise sve spanove i fontove
//html = html.replace( /<SPAN\s*>(.*?)<\/SPAN>/gi, '$1' ) ;
//html = html.replace( /<FONT\s*>(.*?)<\/FONT>/gi, '$1' ) ;
html = html.replace( /<\/?span[^>]*>/gi, '' ) ;
html = html.replace( /<\/?font[^>]*>/gi, '' ) ;
// Dodao da brise cudne Wordove komentare
html = html.replace( /<\!\-\-.+\-\->/gi, '' ) ;
// i visestruke
html = html.replace( / ( )+/gi, ' ' ) ;
//  na pocetku elementa
html = html.replace( />\s* \s*/gi, '>' ) ;
// Remove XML elements and declarations
html = html.replace(/<\\?\?xml[^>]*>/gi, "") ;
// Remove Tags with XML namespace declarations: <o:p></o:p>
html = html.replace(/<\/?\w+:[^>]*>/gi, "") ;
html = html.replace( /<H\d>\s*<\/H\d>/gi, '' ) ;
/*
html = html.replace( /<H1([^>]*)>/gi, '<div$1><b><font size="6">' ) ;
html = html.replace( /<H2([^>]*)>/gi, '<div$1><b><font size="5">' ) ;
html = html.replace( /<H3([^>]*)>/gi, '<div$1><b><font size="4">' ) ;
html = html.replace( /<H4([^>]*)>/gi, '<div$1><b><font size="3">' ) ;
html = html.replace( /<H5([^>]*)>/gi, '<div$1><b><font size="2">' ) ;
html = html.replace( /<H6([^>]*)>/gi, '<div$1><b><font size="1">' ) ;
html = html.replace( /<\/H\d>/gi, '</font></b></div>' ) ;
*/
html = html.replace( /<(U|I|STRIKE)> <\/\1>/gi, ' ' ) ;
// Remove empty tags (three times, just to be sure).
html = html.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
html = html.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
html = html.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
// Transform <P> to <DIV>
// var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ; // Different because of a IE 5.0 error
// html = html.replace( re, "<div$2</div>" ) ;
return html ;
}
ostali su i iskomentarisani originalni delovi (cisto da bude bas,bas hack :)). Elem, nista revolucionarno samo sam sprecio FCKE da naslove zameni sa <div>tagom, posto mi je to potpuno idiotski, i napravio sammalo agresivnije ciscenje spanova i fontova (brisem ih sve, posto ne zelim da iz Worda dobijem bilo kakve stilove vezane za font ili boju). Ova funkcija se poziva samo kad se radi o pastovanju iz Worda, sto je meni ok, ali ako ti ne odgovara mozes je i sam pozvati na nekom drugom html-u
vBulletin® v3.6.8, Copyright ©2000-2024, Jelsoft Enterprises Ltd.