From 4a0d06c45bd07b72e8dc5ef24d8fd5f830829420 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Thu, 4 Aug 2016 12:07:02 -0400 Subject: Another large update to syntax highlighting for .rst files (and some overall changed to the order in which highlighting rules are applied - works for all file types). --- .../lumina-textedit/syntaxSupport.cpp | 40 ++++++++++++++++------ .../desktop-utils/lumina-textedit/syntaxSupport.h | 33 ++++++++++++------ .../desktop-utils/lumina-textedit/tests/test.rst | 10 +++++- 3 files changed, 60 insertions(+), 23 deletions(-) (limited to 'src-qt5/desktop-utils') diff --git a/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp b/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp index 10eec73d..9997961b 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp @@ -143,14 +143,14 @@ void Custom_Syntax::loadRules(QString type){ }else if(type=="reST"){ SyntaxRule rule; // directives - rule.format.setForeground( QColor(settings->value("colors/keyword").toString()) ); + rule.format.setForeground( QColor(settings->value("colors/class").toString()) ); rule.format.setFontItalic(false); - rule.pattern = QRegExp("\\s[:].*[:]`.*`\\s"); + rule.pattern = QRegExp("(\\s|^):[a-zA-Z0-9 ]*:`[^`]*`(?=(\\s|$))"); rules << rule; - // Emphasis + // hyperlinks rule.format.setFontItalic(true); rule.format.setFontWeight(QFont::Normal); - rule.pattern = QRegExp("\\b[*][^*\n]+[*]\\b"); + rule.pattern = QRegExp("`[^\\<]*\\<[^\\>]*\\>`_(\\s|$)"); rules << rule; // Code Sample rule.format.setFontItalic(false); @@ -166,23 +166,41 @@ void Custom_Syntax::loadRules(QString type){ //TODO rule = SyntaxRule(); //reset rule rule.format.setFontWeight( QFont::Bold ); - rule.pattern = QRegExp("\\bTODO\\b"); + rule.pattern = QRegExp("^\\.\\.\\sTODO\\b"); + rules << rule; + rule = SyntaxRule(); //reset rule + rule.format.setFontWeight( QFont::Bold ); + rule.pattern = QRegExp("^\\.\\.\\s(note|warning|important)::\\s"); rules << rule; //Functions rule = SyntaxRule(); //reset rule - rule.format.setBackground( QColor(settings->value("colors/function").toString()) ); - rule.pattern = QRegExp("^(\\s*)\\.\\.(\\s*)\\b_[a-zA-Z0-9]*:(\\s|$)"); + rule.format.setForeground( QColor(settings->value("colors/preprocessor").toString()) ); + rule.pattern = QRegExp("^(\\s*)\\.\\.(\\s*)\\b_[a-zA-Z0-9 ]*:(\\s|$)"); rules << rule; - //figures and other statements + //figures and other properties for them rule = SyntaxRule(); //reset rule - rule.format.setForeground( QColor(settings->value("colors/function").toString()) ); + rule.format.setForeground( QColor(settings->value("colors/keyword").toString()) ); rule.pattern = QRegExp("^(\\s*)\\.\\.\\sfigure::\\s"); rules << rule; - //Comment (multi-line) + rule = SyntaxRule(); //reset rule + rule.format.setForeground( QColor(settings->value("colors/altkeyword").toString()) ); + rule.pattern = QRegExp("^( ){3}:(.)*: "); + rules << rule; + + //Code Blocks SyntaxRuleSplit srule; + srule.format.setBackground( QColor("lightblue") ); + srule.startPattern = QRegExp("\\:\\:$"); + srule.endPattern = QRegExp("^(?=[^\\s])"); + splitrules << srule; + srule.startPattern = QRegExp("^(\\s*)\\.\\.\\scode-block::\\s"); //alternate start string for the same rule + srule.endPattern = QRegExp("^(?=[^\\s])"); + splitrules << srule; + //Comment (multi-line) + srule = SyntaxRuleSplit(); srule.format.setForeground( QColor(settings->value("colors/comment").toString()) ); srule.startPattern = QRegExp("^(\\s*)\\.\\.\\s[^_](?![\\w-_\\.]+::(\\s|$))"); - srule.endPattern = QRegExp("^(?=([^\\.\\s]|$))"); + srule.endPattern = QRegExp("^(?=([^\\s]|$))"); splitrules << srule; } } diff --git a/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.h b/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.h index 5f99dc50..ad8a592b 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.h +++ b/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.h @@ -51,15 +51,6 @@ public: protected: void highlightBlock(const QString &text){ //qDebug() << "Highlight Block:" << text; - for(int i=0; i=0){ - int len = patt.matchedLength(); - setFormat(index, len, rules[i].format); - index = patt.indexIn(text, index+len); //go to the next match - } - }//end loop over normal (single-line) patterns //Now look for any multi-line patterns (starting/continuing/ending) int start = 0; int splitactive = previousBlockState(); @@ -70,11 +61,14 @@ protected: //Find the end of the current rule int end = splitrules[splitactive].endPattern.indexIn(text, start); if(end==-1){ + //qDebug() << "Highlight to end of line:" << text << start; //rule did not finish - apply to all - setFormat(start, text.length()-start, splitrules[splitactive].format); + if(start>0){ setFormat(start-1, text.length()-start+1, splitrules[splitactive].format); } + else{ setFormat(start, text.length()-start, splitrules[splitactive].format); } break; //stop looking for more multi-line patterns }else{ //Found end point + //qDebug() << "Highlight to particular point:" << text << start << end; int len = end-start+splitrules[splitactive].endPattern.matchedLength(); setFormat(start, len , splitrules[splitactive].format); start+=len; //move pointer to the end of handled range @@ -86,13 +80,30 @@ protected: //qDebug() << "Look for start of split rule:" << splitrules[i].startPattern << splitactive; int newstart = splitrules[i].startPattern.indexIn(text,start); if(newstart>=start){ + //qDebug() << "Got Start of split rule:" << start << newstart << text; splitactive = i; - start = newstart; + start = newstart+1; + if(start>=text.length()-1){ + //qDebug() << "Special case: start now greater than line length"; + //Need to apply highlighting to this section too - start matches the end of the line + setFormat(start-1, text.length()-start+1, splitrules[splitactive].format); + } } } if(splitactive<0){ break; } //no other rules found - go ahead and exit the loop } setCurrentBlockState(splitactive); + //Do all the single-line patterns + for(int i=0; i=0 && index>=start){ continue; } //skip this one - falls within a multi-line pattern above + while(index>=0){ + int len = patt.matchedLength(); + setFormat(index, len, rules[i].format); + index = patt.indexIn(text, index+len); //go to the next match + } + }//end loop over normal (single-line) patterns } }; #endif diff --git a/src-qt5/desktop-utils/lumina-textedit/tests/test.rst b/src-qt5/desktop-utils/lumina-textedit/tests/test.rst index a0a39d12..156f0eca 100644 --- a/src-qt5/desktop-utils/lumina-textedit/tests/test.rst +++ b/src-qt5/desktop-utils/lumina-textedit/tests/test.rst @@ -6,7 +6,7 @@ breaks when justify left TODO -.. code-block::JSON +.. code-block:: JSON Everything in a code block is blue text .. testlink: will be blue text @@ -22,6 +22,14 @@ directives :command:`test` from "`" to "`" is yellow text. .. figure:: images/lumina1e.png :scale: 50% +:: + + + +.. code-block:: python + + + .. _gettingstarted: Getting Started -- cgit