How to highlite blocks of HTML code in c++ code?

Issue

I write web project on c++. In my c++ code has to insert html, for example such

void CPage::putBaseFooter() {
  if(m_canRender) {
    HTML(
      <!++
      </main>
      <footer>
          <f++ composePageFooter(); ++f>
      </footer>
      </body>
      </html>
      ++!>);
  }
}

That is the whole html code is between <!++ and ++!> (Code is processed before compiling its own preprocessor to string)

Just have your own macros preprocessor, such as for example

<f++ composeHead(); ++f>
<v++ ts.tm_year + 1900++v>
<paged_list++ [day_tasks_control] [/tasks/list] [taskListRenderer]>
...
<++paged_list>
<labeled_control++ [Description] [taskDescription]>
  <textarea></textarea>
<++labeled_control>

Tell me please, how i can highlite html keywords and own macroses into qt-creator code editor? I tried to write a higlite-xml for Kate (with inheritance c++ highlite), but probably something I do not understand, since the backlight does not work.

Here are my sketches syntax highlighting

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd"
[
    <!ENTITY space " ">
    <!ENTITY separators ",&#59;">
    <!ENTITY ns_punctuators "!&#37;&space;&amp;()+-/.*&lt;=&gt;?[]{|}~^&separators;">
]>
<!--
  Copyright (c) 2012 by Alex Turbov (i.zaufi@gmail.com)
  -->
<language
    name="C++"
    section="Sources"
    version="1.0"
    kateversion="2.4"
    indenter="cstyle"
    style="C++"
    mimetype="text/x-c++src;text/x-c++hdr;text/x-chdr"
    extensions="*.c++;*.cxx;*.cpp;*.cc;*.C;*.h;*.hh;*.H;*.h++;*.hxx;*.hpp;*.hcc;*.moc"
    author="Sheridan (gorlov.maxim@gmail.com)"
    license="LGPL"
    priority="11"
  >

<highlighting>

  <list name="InplaceHTML">
    <item> form </item>
    <item> table </item>
    <item> div </item>
    <item> td </item>
    <item> tr </item>
    <item> th </item>
    <item> span </item>
    <item> input </item>
    <item> textarea </item>
    <item> label </item>
    <item> a </item>
    <item> head </item>
    <item> link </item>
    <item> script </item>
  </list>

  <contexts>

    <context attribute="Normal Text" lineEndContext="#stay" name="Normal">
      <IncludeRules context="##C++" />
      <IncludeRules context="DetectInplaceHTML" />
    </context>

    <context attribute="Normal Text" lineEndContext="#stay" name="DetectInplaceHTML">
      <keyword attribute="Inplace HTML" context="#stay" String="InplaceHTML" />
    </context>

  </contexts>

  <itemDatas>
    <itemData name="Normal Text"    defStyleNum="dsNormal" spellChecking="false" />
    <itemData name="Inplace HTML" defStyleNum="dsKeyword" color="#0095ff" selColor="#ffffff" bold="1" italic="0" spellChecking="false" />
  </itemDatas>
</highlighting>

</language>

Solution

The Kate C++ highlighting is not used in Qt Creator, changing/extending the Kate configuration file won’t have anny affect. You could try to register a separate mime type that’s not recognized as C or C++ by Qt Creator and write a Kate highlighter for that, but I don’t know whether this would work.

Answered By – tors

Answer Checked By – Mary Flores (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.