[prev in list] [next in list] [prev in thread] [next in thread]
List: kwrite-devel
Subject: Re: [Kwrite-devel] [PATCH] nice feature for kate..
From: Emmanuel Touzery <emmanuel.touzery () wanadoo ! fr>
Date: 2001-12-16 15:30:06
[Download RAW message or body]
good points! i attach the latest version of the source. konqueror is indeed
still happy if i remove all <br/> :o)
emmanuel.
PS: so, there is no way to get kde libs to encode entities for us? as you can
see, the entities encoding is ... limited, that's the least i can say (i only
support <,>, and &).
PPS: yes, now you mention the mozilla thing, it might be a good idea to test
with netscape4/IE and others, if you do have them installed. i only have
konqueror on my computer (and no windows around).
Le Dimanche 16 Décembre 2001 10:10, Daniel Naber a écrit :
> On Sunday 16 December 2001 21:51, Emmanuel Touzery wrote:
> > here we are. the attached html file is XHTML-1.0 compliant according to
> > validator.w3.org (tell me if there's still anything wrong, though), and
> > you also have the relevant sources.
>
> Great, just one last thing: the first line says it's UTF-8, but you have to
> use setEncoding() for that, otherwise the stream will default to the local
> encoding (that's not bad, but then the first line isn't correct).
>
> I think you can also remove all "<br/>" because you are already inside
> <pre>. Mozilla currently renders two linebreaks for each line.
>
> regadrs
> Daniel
--
dessine moi un mouton..
le ciel est vide sans imagination..
["patch3.cpp" (text/x-c++)]
bool KateDocument::exportDocumentToHTML(const QString& targetFileName)
{
ASSERT(targetFileName != NULL);
// start by opening the target file :
QFile outputFile( targetFileName );
if ( !outputFile.open( IO_WriteOnly ) )
return false; // Error
QTextStream outputStream(&outputFile);
outputStream.setEncoding(QTextStream::UnicodeUTF8);
// let's write the HTML header :
outputStream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
outputStream << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \
\"DTD/xhtml1-strict.dtd\">" << endl; outputStream << "<html \
xmlns=\"http://www.w3.org/1999/xhtml\">" << endl; outputStream << "<head>" << endl;
outputStream << "<meta http-equiv=\"Content-Type\" content=\"text/html; \
charset=UTF-8\" />" << endl; outputStream << "<meta name=\"Generator\" \
content=\"Kate, the KDE Advanced Text Editor\" />" << endl; // for the title, we \
write the name of the file (/usr/local/emmanuel/myfile.cpp -> myfile.cpp) \
outputStream << "<title>" << targetFileName.right(targetFileName.length() - \
targetFileName.findRev('/') -1) << "</title>" << endl; outputStream << "</head>" << \
endl;
outputStream << "<body><pre>" << endl;
// for each line :
// some variables :
bool previousCharacterWasBold = false;
bool previousCharacterWasItalic = false;
// when entering a new color, we'll close all the <b> & <i> tags,
// for HTML compliancy. that means right after that font tag, we'll
// need to reinitialize the <b> and <i> tags.
bool needToReinitializeTags = false;
QColor previousCharacterColor(0,0,0); // default color of HTML characters is black
outputStream << "<span style='color=#000000'>";
for (int curLine=0;curLine<getTextLineCount();curLine++)
{ // html-export that line :
TextLine::Ptr textLine = getTextLine(curLine);
ASSERT(textLine != NULL);
// for each character of the line : (curPos is the position in the line)
for (int curPos=0;curPos<textLine->length();curPos++)
{
Attribute *charAttributes = &m_attribs[textLine->getAttr(curPos)];
ASSERT(charAttributes != NULL);
// let's give the color for that character :
if ( (charAttributes->col != previousCharacterColor))
{ // the new character has a different color :
// if we were in a bold or italic section, close it
if (previousCharacterWasBold)
outputStream << "</b>";
if (previousCharacterWasItalic)
outputStream << "</i>";
// close the previous font tag :
outputStream << "</span>";
// let's read that color :
int red, green, blue;
// getting the red, green, blue values of the color :
charAttributes->col.rgb(&red, &green, &blue);
outputStream << "<span style='color:#"
<< ( (red < 0x10)?"0":"") // need to put 0f, NOT f for instance. don't touch \
1f.
<< QString::number(red, 16) // html wants the hex value here (hence the 16)
<< ( (green < 0x10)?"0":"")
<< QString::number(green, 16)
<< ( (blue < 0x10)?"0":"")
<< QString::number(blue, 16)
<< "'>";
// we need to reinitialize the bold/italic status, since we closed all the tags
needToReinitializeTags = true;
}
// bold status :
if ( (needToReinitializeTags && charAttributes->bold) ||
(!previousCharacterWasBold && charAttributes->bold) )
// we enter a bold section
outputStream << "<b>";
if ( !needToReinitializeTags && (previousCharacterWasBold && \
!charAttributes->bold) ) // we leave a bold section
outputStream << "</b>";
// italic status :
if ( (needToReinitializeTags && charAttributes->italic) ||
(!previousCharacterWasItalic && charAttributes->italic) )
// we enter an italic section
outputStream << "<i>";
if ( !needToReinitializeTags && (previousCharacterWasItalic && \
!charAttributes->italic) ) // we leave an italic section
outputStream << "</i>";
// write the actual character :
outputStream << HTMLEncode(textLine->getChar(curPos));
// save status for the next character :
previousCharacterWasItalic = charAttributes->italic;
previousCharacterWasBold = charAttributes->bold;
previousCharacterColor = charAttributes->col;
needToReinitializeTags = false;
}
// finish the line :
outputStream << endl;
}
// HTML document end :
outputStream << "</span>"; // i'm guaranteed a span is started (i started one at \
the beginning of the output). outputStream << "</pre></body>";
outputStream << "</html>";
// close the file :
outputFile.close();
return (outputFile.status() == IO_Ok);
}
QString KateDocument::HTMLEncode(QChar theChar)
{
switch (theChar.latin1())
{
case '>':
return QString(">");
case '<':
return QString("<");
case '&':
return QString("&");
};
return theChar;
}
_______________________________________________
kwrite-devel mailing list
kwrite-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/kwrite-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic