Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="Generator" content="Kate, the KDE Advanced Text Editor">
<title>highlighter.cpp</title>
<style>
pre.kate {
color:#1f1c1b;
background-color:#ffffff;
}
.C\+\+\:Qt4-Functions{
color:#644a9b;
}
.ISO-C\+\+\:Comment{
color:#898887;
}
.ISO-C\+\+\:Data-Members-\(m_\*\){
}
.ISO-C\+\+\:Type-Modifiers{
color:#0057ae;
}
.Doxygen\:Comment{
color:#898887;
}
.C\+\+\:Qt4-Classes{
color:#006e28;
}
.C\+\+\:Qt4-Macros{
font-weight:bold;
color:#0095ff;
}
.ISO-C\+\+\:Region-Marker{
color:#0057ae;
background-color:#e0e9f8;
}
.ISO-C\+\+\:String-Char{
color:#924c9d;
}
.ISO-C\+\+\:Preprocessor{
color:#006e28;
}
.ISO-C\+\+\:Symbol{
}
.ISO-C\+\+\:Decimal{
color:#b08000;
}
.ISO-C\+\+\:Data-Type{
color:#0057ae;
}
.ISO-C\+\+\:CONSTS\/MACROS{
}
.ISO-C\+\+\:Separator-Symbol{
}
.ISO-C\+\+\:Keyword{
font-weight:bold;
}
.ISO-C\+\+\:Prep\.-Lib{
color:#006e28;
}
.ISO-C\+\+\:String{
color:#bf0303;
}
.Alerts\:Alert-Level-2{
font-weight:bold;
color:#ca9219;
background-color:#451e1a;
}
</style>
</head>
<body>
<pre class="kate">
<span class="ISO-C++:Preprocessor">#include </span><span class="ISO-C++:Prep.-Lib">&lt;ktexteditor/document.h&gt;</span>
<span class="ISO-C++:Preprocessor">#include </span><span class="ISO-C++:Prep.-Lib">&lt;ktexteditor/view.h&gt;</span>
<span class="ISO-C++:Preprocessor">#include </span><span class="ISO-C++:Prep.-Lib">&lt;ktexteditor/editor.h&gt;</span>
<span class="ISO-C++:Preprocessor">#include </span><span class="ISO-C++:Prep.-Lib">&lt;ktexteditor/configinterface.h&gt;</span>
<span class="ISO-C++:Preprocessor">#include </span><span class="ISO-C++:Prep.-Lib">&lt;KAboutData&gt;</span>
<span class="ISO-C++:Preprocessor">#include </span><span class="ISO-C++:Prep.-Lib">&lt;QApplication&gt;</span>
<span class="ISO-C++:Preprocessor">#include </span><span class="ISO-C++:Prep.-Lib">&lt;QTextStream&gt;</span>
<span class="ISO-C++:Preprocessor">#include </span><span class="ISO-C++:Prep.-Lib">&lt;QUrl&gt;</span>
<span class="ISO-C++:Preprocessor">#include </span><span class="ISO-C++:Prep.-Lib">&lt;QDir&gt;</span>
<span class="ISO-C++:Preprocessor">#include </span><span class="ISO-C++:Prep.-Lib">&lt;QString&gt;</span>
<span class="ISO-C++:Preprocessor">#include </span><span class="ISO-C++:Prep.-Lib">&lt;QRegularExpression&gt;</span>
<span class="ISO-C++:Preprocessor">#include </span><span class="ISO-C++:Prep.-Lib">&lt;QCommandLineParser&gt;</span>
<span class="ISO-C++:Preprocessor">#include </span><span class="ISO-C++:Prep.-Lib">&lt;QTextCodec&gt;</span>
<span class="ISO-C++:Type-Modifiers">const</span> QRegularExpression <span class="ISO-C++:CONSTS/MACROS">WHITESPACE</span><span class="ISO-C++:Symbol">(</span><span class="ISO-C++:String">&quot;</span><span class="ISO-C++:String-Char">\\</span><span class="ISO-C++:String">s&quot;</span><span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Type-Modifiers">const</span> KTextEditor<span class="ISO-C++:Symbol">::</span>Attribute<span class="ISO-C++:Symbol">::</span>Ptr <span class="ISO-C++:CONSTS/MACROS">NO_ATTRIB</span><span class="ISO-C++:Symbol">(</span><span class="ISO-C++:Decimal">0</span><span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="Doxygen:Comment">/** </span><span class="Doxygen:Comment">Escape CSS identifiers or classes</span>
<span class="Doxygen:Comment"> * The grammar allows anything but whitespace, although anthing ASCII</span>
<span class="Doxygen:Comment"> * that isn’t letters, numbers, or dashes needs to be escaped.</span>
<span class="Doxygen:Comment"> * </span>
<span class="Doxygen:Comment"> * http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#w3cselgrammar</span>
<span class="Doxygen:Comment"> </span><span class="Doxygen:Comment">*/</span>
<span class="C++:Qt4-Classes">QString</span> maybeEscapeCSS<span class="ISO-C++:Symbol">(</span><span class="C++:Qt4-Classes">QChar</span> c<span class="ISO-C++:Separator-Symbol">,</span> <span class="ISO-C++:Data-Type">bool</span> start <span class="ISO-C++:Symbol">=</span> <span class="ISO-C++:Keyword">false</span><span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
<span class="ISO-C++:Data-Type">bool</span> alphanum <span class="ISO-C++:Symbol">=</span> <span class="ISO-C++:Symbol">(</span>start<span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">?</span> c<span class="ISO-C++:Symbol">.</span>isLetter<span class="ISO-C++:Symbol">()</span> <span class="ISO-C++:Symbol">:</span> c<span class="ISO-C++:Symbol">.</span>isLetterOrNumber<span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Keyword">if</span> <span class="ISO-C++:Symbol">(</span><span class="C++:Qt4-Classes">QString</span><span class="ISO-C++:Symbol">(</span>c<span class="ISO-C++:Symbol">).</span>contains<span class="ISO-C++:Symbol">(</span><span class="ISO-C++:CONSTS/MACROS">WHITESPACE</span><span class="ISO-C++:Symbol">))</span> <span class="ISO-C++:Symbol">{</span>
<span class="ISO-C++:Keyword">return</span> <span class="C++:Qt4-Classes">QString</span><span class="ISO-C++:Symbol">(</span><span class="ISO-C++:String">'-'</span><span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Comment">//if ASCII, but not in allowed range: escape</span>
<span class="ISO-C++:Symbol">}</span> <span class="ISO-C++:Keyword">else</span> <span class="ISO-C++:Keyword">if</span> <span class="ISO-C++:Symbol">(</span>c <span class="ISO-C++:Symbol">&lt;=</span> <span class="ISO-C++:Decimal">177</span> <span class="ISO-C++:Symbol">&amp;&amp;</span> c <span class="ISO-C++:Symbol">!=</span> <span class="ISO-C++:String">'-'</span> <span class="ISO-C++:Symbol">&amp;&amp;</span> c <span class="ISO-C++:Symbol">!=</span> <span class="ISO-C++:String">'_'</span> <span class="ISO-C++:Symbol">&amp;&amp;</span> <span class="ISO-C++:Symbol">!</span>alphanum<span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
<span class="ISO-C++:Keyword">return</span> <span class="ISO-C++:String">&quot;</span><span class="ISO-C++:String-Char">\\</span><span class="ISO-C++:String">&quot;</span> <span class="ISO-C++:Symbol">+</span> c<span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span> <span class="ISO-C++:Keyword">else</span> <span class="ISO-C++:Symbol">{</span>
<span class="ISO-C++:Keyword">return</span> <span class="C++:Qt4-Classes">QString</span><span class="ISO-C++:Symbol">(</span>c<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Symbol">}</span>
<span class="C++:Qt4-Classes">QString</span> slugifyCSS<span class="ISO-C++:Symbol">(</span><span class="C++:Qt4-Classes">QString</span> s<span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
<span class="ISO-C++:Keyword">if</span> <span class="ISO-C++:Symbol">(</span>s<span class="ISO-C++:Symbol">.</span>isEmpty<span class="ISO-C++:Symbol">())</span> <span class="ISO-C++:Keyword">return</span> <span class="ISO-C++:String">&quot;&quot;</span><span class="ISO-C++:Separator-Symbol">;</span> <span class="ISO-C++:Comment">//empty shouldn’t be allowed anyway</span>
<span class="C++:Qt4-Classes">QString</span> result<span class="ISO-C++:Separator-Symbol">;</span>
result<span class="ISO-C++:Symbol">.</span>reserve<span class="ISO-C++:Symbol">(</span>s<span class="ISO-C++:Symbol">.</span>size<span class="ISO-C++:Symbol">()</span> <span class="ISO-C++:Symbol">*</span> <span class="ISO-C++:Decimal">2</span><span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span> <span class="ISO-C++:Comment">//if everything needs to be escaped, we need twice the space</span>
result <span class="ISO-C++:Symbol">+=</span> maybeEscapeCSS<span class="ISO-C++:Symbol">(</span>s<span class="ISO-C++:Symbol">.</span>at<span class="ISO-C++:Symbol">(</span><span class="ISO-C++:Decimal">0</span><span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">,</span> <span class="ISO-C++:Keyword">true</span><span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Keyword">for</span> <span class="ISO-C++:Symbol">(</span><span class="ISO-C++:Data-Type">int</span> i <span class="ISO-C++:Symbol">=</span> <span class="ISO-C++:Decimal">1</span><span class="ISO-C++:Separator-Symbol">;</span> i <span class="ISO-C++:Symbol">&lt;</span> s<span class="ISO-C++:Symbol">.</span>size<span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">;</span> <span class="ISO-C++:Symbol">++</span>i<span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
result <span class="ISO-C++:Symbol">+=</span> maybeEscapeCSS<span class="ISO-C++:Symbol">(</span>s<span class="ISO-C++:Symbol">.</span>at<span class="ISO-C++:Symbol">(</span>i<span class="ISO-C++:Symbol">))</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Keyword">return</span> result<span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Keyword">class</span> HTML5Exporter <span class="ISO-C++:Symbol">{</span>
<span class="ISO-C++:Keyword">protected</span><span class="ISO-C++:Symbol">:</span>
<span class="C++:Qt4-Classes">QTextStream</span> <span class="ISO-C++:Symbol">&amp;</span> out<span class="ISO-C++:Separator-Symbol">;</span>
KTextEditor<span class="ISO-C++:Symbol">::</span>View <span class="ISO-C++:Symbol">*</span> view<span class="ISO-C++:Separator-Symbol">;</span>
KTextEditor<span class="ISO-C++:Symbol">::</span>Attribute<span class="ISO-C++:Symbol">::</span>Ptr defaultAttribute<span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Keyword">public</span><span class="ISO-C++:Symbol">:</span>
HTML5Exporter<span class="ISO-C++:Symbol">(</span><span class="C++:Qt4-Classes">QTextStream</span> <span class="ISO-C++:Symbol">&amp;</span> o<span class="ISO-C++:Separator-Symbol">,</span> KTextEditor<span class="ISO-C++:Symbol">::</span>View <span class="ISO-C++:Symbol">*</span> v<span class="ISO-C++:Separator-Symbol">,</span> <span class="C++:Qt4-Classes">QHash</span><span class="ISO-C++:Symbol">&lt;</span><span class="C++:Qt4-Classes">QString</span><span class="ISO-C++:Separator-Symbol">,</span> KTextEditor<span class="ISO-C++:Symbol">::</span>Attribute<span class="ISO-C++:Symbol">::</span>Ptr<span class="ISO-C++:Symbol">&gt;</span> <span class="ISO-C++:Symbol">&amp;</span> attrs<span class="ISO-C++:Symbol">):</span> out<span class="ISO-C++:Symbol">(</span>o<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">,</span> view<span class="ISO-C++:Symbol">(</span>v<span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
<span class="C++:Qt4-Classes">QColor</span> defaultBackground<span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Keyword">if</span> <span class="ISO-C++:Symbol">(</span>KTextEditor<span class="ISO-C++:Symbol">::</span>ConfigInterface <span class="ISO-C++:Symbol">*</span>ciface <span class="ISO-C++:Symbol">=</span> <span class="C++:Qt4-Functions">qobject_cast</span><span class="ISO-C++:Symbol">&lt;</span>KTextEditor<span class="ISO-C++:Symbol">::</span>ConfigInterface<span class="ISO-C++:Symbol">*&gt;(</span>view<span class="ISO-C++:Symbol">))</span> <span class="ISO-C++:Symbol">{</span>
<span class="C++:Qt4-Classes">QVariant</span> variant <span class="ISO-C++:Symbol">=</span> ciface<span class="ISO-C++:Symbol">-&gt;</span>configValue<span class="ISO-C++:Symbol">(</span><span class="C++:Qt4-Classes">QString</span><span class="ISO-C++:Symbol">(</span><span class="ISO-C++:String">&quot;background-color&quot;</span><span class="ISO-C++:Symbol">))</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Keyword">if</span> <span class="ISO-C++:Symbol">(</span>variant<span class="ISO-C++:Symbol">.</span>canConvert<span class="ISO-C++:Symbol">&lt;</span><span class="C++:Qt4-Classes">QColor</span><span class="ISO-C++:Symbol">&gt;())</span> <span class="ISO-C++:Symbol">{</span>
defaultBackground <span class="ISO-C++:Symbol">=</span> variant<span class="ISO-C++:Symbol">.</span>value<span class="ISO-C++:Symbol">&lt;</span><span class="C++:Qt4-Classes">QColor</span><span class="ISO-C++:Symbol">&gt;()</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Symbol">}</span>
defaultAttribute <span class="ISO-C++:Symbol">=</span> view<span class="ISO-C++:Symbol">-&gt;</span>defaultStyleAttribute<span class="ISO-C++:Symbol">(</span>KTextEditor<span class="ISO-C++:Symbol">::</span>dsNormal<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
defaultAttribute<span class="ISO-C++:Symbol">-&gt;</span>setBackground<span class="ISO-C++:Symbol">(</span><span class="C++:Qt4-Classes">QBrush</span><span class="ISO-C++:Symbol">(</span>defaultBackground<span class="ISO-C++:Symbol">))</span><span class="ISO-C++:Separator-Symbol">;</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;&lt;!DOCTYPE html&gt;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;&lt;html&gt;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;&lt;head&gt;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;&lt;meta charset=</span><span class="ISO-C++:String-Char">\&quot;</span><span class="ISO-C++:String">UTF-8</span><span class="ISO-C++:String-Char">\&quot;</span><span class="ISO-C++:String">&gt;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;&lt;meta name=</span><span class="ISO-C++:String-Char">\&quot;</span><span class="ISO-C++:String">Generator</span><span class="ISO-C++:String-Char">\&quot;</span><span class="ISO-C++:String"> content=</span><span class="ISO-C++:String-Char">\&quot;</span><span class="ISO-C++:String">Kate, the KDE Advanced Text Editor</span><span class="ISO-C++:String-Char">\&quot;</span><span class="ISO-C++:String">&gt;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;&lt;title&gt;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> view<span class="ISO-C++:Symbol">-&gt;</span>document<span class="ISO-C++:Symbol">()-&gt;</span>documentName<span class="ISO-C++:Symbol">()</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;&lt;/title&gt;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span>
exportStyle<span class="ISO-C++:Symbol">(</span>attrs<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;&lt;/head&gt;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;&lt;body&gt;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;&lt;pre class=</span><span class="ISO-C++:String-Char">\&quot;</span><span class="ISO-C++:String">kate</span><span class="ISO-C++:String-Char">\&quot;</span><span class="ISO-C++:String">&gt;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Symbol">~</span>HTML5Exporter<span class="ISO-C++:Symbol">()</span> <span class="ISO-C++:Symbol">{</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;&lt;/pre&gt;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;&lt;/body&gt;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;&lt;/html&gt;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span>
out<span class="ISO-C++:Symbol">.</span>flush<span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Data-Type">void</span> exportStyle<span class="ISO-C++:Symbol">(</span><span class="C++:Qt4-Classes">QHash</span><span class="ISO-C++:Symbol">&lt;</span><span class="C++:Qt4-Classes">QString</span><span class="ISO-C++:Separator-Symbol">,</span> KTextEditor<span class="ISO-C++:Symbol">::</span>Attribute<span class="ISO-C++:Symbol">::</span>Ptr<span class="ISO-C++:Symbol">&gt;</span> <span class="ISO-C++:Symbol">&amp;</span> attrs<span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;&lt;style&gt;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;pre.kate {&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Keyword">if</span> <span class="ISO-C++:Symbol">(</span>defaultAttribute<span class="ISO-C++:Symbol">-&gt;</span>fontBold<span class="ISO-C++:Symbol">()</span> <span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span> out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;font-weight:bold;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span> <span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Keyword">if</span> <span class="ISO-C++:Symbol">(</span>defaultAttribute<span class="ISO-C++:Symbol">-&gt;</span>fontItalic<span class="ISO-C++:Symbol">())</span> <span class="ISO-C++:Symbol">{</span> out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;font-style:italic;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span> <span class="ISO-C++:Symbol">}</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;color:&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> defaultAttribute<span class="ISO-C++:Symbol">-&gt;</span>foreground<span class="ISO-C++:Symbol">().</span>color<span class="ISO-C++:Symbol">().</span>name<span class="ISO-C++:Symbol">()</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;background-color:&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> defaultAttribute<span class="ISO-C++:Symbol">-&gt;</span>background<span class="ISO-C++:Symbol">().</span>color<span class="ISO-C++:Symbol">().</span>name<span class="ISO-C++:Symbol">()</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;}&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Keyword">for</span> <span class="ISO-C++:Symbol">(</span><span class="C++:Qt4-Classes">QHash</span><span class="ISO-C++:Symbol">&lt;</span><span class="C++:Qt4-Classes">QString</span><span class="ISO-C++:Separator-Symbol">,</span> KTextEditor<span class="ISO-C++:Symbol">::</span>Attribute<span class="ISO-C++:Symbol">::</span>Ptr<span class="ISO-C++:Symbol">&gt;::</span>const_iterator i <span class="ISO-C++:Symbol">=</span> attrs<span class="ISO-C++:Symbol">.</span>constBegin<span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">;</span> i <span class="ISO-C++:Symbol">!=</span> attrs<span class="ISO-C++:Symbol">.</span>constEnd<span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">;</span> <span class="ISO-C++:Symbol">++</span>i<span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">'.'</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> slugifyCSS<span class="ISO-C++:Symbol">(</span>i<span class="ISO-C++:Symbol">.</span>key<span class="ISO-C++:Symbol">())</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;{&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span>
KTextEditor<span class="ISO-C++:Symbol">::</span>Attribute<span class="ISO-C++:Symbol">::</span>Ptr attrib <span class="ISO-C++:Symbol">=</span> i<span class="ISO-C++:Symbol">.</span>value<span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Data-Type">bool</span> writeForeground <span class="ISO-C++:Symbol">=</span> attrib<span class="ISO-C++:Symbol">-&gt;</span>hasProperty<span class="ISO-C++:Symbol">(</span><span class="C++:Qt4-Classes">QTextCharFormat::ForegroundBrush</span><span class="ISO-C++:Symbol">)</span>
<span class="ISO-C++:Symbol">&amp;&amp;</span> attrib<span class="ISO-C++:Symbol">-&gt;</span>foreground<span class="ISO-C++:Symbol">().</span>color<span class="ISO-C++:Symbol">()</span> <span class="ISO-C++:Symbol">!=</span> defaultAttribute<span class="ISO-C++:Symbol">-&gt;</span>foreground<span class="ISO-C++:Symbol">().</span>color<span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Data-Type">bool</span> writeBackground <span class="ISO-C++:Symbol">=</span> attrib<span class="ISO-C++:Symbol">-&gt;</span>hasProperty<span class="ISO-C++:Symbol">(</span><span class="C++:Qt4-Classes">QTextCharFormat::BackgroundBrush</span><span class="ISO-C++:Symbol">)</span>
<span class="ISO-C++:Symbol">&amp;&amp;</span> attrib<span class="ISO-C++:Symbol">-&gt;</span>background<span class="ISO-C++:Symbol">().</span>color<span class="ISO-C++:Symbol">()</span> <span class="ISO-C++:Symbol">!=</span> defaultAttribute<span class="ISO-C++:Symbol">-&gt;</span>background<span class="ISO-C++:Symbol">().</span>color<span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Keyword">if</span> <span class="ISO-C++:Symbol">(</span>attrib<span class="ISO-C++:Symbol">-&gt;</span>fontBold<span class="ISO-C++:Symbol">()</span> <span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span> out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;font-weight:bold;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span> <span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Keyword">if</span> <span class="ISO-C++:Symbol">(</span>attrib<span class="ISO-C++:Symbol">-&gt;</span>fontItalic<span class="ISO-C++:Symbol">())</span> <span class="ISO-C++:Symbol">{</span> out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;font-style:italic;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span> <span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Keyword">if</span> <span class="ISO-C++:Symbol">(</span>writeForeground<span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span> out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;color:&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> attrib<span class="ISO-C++:Symbol">-&gt;</span>foreground<span class="ISO-C++:Symbol">().</span>color<span class="ISO-C++:Symbol">().</span>name<span class="ISO-C++:Symbol">()</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span> <span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Keyword">if</span> <span class="ISO-C++:Symbol">(</span>writeBackground<span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span> out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;background-color:&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> attrib<span class="ISO-C++:Symbol">-&gt;</span>background<span class="ISO-C++:Symbol">().</span>color<span class="ISO-C++:Symbol">().</span>name<span class="ISO-C++:Symbol">()</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span> <span class="ISO-C++:Symbol">}</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;}&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;&lt;/style&gt;&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Data-Type">void</span> exportText<span class="ISO-C++:Symbol">(</span><span class="ISO-C++:Type-Modifiers">const</span> <span class="C++:Qt4-Classes">QString</span> <span class="ISO-C++:Symbol">&amp;</span>text<span class="ISO-C++:Separator-Symbol">,</span> <span class="ISO-C++:Type-Modifiers">const</span> KTextEditor<span class="ISO-C++:Symbol">::</span>Attribute<span class="ISO-C++:Symbol">::</span>Ptr <span class="ISO-C++:Symbol">&amp;</span>attrib <span class="ISO-C++:Symbol">=</span> <span class="ISO-C++:CONSTS/MACROS">NO_ATTRIB</span><span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
<span class="ISO-C++:Keyword">if</span> <span class="ISO-C++:Symbol">(!</span>attrib <span class="ISO-C++:Symbol">||</span> <span class="ISO-C++:Symbol">!</span>attrib<span class="ISO-C++:Symbol">-&gt;</span>hasAnyProperty<span class="ISO-C++:Symbol">()</span> <span class="ISO-C++:Symbol">||</span> attrib <span class="ISO-C++:Symbol">==</span> defaultAttribute<span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> text<span class="ISO-C++:Symbol">.</span>toHtmlEscaped<span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Keyword">return</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;&lt;span class=</span><span class="ISO-C++:String-Char">\&quot;</span><span class="ISO-C++:String">&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> attrib<span class="ISO-C++:Symbol">-&gt;</span>name<span class="ISO-C++:Symbol">().</span>replace<span class="ISO-C++:Symbol">(</span><span class="ISO-C++:CONSTS/MACROS">WHITESPACE</span><span class="ISO-C++:Separator-Symbol">,</span> <span class="ISO-C++:String">&quot;-&quot;</span><span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;</span><span class="ISO-C++:String-Char">\&quot;</span><span class="ISO-C++:String">&gt;&quot;</span><span class="ISO-C++:Separator-Symbol">;</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> text<span class="ISO-C++:Symbol">.</span>toHtmlEscaped<span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">;</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;&lt;/span&gt;&quot;</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Data-Type">void</span> finishLine<span class="ISO-C++:Symbol">()</span> <span class="ISO-C++:Symbol">{</span>
out <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Symbol">}</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Data-Type">void</span> <span class="ISO-C++:Data-Members-(m_*)">export_</span><span class="ISO-C++:Symbol">(</span><span class="C++:Qt4-Classes">QTextStream</span> <span class="ISO-C++:Symbol">&amp;</span>out<span class="ISO-C++:Separator-Symbol">,</span> KTextEditor<span class="ISO-C++:Symbol">::</span>View <span class="ISO-C++:Symbol">*</span>view<span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
<span class="ISO-C++:Data-Type">int</span> lines <span class="ISO-C++:Symbol">=</span> view<span class="ISO-C++:Symbol">-&gt;</span>document<span class="ISO-C++:Symbol">()-&gt;</span>lines<span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Comment">//out.setEncoding(QTextStream::UnicodeUTF8);</span>
<span class="ISO-C++:Comment">//out.setCodec(QTextCodec::codecForName(&quot;UTF-8&quot;));</span>
<span class="C++:Qt4-Classes">QHash</span><span class="ISO-C++:Symbol">&lt;</span><span class="C++:Qt4-Classes">QString</span><span class="ISO-C++:Separator-Symbol">,</span> KTextEditor<span class="ISO-C++:Symbol">::</span>Attribute<span class="ISO-C++:Symbol">::</span>Ptr<span class="ISO-C++:Symbol">&gt;</span> attrs<span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Keyword">for</span> <span class="ISO-C++:Symbol">(</span><span class="ISO-C++:Data-Type">int</span> i <span class="ISO-C++:Symbol">=</span> <span class="ISO-C++:Decimal">0</span><span class="ISO-C++:Separator-Symbol">;</span> i <span class="ISO-C++:Symbol">&lt;</span> lines<span class="ISO-C++:Separator-Symbol">;</span> <span class="ISO-C++:Symbol">++</span>i<span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
<span class="ISO-C++:Type-Modifiers">const</span> <span class="C++:Qt4-Classes">QString</span> <span class="ISO-C++:Symbol">&amp;</span>line <span class="ISO-C++:Symbol">=</span> view<span class="ISO-C++:Symbol">-&gt;</span>document<span class="ISO-C++:Symbol">()-&gt;</span>line<span class="ISO-C++:Symbol">(</span>i<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="C++:Qt4-Classes">QList</span><span class="ISO-C++:Symbol">&lt;</span>KTextEditor<span class="ISO-C++:Symbol">::</span>AttributeBlock<span class="ISO-C++:Symbol">&gt;</span> attribs <span class="ISO-C++:Symbol">=</span> view<span class="ISO-C++:Symbol">-&gt;</span>lineAttributes<span class="ISO-C++:Symbol">(</span>i<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="C++:Qt4-Macros">foreach</span> <span class="ISO-C++:Symbol">(</span><span class="ISO-C++:Type-Modifiers">const</span> KTextEditor<span class="ISO-C++:Symbol">::</span>AttributeBlock <span class="ISO-C++:Symbol">&amp;</span> block<span class="ISO-C++:Separator-Symbol">,</span> attribs<span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
<span class="ISO-C++:Keyword">if</span> <span class="ISO-C++:Symbol">(!</span>attrs<span class="ISO-C++:Symbol">.</span>contains<span class="ISO-C++:Symbol">(</span>block<span class="ISO-C++:Symbol">.</span>attribute<span class="ISO-C++:Symbol">-&gt;</span>name<span class="ISO-C++:Symbol">()))</span> <span class="ISO-C++:Symbol">{</span>
attrs<span class="ISO-C++:Symbol">[</span>block<span class="ISO-C++:Symbol">.</span>attribute<span class="ISO-C++:Symbol">-&gt;</span>name<span class="ISO-C++:Symbol">()]</span> <span class="ISO-C++:Symbol">=</span> block<span class="ISO-C++:Symbol">.</span>attribute<span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Symbol">}</span>
HTML5Exporter exporter<span class="ISO-C++:Symbol">(</span>out<span class="ISO-C++:Separator-Symbol">,</span> view<span class="ISO-C++:Separator-Symbol">,</span> attrs<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Keyword">for</span> <span class="ISO-C++:Symbol">(</span><span class="ISO-C++:Data-Type">int</span> i <span class="ISO-C++:Symbol">=</span> <span class="ISO-C++:Decimal">0</span><span class="ISO-C++:Separator-Symbol">;</span> i <span class="ISO-C++:Symbol">&lt;</span> lines<span class="ISO-C++:Separator-Symbol">;</span> <span class="ISO-C++:Symbol">++</span>i<span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
<span class="ISO-C++:Type-Modifiers">const</span> <span class="C++:Qt4-Classes">QString</span> <span class="ISO-C++:Symbol">&amp;</span>line <span class="ISO-C++:Symbol">=</span> view<span class="ISO-C++:Symbol">-&gt;</span>document<span class="ISO-C++:Symbol">()-&gt;</span>line<span class="ISO-C++:Symbol">(</span>i<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="C++:Qt4-Classes">QList</span><span class="ISO-C++:Symbol">&lt;</span>KTextEditor<span class="ISO-C++:Symbol">::</span>AttributeBlock<span class="ISO-C++:Symbol">&gt;</span> attribs <span class="ISO-C++:Symbol">=</span> view<span class="ISO-C++:Symbol">-&gt;</span>lineAttributes<span class="ISO-C++:Symbol">(</span>i<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Data-Type">int</span> lineStart <span class="ISO-C++:Symbol">=</span> <span class="ISO-C++:Decimal">0</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Data-Type">int</span> remainingChars <span class="ISO-C++:Symbol">=</span> line<span class="ISO-C++:Symbol">.</span>length<span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Data-Type">int</span> handledUntil <span class="ISO-C++:Symbol">=</span> lineStart<span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Region-Marker">//</span><span class="ISO-C++:Comment"> qDebug() &lt;&lt; &quot;size:&quot; &lt;&lt; attribs.size();</span>
<span class="C++:Qt4-Macros">foreach</span> <span class="ISO-C++:Symbol">(</span><span class="ISO-C++:Type-Modifiers">const</span> KTextEditor<span class="ISO-C++:Symbol">::</span>AttributeBlock <span class="ISO-C++:Symbol">&amp;</span> block<span class="ISO-C++:Separator-Symbol">,</span> attribs<span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
<span class="ISO-C++:Comment">// honor (block-) selections</span>
<span class="ISO-C++:Keyword">if</span> <span class="ISO-C++:Symbol">(</span>block<span class="ISO-C++:Symbol">.</span>start <span class="ISO-C++:Symbol">+</span> block<span class="ISO-C++:Symbol">.</span>length <span class="ISO-C++:Symbol">&lt;=</span> lineStart<span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
<span class="ISO-C++:Keyword">continue</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span> <span class="ISO-C++:Keyword">else</span> <span class="ISO-C++:Keyword">if</span> <span class="ISO-C++:Symbol">(</span>block<span class="ISO-C++:Symbol">.</span>start <span class="ISO-C++:Symbol">&gt;=</span> lineStart <span class="ISO-C++:Symbol">+</span> remainingChars<span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
<span class="ISO-C++:Keyword">break</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Data-Type">int</span> start <span class="ISO-C++:Symbol">=</span> <span class="C++:Qt4-Functions">qMax</span><span class="ISO-C++:Symbol">(</span>block<span class="ISO-C++:Symbol">.</span>start<span class="ISO-C++:Separator-Symbol">,</span> lineStart<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Keyword">if</span> <span class="ISO-C++:Symbol">(</span>start <span class="ISO-C++:Symbol">&gt;</span> handledUntil<span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
exporter<span class="ISO-C++:Symbol">.</span>exportText<span class="ISO-C++:Symbol">(</span>line<span class="ISO-C++:Symbol">.</span>mid<span class="ISO-C++:Symbol">(</span>handledUntil<span class="ISO-C++:Separator-Symbol">,</span> start <span class="ISO-C++:Symbol">-</span> handledUntil<span class="ISO-C++:Symbol">))</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Data-Type">int</span> length <span class="ISO-C++:Symbol">=</span> <span class="C++:Qt4-Functions">qMin</span><span class="ISO-C++:Symbol">(</span>block<span class="ISO-C++:Symbol">.</span>length<span class="ISO-C++:Separator-Symbol">,</span> remainingChars<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
exporter<span class="ISO-C++:Symbol">.</span>exportText<span class="ISO-C++:Symbol">(</span>line<span class="ISO-C++:Symbol">.</span>mid<span class="ISO-C++:Symbol">(</span>start<span class="ISO-C++:Separator-Symbol">,</span> length<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">,</span> block<span class="ISO-C++:Symbol">.</span>attribute<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
handledUntil <span class="ISO-C++:Symbol">=</span> start <span class="ISO-C++:Symbol">+</span> length<span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Keyword">if</span> <span class="ISO-C++:Symbol">(</span>handledUntil <span class="ISO-C++:Symbol">&lt;</span> lineStart <span class="ISO-C++:Symbol">+</span> remainingChars<span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
exporter<span class="ISO-C++:Symbol">.</span>exportText<span class="ISO-C++:Symbol">(</span>line<span class="ISO-C++:Symbol">.</span>mid<span class="ISO-C++:Symbol">(</span>handledUntil<span class="ISO-C++:Separator-Symbol">,</span> remainingChars<span class="ISO-C++:Symbol">))</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Keyword">if</span> <span class="ISO-C++:Symbol">(</span>i <span class="ISO-C++:Symbol">!=</span> lines <span class="ISO-C++:Symbol">-</span> <span class="ISO-C++:Decimal">1</span><span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
exporter<span class="ISO-C++:Symbol">.</span>finishLine<span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Data-Type">void</span> run<span class="ISO-C++:Symbol">(</span>QCommandLineParser <span class="ISO-C++:Symbol">&amp;</span> parser<span class="ISO-C++:Separator-Symbol">,</span> KTextEditor<span class="ISO-C++:Symbol">::</span>View <span class="ISO-C++:Symbol">*</span> view<span class="ISO-C++:Separator-Symbol">,</span> <span class="C++:Qt4-Classes">QTextStream</span> <span class="ISO-C++:Symbol">&amp;</span> stdOut<span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
<span class="ISO-C++:Type-Modifiers">const</span> <span class="C++:Qt4-Classes">QStringList</span> args <span class="ISO-C++:Symbol">=</span> parser<span class="ISO-C++:Symbol">.</span>positionalArguments<span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Comment">//Source</span>
<span class="ISO-C++:Keyword">if</span> <span class="ISO-C++:Symbol">(</span>args<span class="ISO-C++:Symbol">.</span>length<span class="ISO-C++:Symbol">()</span> <span class="ISO-C++:Symbol">&lt;</span> <span class="ISO-C++:Decimal">1</span> <span class="ISO-C++:Symbol">||</span> args<span class="ISO-C++:Symbol">.</span>at<span class="ISO-C++:Symbol">(</span><span class="ISO-C++:Decimal">0</span><span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">==</span> <span class="ISO-C++:String">&quot;-&quot;</span><span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
<span class="C++:Qt4-Classes">QTextStream</span> input<span class="ISO-C++:Symbol">(</span>stdin<span class="ISO-C++:Separator-Symbol">,</span> <span class="C++:Qt4-Classes">QIODevice::ReadOnly</span><span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
input<span class="ISO-C++:Symbol">.</span>setCodec<span class="ISO-C++:Symbol">(</span><span class="C++:Qt4-Classes">QTextCodec::codecForName</span><span class="ISO-C++:Symbol">(</span><span class="ISO-C++:String">&quot;UTF-8&quot;</span><span class="ISO-C++:Symbol">))</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="C++:Qt4-Classes">QString</span> line<span class="ISO-C++:Separator-Symbol">,</span> text<span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Keyword">do</span> <span class="ISO-C++:Symbol">{</span>
line <span class="ISO-C++:Symbol">=</span> input<span class="ISO-C++:Symbol">.</span>readLine<span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">;</span>
text<span class="ISO-C++:Symbol">.</span>append<span class="ISO-C++:Symbol">(</span>line <span class="ISO-C++:Symbol">+</span> <span class="C++:Qt4-Classes">QLatin1Char</span><span class="ISO-C++:Symbol">(</span><span class="ISO-C++:String">'</span><span class="ISO-C++:String-Char">\n</span><span class="ISO-C++:String">'</span><span class="ISO-C++:Symbol">))</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span> <span class="ISO-C++:Keyword">while</span> <span class="ISO-C++:Symbol">(!</span>line<span class="ISO-C++:Symbol">.</span>isNull<span class="ISO-C++:Symbol">())</span><span class="ISO-C++:Separator-Symbol">;</span>
view<span class="ISO-C++:Symbol">-&gt;</span>document<span class="ISO-C++:Symbol">()-&gt;</span>setText<span class="ISO-C++:Symbol">(</span>text<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Comment">//</span><span class="Alerts:Alert-Level-2">TODO</span><span class="ISO-C++:Comment">: highlighting</span>
<span class="ISO-C++:Symbol">}</span> <span class="ISO-C++:Keyword">else</span> <span class="ISO-C++:Symbol">{</span>
<span class="C++:Qt4-Classes">QUrl</span> url<span class="ISO-C++:Symbol">(</span>args<span class="ISO-C++:Symbol">.</span>at<span class="ISO-C++:Symbol">(</span><span class="ISO-C++:Decimal">0</span><span class="ISO-C++:Symbol">))</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Keyword">if</span> <span class="ISO-C++:Symbol">(</span>url<span class="ISO-C++:Symbol">.</span>scheme<span class="ISO-C++:Symbol">().</span>isEmpty<span class="ISO-C++:Symbol">())</span> <span class="ISO-C++:Symbol">{</span>
url<span class="ISO-C++:Symbol">.</span>setScheme<span class="ISO-C++:Symbol">(</span><span class="C++:Qt4-Classes">QString</span><span class="ISO-C++:Symbol">(</span><span class="ISO-C++:String">&quot;file&quot;</span><span class="ISO-C++:Symbol">))</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span>
view<span class="ISO-C++:Symbol">-&gt;</span>document<span class="ISO-C++:Symbol">()-&gt;</span>openUrl<span class="ISO-C++:Symbol">(</span>url<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Comment">//Target</span>
<span class="ISO-C++:Keyword">if</span> <span class="ISO-C++:Symbol">(</span>args<span class="ISO-C++:Symbol">.</span>length<span class="ISO-C++:Symbol">()</span> <span class="ISO-C++:Symbol">&lt;</span> <span class="ISO-C++:Decimal">2</span> <span class="ISO-C++:Symbol">||</span> args<span class="ISO-C++:Symbol">.</span>at<span class="ISO-C++:Symbol">(</span><span class="ISO-C++:Decimal">1</span><span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">==</span> <span class="ISO-C++:String">&quot;-&quot;</span><span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
<span class="ISO-C++:Data-Members-(m_*)">export_</span><span class="ISO-C++:Symbol">(</span>stdOut<span class="ISO-C++:Separator-Symbol">,</span> view<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span> <span class="ISO-C++:Keyword">else</span> <span class="ISO-C++:Symbol">{</span>
<span class="C++:Qt4-Classes">QFile</span> file<span class="ISO-C++:Symbol">(</span>args<span class="ISO-C++:Symbol">.</span>at<span class="ISO-C++:Symbol">(</span><span class="ISO-C++:Decimal">1</span><span class="ISO-C++:Symbol">))</span><span class="ISO-C++:Separator-Symbol">;</span>
file<span class="ISO-C++:Symbol">.</span>open<span class="ISO-C++:Symbol">(</span><span class="C++:Qt4-Classes">QIODevice::WriteOnly</span> <span class="ISO-C++:Symbol">|</span> <span class="C++:Qt4-Classes">QIODevice::Text</span><span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="C++:Qt4-Classes">QTextStream</span> out<span class="ISO-C++:Symbol">(&amp;</span>file<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
out<span class="ISO-C++:Symbol">.</span>setCodec<span class="ISO-C++:Symbol">(</span><span class="C++:Qt4-Classes">QTextCodec::codecForName</span><span class="ISO-C++:Symbol">(</span><span class="ISO-C++:String">&quot;UTF-8&quot;</span><span class="ISO-C++:Symbol">))</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Data-Members-(m_*)">export_</span><span class="ISO-C++:Symbol">(</span>out<span class="ISO-C++:Separator-Symbol">,</span> view<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
file<span class="ISO-C++:Symbol">.</span>close<span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Type-Modifiers">extern</span> <span class="ISO-C++:String">&quot;C&quot;</span> <span class="ISO-C++:CONSTS/MACROS">Q_DECL_EXPORT</span> <span class="ISO-C++:Data-Type">int</span> kdemain<span class="ISO-C++:Symbol">(</span><span class="ISO-C++:Data-Type">int</span> argc<span class="ISO-C++:Separator-Symbol">,</span> <span class="ISO-C++:Data-Type">char</span> <span class="ISO-C++:Symbol">**</span>argv<span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
<span class="C++:Qt4-Classes">QApplication</span> app<span class="ISO-C++:Symbol">(</span>argc<span class="ISO-C++:Separator-Symbol">,</span> argv<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
KAboutData aboutData<span class="ISO-C++:Symbol">(</span><span class="ISO-C++:String">&quot;khighlighter&quot;</span><span class="ISO-C++:Separator-Symbol">,</span> <span class="ISO-C++:String">&quot;KHighlighter&quot;</span><span class="ISO-C++:Separator-Symbol">,</span> <span class="ISO-C++:String">&quot;0.1&quot;</span><span class="ISO-C++:Separator-Symbol">,</span> <span class="ISO-C++:String">&quot;Kate-based syntax highlighter&quot;</span><span class="ISO-C++:Separator-Symbol">,</span> KAboutLicense<span class="ISO-C++:Symbol">::</span><span class="ISO-C++:CONSTS/MACROS">LGPL_V2</span><span class="ISO-C++:Separator-Symbol">,</span>
<span class="ISO-C++:String">&quot;(c) 2014 Phil Schaf&quot;</span><span class="ISO-C++:Separator-Symbol">,</span> <span class="C++:Qt4-Classes">QString</span><span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">,</span> <span class="ISO-C++:String">&quot;http://kate-editor.org&quot;</span><span class="ISO-C++:Separator-Symbol">,</span> <span class="ISO-C++:String">&quot;flying-sheep@web.de&quot;</span><span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
QCommandLineParser parser<span class="ISO-C++:Separator-Symbol">;</span>
aboutData<span class="ISO-C++:Symbol">.</span>setupCommandLine<span class="ISO-C++:Symbol">(&amp;</span>parser<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
parser<span class="ISO-C++:Symbol">.</span>setApplicationDescription<span class="ISO-C++:Symbol">(</span>aboutData<span class="ISO-C++:Symbol">.</span>shortDescription<span class="ISO-C++:Symbol">())</span><span class="ISO-C++:Separator-Symbol">;</span>
parser<span class="ISO-C++:Symbol">.</span>addHelpOption<span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">;</span>
parser<span class="ISO-C++:Symbol">.</span>addVersionOption<span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">;</span>
QCommandLineOption optionLang<span class="ISO-C++:Symbol">(</span><span class="C++:Qt4-Classes">QStringList</span><span class="ISO-C++:Symbol">()</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;l&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;lang&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;language&quot;</span><span class="ISO-C++:Separator-Symbol">,</span> <span class="ISO-C++:String">&quot;Set the highlighting language.</span><span class="ISO-C++:String-Char">\n</span><span class="ISO-C++:String">Default: inferred from the source file.&quot;</span><span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
parser<span class="ISO-C++:Symbol">.</span>addOption<span class="ISO-C++:Symbol">(</span>optionLang<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
QCommandLineOption optionLangs<span class="ISO-C++:Symbol">(</span><span class="C++:Qt4-Classes">QStringList</span><span class="ISO-C++:Symbol">()</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;langs&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;languages&quot;</span> <span class="ISO-C++:Symbol">&lt;&lt;</span> <span class="ISO-C++:String">&quot;list-langs&quot;</span><span class="ISO-C++:Separator-Symbol">,</span> <span class="ISO-C++:String">&quot;List available highlighting languages.&quot;</span><span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
parser<span class="ISO-C++:Symbol">.</span>addOption<span class="ISO-C++:Symbol">(</span>optionLangs<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Region-Marker">//</span><span class="ISO-C++:Comment"> QCommandLineOption optionTheme(QStringList() &lt;&lt; &quot;t&quot; &lt;&lt; &quot;theme&quot;, &quot;Set the highlighting color theme.&quot;);</span>
<span class="ISO-C++:Region-Marker">//</span><span class="ISO-C++:Comment"> parser.addOption(optionTheme);</span>
<span class="ISO-C++:Region-Marker">//</span><span class="ISO-C++:Comment"> QCommandLineOption optionThemes(QStringList() &lt;&lt; &quot;themes&quot; &lt;&lt; &quot;list-themes&quot;, &quot;List available highlighting color themes.&quot;);</span>
<span class="ISO-C++:Region-Marker">//</span><span class="ISO-C++:Comment"> parser.addOption(optionThemes);</span>
parser<span class="ISO-C++:Symbol">.</span>addPositionalArgument<span class="ISO-C++:Symbol">(</span><span class="ISO-C++:String">&quot;source&quot;</span><span class="ISO-C++:Separator-Symbol">,</span> <span class="ISO-C++:String">&quot;File to highlight.</span><span class="ISO-C++:String-Char">\n</span><span class="ISO-C++:String">Default: - (Std. in)&quot;</span><span class="ISO-C++:Separator-Symbol">,</span> <span class="ISO-C++:String">&quot;[source]&quot;</span><span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
parser<span class="ISO-C++:Symbol">.</span>addPositionalArgument<span class="ISO-C++:Symbol">(</span><span class="ISO-C++:String">&quot;target&quot;</span><span class="ISO-C++:Separator-Symbol">,</span> <span class="ISO-C++:String">&quot;File to write output to.</span><span class="ISO-C++:String-Char">\n</span><span class="ISO-C++:String">Default: - (Std. out)&quot;</span><span class="ISO-C++:Separator-Symbol">,</span> <span class="ISO-C++:String">&quot;[target]&quot;</span><span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
parser<span class="ISO-C++:Symbol">.</span>process<span class="ISO-C++:Symbol">(</span>app<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
KTextEditor<span class="ISO-C++:Symbol">::</span>Editor<span class="ISO-C++:Symbol">*</span> editor <span class="ISO-C++:Symbol">=</span> KTextEditor<span class="ISO-C++:Symbol">::</span>Editor<span class="ISO-C++:Symbol">::</span>instance<span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">;</span>
KTextEditor<span class="ISO-C++:Symbol">::</span>Document <span class="ISO-C++:Symbol">*</span>document <span class="ISO-C++:Symbol">=</span> editor<span class="ISO-C++:Symbol">-&gt;</span>createDocument<span class="ISO-C++:Symbol">(</span><span class="ISO-C++:Decimal">0</span><span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
KTextEditor<span class="ISO-C++:Symbol">::</span>View <span class="ISO-C++:Symbol">*</span>view <span class="ISO-C++:Symbol">=</span> document<span class="ISO-C++:Symbol">-&gt;</span>createView<span class="ISO-C++:Symbol">(</span><span class="ISO-C++:Decimal">0</span><span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="C++:Qt4-Classes">QTextStream</span> stdOut<span class="ISO-C++:Symbol">(</span>stdout<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Keyword">if</span> <span class="ISO-C++:Symbol">(</span>parser<span class="ISO-C++:Symbol">.</span>isSet<span class="ISO-C++:Symbol">(</span>optionLangs<span class="ISO-C++:Symbol">))</span> <span class="ISO-C++:Symbol">{</span>
<span class="C++:Qt4-Classes">QStringList</span> langs <span class="ISO-C++:Symbol">=</span> document<span class="ISO-C++:Symbol">-&gt;</span>highlightingModes<span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="C++:Qt4-Macros">foreach</span><span class="ISO-C++:Symbol">(</span><span class="C++:Qt4-Classes">QString</span> lang<span class="ISO-C++:Separator-Symbol">,</span> langs<span class="ISO-C++:Symbol">)</span> <span class="ISO-C++:Symbol">{</span>
stdOut <span class="ISO-C++:Symbol">&lt;&lt;</span> lang <span class="ISO-C++:Symbol">&lt;&lt;</span> endl<span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span>
app<span class="ISO-C++:Symbol">.</span>quit<span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Keyword">return</span> <span class="ISO-C++:Decimal">0</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Symbol">}</span>
<span class="ISO-C++:Region-Marker">//</span><span class="ISO-C++:Comment"> if (parser.isSet(optionThemes)) {</span>
<span class="ISO-C++:Region-Marker">//</span><span class="ISO-C++:Comment"> QStringList langs = view-&gt;();</span>
<span class="ISO-C++:Region-Marker">//</span><span class="ISO-C++:Comment"> foreach(QString lang, langs) {</span>
<span class="ISO-C++:Region-Marker">//</span><span class="ISO-C++:Comment"> stdOut &lt;&lt; lang &lt;&lt; endl;</span>
<span class="ISO-C++:Region-Marker">//</span><span class="ISO-C++:Comment"> }</span>
<span class="ISO-C++:Region-Marker">//</span><span class="ISO-C++:Comment"> app.quit();</span>
<span class="ISO-C++:Region-Marker">//</span><span class="ISO-C++:Comment"> return 0;</span>
<span class="ISO-C++:Region-Marker">//</span><span class="ISO-C++:Comment"> }</span>
run<span class="ISO-C++:Symbol">(</span>parser<span class="ISO-C++:Separator-Symbol">,</span> view<span class="ISO-C++:Separator-Symbol">,</span> stdOut<span class="ISO-C++:Symbol">)</span><span class="ISO-C++:Separator-Symbol">;</span>
app<span class="ISO-C++:Symbol">.</span>quit<span class="ISO-C++:Symbol">()</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Keyword">return</span> <span class="ISO-C++:Decimal">0</span><span class="ISO-C++:Separator-Symbol">;</span>
<span class="ISO-C++:Comment">//return app.exec();</span>
<span class="ISO-C++:Symbol">}</span></pre>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment