Edit Book: Highlight class attributes inside HTML tags

Rather than using a special highlighting group, use the same style as
that used for classes in the css syntax.
This commit is contained in:
Kovid Goyal 2016-09-21 08:26:16 +05:30
parent 25de034110
commit 069c74563c
3 changed files with 11 additions and 10 deletions

View File

@ -46,6 +46,7 @@ SPELL_LOCALE_PROPERTY = SPELL_PROPERTY + 1
LINK_PROPERTY = SPELL_LOCALE_PROPERTY + 1 LINK_PROPERTY = SPELL_LOCALE_PROPERTY + 1
TAG_NAME_PROPERTY = LINK_PROPERTY + 1 TAG_NAME_PROPERTY = LINK_PROPERTY + 1
CSS_PROPERTY = TAG_NAME_PROPERTY + 1 CSS_PROPERTY = TAG_NAME_PROPERTY + 1
CLASS_ATTRIBUTE_PROPERTY = CSS_PROPERTY + 1
def syntax_text_char_format(*args): def syntax_text_char_format(*args):
ans = QTextCharFormat(*args) ans = QTextCharFormat(*args)

View File

@ -18,7 +18,7 @@ from calibre.spell.break_iterator import split_into_words_and_positions
from calibre.gui2.tweak_book import dictionaries, tprefs, verify_link from calibre.gui2.tweak_book import dictionaries, tprefs, verify_link
from calibre.gui2.tweak_book.editor import ( from calibre.gui2.tweak_book.editor import (
syntax_text_char_format, SPELL_PROPERTY, SPELL_LOCALE_PROPERTY, syntax_text_char_format, SPELL_PROPERTY, SPELL_LOCALE_PROPERTY,
store_locale, LINK_PROPERTY, TAG_NAME_PROPERTY) store_locale, LINK_PROPERTY, TAG_NAME_PROPERTY, CLASS_ATTRIBUTE_PROPERTY)
from calibre.gui2.tweak_book.editor.syntax.base import SyntaxHighlighter, run_loop from calibre.gui2.tweak_book.editor.syntax.base import SyntaxHighlighter, run_loop
from calibre.gui2.tweak_book.editor.syntax.css import ( from calibre.gui2.tweak_book.editor.syntax.css import (
create_formats as create_css_formats, state_map as css_state_map, CSSState, CSSUserData) create_formats as create_css_formats, state_map as css_state_map, CSSState, CSSUserData)
@ -535,7 +535,8 @@ def create_formats(highlighter, add_css=True):
if add_css: if add_css:
formats['css_sub_formats'] = create_css_formats(highlighter) formats['css_sub_formats'] = create_css_formats(highlighter)
formats['spell'].setProperty(SPELL_PROPERTY, True) formats['spell'].setProperty(SPELL_PROPERTY, True)
formats['class_attr'] = syntax_text_char_format(t.get('ClassAttribute', t['String'])) formats['class_attr'] = syntax_text_char_format(t['Special'])
formats['class_attr'].setProperty(CLASS_ATTRIBUTE_PROPERTY, True)
formats['link'] = syntax_text_char_format(t['Link']) formats['link'] = syntax_text_char_format(t['Link'])
formats['link'].setProperty(LINK_PROPERTY, True) formats['link'].setProperty(LINK_PROPERTY, True)
formats['link'].setToolTip(_('Hold down the Ctrl key and click to open this link')) formats['link'].setToolTip(_('Hold down the Ctrl key and click to open this link'))

View File

@ -71,7 +71,6 @@ SOLARIZED = \
Tooltip fg=black bg=ffffed Tooltip fg=black bg=ffffed
Link fg={blue} Link fg={blue}
BadLink fg={cyan} us=wave uc={red} BadLink fg={cyan} us=wave uc={red}
ClassAttribute fg={cyan}
DiffDelete bg={base02} fg={red} DiffDelete bg={base02} fg={red}
DiffInsert bg={base02} fg={green} DiffInsert bg={base02} fg={green}
@ -109,13 +108,12 @@ THEMES = {
Type fg={identifier} Type fg={identifier}
Statement fg={keyword} Statement fg={keyword}
Keyword fg={keyword} Keyword fg={keyword}
Special fg=e7f6da Special fg={special}
Error us=wave uc=red Error us=wave uc=red
SpellError us=wave uc=orange SpellError us=wave uc=orange
SpecialCharacter bg={cursor_loc} SpecialCharacter bg={cursor_loc}
Link fg=cyan Link fg=cyan
BadLink fg={string} us=wave uc=red BadLink fg={string} us=wave uc=red
ClassAttribute fg={string}
DiffDelete bg=341414 fg=642424 DiffDelete bg=341414 fg=642424
DiffInsert bg=143414 fg=246424 DiffInsert bg=143414 fg=246424
@ -128,7 +126,8 @@ THEMES = {
comment='99968b', comment='99968b',
string='95e454', string='95e454',
keyword='8ac6f2', keyword='8ac6f2',
constant='e5786d'), # }}} constant='e5786d',
special='e7f6da'), # }}}
'pyte-light': # {{{ 'pyte-light': # {{{
''' '''
@ -158,13 +157,12 @@ THEMES = {
Type fg={identifier} Type fg={identifier}
Statement fg={keyword} Statement fg={keyword}
Keyword fg={keyword} Keyword fg={keyword}
Special fg=70a0d0 italic Special fg={special} italic
SpecialCharacter bg={cursor_loc} SpecialCharacter bg={cursor_loc}
Error us=wave uc=red Error us=wave uc=red
SpellError us=wave uc=magenta SpellError us=wave uc=magenta
Link fg=blue Link fg=blue
BadLink fg={string} us=wave uc=red BadLink fg={string} us=wave uc=red
ClassAttribute fg={string}
DiffDelete bg=rgb(255,180,200) fg=rgb(200,80,110) DiffDelete bg=rgb(255,180,200) fg=rgb(200,80,110)
DiffInsert bg=rgb(180,255,180) fg=rgb(80,210,80) DiffInsert bg=rgb(180,255,180) fg=rgb(80,210,80)
@ -177,7 +175,8 @@ THEMES = {
comment='a0b0c0', comment='a0b0c0',
string='4070a0', string='4070a0',
keyword='007020', keyword='007020',
constant='a07040'), # }}} constant='a07040',
special='70a0d0'), # }}}
'solarized-x-dark': SOLARIZED.format(**SLDX), 'solarized-x-dark': SOLARIZED.format(**SLDX),
'solarized-dark': SOLARIZED.format(**SLD), 'solarized-dark': SOLARIZED.format(**SLD),
@ -569,7 +568,7 @@ class ThemeEditor(Dialog):
*['<b>%s</b>' % x for x in ( *['<b>%s</b>' % x for x in (
'Normal', 'Visual', 'CursorLine', 'LineNr', 'MatchParen', 'Normal', 'Visual', 'CursorLine', 'LineNr', 'MatchParen',
'Function', 'Type', 'Statement', 'Constant', 'SpecialCharacter', 'Function', 'Type', 'Statement', 'Constant', 'SpecialCharacter',
'Error', 'SpellError', 'Comment', 'ClassAttribute' 'Error', 'SpellError', 'Comment'
)] )]
)) ))
p.setMaximumWidth(p.size_hint.width() + 5) p.setMaximumWidth(p.size_hint.width() + 5)