From 25de0341100d480b614cb623f205533886abab94 Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Wed, 21 Sep 2016 07:58:05 +0530
Subject: [PATCH] Edit Book: Allow highlighting class names in the HTML
differently via Preferences->Editor settings->Color scheme
---
.../gui2/tweak_book/editor/syntax/html.py | 6 +++-
src/calibre/gui2/tweak_book/editor/themes.py | 31 ++++++++++---------
2 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/src/calibre/gui2/tweak_book/editor/syntax/html.py b/src/calibre/gui2/tweak_book/editor/syntax/html.py
index d3e9d5e613..c43a72179c 100644
--- a/src/calibre/gui2/tweak_book/editor/syntax/html.py
+++ b/src/calibre/gui2/tweak_book/editor/syntax/html.py
@@ -434,7 +434,7 @@ def quoted_val(state, text, i, formats, user_data):
pos = text.find(quote, i)
if pos == -1:
num = len(text) - i
- is_link = False
+ is_link = is_class = False
else:
num = pos - i + 1
state.parse = IN_OPENING_TAG
@@ -445,11 +445,14 @@ def quoted_val(state, text, i, formats, user_data):
pass
add_attr_data(user_data, ATTR_VALUE, ATTR_END, i + num)
is_link = state.attribute_name in LINK_ATTRS
+ is_class = not is_link and state.attribute_name == 'class'
if is_link:
if verify_link(text[i:i+num - 1], user_data.doc_name) is False:
return [(num - 1, formats['bad_link']), (1, formats['string'])]
return [(num - 1, formats['link']), (1, formats['string'])]
+ elif is_class:
+ return [(num - 1, formats['class_attr']), (1, formats['string'])]
return [(num, formats['string'])]
def closing_tag(state, text, i, formats, user_data):
@@ -532,6 +535,7 @@ def create_formats(highlighter, add_css=True):
if add_css:
formats['css_sub_formats'] = create_css_formats(highlighter)
formats['spell'].setProperty(SPELL_PROPERTY, True)
+ formats['class_attr'] = syntax_text_char_format(t.get('ClassAttribute', t['String']))
formats['link'] = syntax_text_char_format(t['Link'])
formats['link'].setProperty(LINK_PROPERTY, True)
formats['link'].setToolTip(_('Hold down the Ctrl key and click to open this link'))
diff --git a/src/calibre/gui2/tweak_book/editor/themes.py b/src/calibre/gui2/tweak_book/editor/themes.py
index 90d71a56bf..1df2299cbd 100644
--- a/src/calibre/gui2/tweak_book/editor/themes.py
+++ b/src/calibre/gui2/tweak_book/editor/themes.py
@@ -71,6 +71,7 @@ SOLARIZED = \
Tooltip fg=black bg=ffffed
Link fg={blue}
BadLink fg={cyan} us=wave uc={red}
+ ClassAttribute fg={cyan}
DiffDelete bg={base02} fg={red}
DiffInsert bg={base02} fg={green}
@@ -114,6 +115,7 @@ THEMES = {
SpecialCharacter bg={cursor_loc}
Link fg=cyan
BadLink fg={string} us=wave uc=red
+ ClassAttribute fg={string}
DiffDelete bg=341414 fg=642424
DiffInsert bg=143414 fg=246424
@@ -162,6 +164,7 @@ THEMES = {
SpellError us=wave uc=magenta
Link fg=blue
BadLink fg={string} us=wave uc=red
+ ClassAttribute fg={string}
DiffDelete bg=rgb(255,180,200) fg=rgb(200,80,110)
DiffInsert bg=rgb(180,255,180) fg=rgb(80,210,80)
@@ -456,23 +459,19 @@ class Property(QWidget):
HELP_TEXT = _('''\
Creating a custom theme
-You can create a custom syntax highlighting
-theme, with your own colors and font styles. The most important
-types of highlighting rules are described below. Note that not
-every rule supports every kind of customization, for example,
-changing font or underline styles for the Cursor
rule
-does not have any effect as that rule is used only for the color of
-the blinking cursor.
+You can create a custom syntax highlighting theme, \
+with your own colors and font styles. The most important types of highlighting \
+rules are described below. Note that not every rule supports every kind of \
+customization, for example, changing font or underline styles for the \
+Cursor
rule does not have any effect as that rule is used only for \
+the color of the blinking cursor.
-As you make changes to your theme on the left, the changes will
-be reflected live in this panel.
+As you make changes to your theme on the left, the changes will be reflected live in this panel.
{0}
- The most important rule. Sets the
- foreground and background colors for the editor as well as the
- style of "normal" text, that is, text that does not match any
- special syntax.
+ The most important rule. Sets the foreground and background colors for the \
+ editor as well as the style of "normal" text, that is, text that does not match any special syntax.
{1}
Defines the colors for text selected by the mouse.
@@ -510,6 +509,9 @@ be reflected live in this panel.
{12}
Comments like
+
+{13}
+ Class attributes, like this