diff --git a/src/calibre/gui2/tweak_book/editor/syntax/html.py b/src/calibre/gui2/tweak_book/editor/syntax/html.py index a9e7c2df7a..e506d4229b 100644 --- a/src/calibre/gui2/tweak_book/editor/syntax/html.py +++ b/src/calibre/gui2/tweak_book/editor/syntax/html.py @@ -13,6 +13,7 @@ from collections import namedtuple from PyQt4.Qt import QFont, QTextBlockUserData from calibre.ebooks.oeb.polish.spell import html_spell_tags, xml_spell_tags +from calibre.spell.dictionary import parse_lang_code from calibre.gui2.tweak_book.editor import SyntaxTextCharFormat from calibre.gui2.tweak_book.editor.syntax.base import SyntaxHighlighter, run_loop from calibre.gui2.tweak_book.editor.syntax.css import ( @@ -318,6 +319,7 @@ def attribute_name(state, text, i, formats, user_data): return [(1, formats['attr'])] # Standalone attribute with no value state.parse = IN_OPENING_TAG + state.attribute_name = None return [(0, None)] def attribute_value(state, text, i, formats, user_data): @@ -329,6 +331,7 @@ def attribute_value(state, text, i, formats, user_data): state.parse = SQ_VAL if ch == "'" else DQ_VAL return [(1, formats['string'])] state.parse = IN_OPENING_TAG + state.attribute_name = None m = unquoted_val_pat.match(text, i) if m is None: return [(1, formats['no-attr-value'])] @@ -344,6 +347,11 @@ def quoted_val(state, text, i, formats, user_data): else: num = pos - i + 1 state.parse = IN_OPENING_TAG + if state.tag_being_defined is not None and state.attribute_name in ('lang', 'xml:lang'): + try: + state.tag_being_defined.lang = parse_lang_code(text[i:pos]) + except ValueError: + pass add_attr_data(user_data, ATTR_VALUE, ATTR_END, i + num) return [(num, formats['string'])] @@ -468,9 +476,9 @@ if __name__ == '__main__': - -

A heading that should appear in bold, with an italic word

+

A heading that should appear in bold, with an italic word

Some text with inline formatting, that is syntax highlighted. A bold word, and an italic word. \ Some italic text with a bold-italic word in the middle.