mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Store language data when syntax highlighting
This commit is contained in:
parent
637109e7e5
commit
91f14b07ab
@ -13,6 +13,7 @@ from collections import namedtuple
|
|||||||
from PyQt4.Qt import QFont, QTextBlockUserData
|
from PyQt4.Qt import QFont, QTextBlockUserData
|
||||||
|
|
||||||
from calibre.ebooks.oeb.polish.spell import html_spell_tags, xml_spell_tags
|
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 import SyntaxTextCharFormat
|
||||||
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 (
|
||||||
@ -318,6 +319,7 @@ def attribute_name(state, text, i, formats, user_data):
|
|||||||
return [(1, formats['attr'])]
|
return [(1, formats['attr'])]
|
||||||
# Standalone attribute with no value
|
# Standalone attribute with no value
|
||||||
state.parse = IN_OPENING_TAG
|
state.parse = IN_OPENING_TAG
|
||||||
|
state.attribute_name = None
|
||||||
return [(0, None)]
|
return [(0, None)]
|
||||||
|
|
||||||
def attribute_value(state, text, i, formats, user_data):
|
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
|
state.parse = SQ_VAL if ch == "'" else DQ_VAL
|
||||||
return [(1, formats['string'])]
|
return [(1, formats['string'])]
|
||||||
state.parse = IN_OPENING_TAG
|
state.parse = IN_OPENING_TAG
|
||||||
|
state.attribute_name = None
|
||||||
m = unquoted_val_pat.match(text, i)
|
m = unquoted_val_pat.match(text, i)
|
||||||
if m is None:
|
if m is None:
|
||||||
return [(1, formats['no-attr-value'])]
|
return [(1, formats['no-attr-value'])]
|
||||||
@ -344,6 +347,11 @@ def quoted_val(state, text, i, formats, user_data):
|
|||||||
else:
|
else:
|
||||||
num = pos - i + 1
|
num = pos - i + 1
|
||||||
state.parse = IN_OPENING_TAG
|
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)
|
add_attr_data(user_data, ATTR_VALUE, ATTR_END, i + num)
|
||||||
return [(num, formats['string'])]
|
return [(num, formats['string'])]
|
||||||
|
|
||||||
@ -468,9 +476,9 @@ if __name__ == '__main__':
|
|||||||
</style>
|
</style>
|
||||||
<style type="text/css">p.small { font-size: x-small; color:gray }</style>
|
<style type="text/css">p.small { font-size: x-small; color:gray }</style>
|
||||||
</head id="invalid attribute on closing tag">
|
</head id="invalid attribute on closing tag">
|
||||||
<body><p:
|
<body lang="en_IN"><p:
|
||||||
<!-- The start of the actual body text -->
|
<!-- The start of the actual body text -->
|
||||||
<h1>A heading that should appear in bold, with an <i>italic</i> word</h1>
|
<h1 lang="en_US">A heading that should appear in bold, with an <i>italic</i> word</h1>
|
||||||
<p>Some text with inline formatting, that is syntax highlighted. A <b>bold</b> word, and an <em>italic</em> word. \
|
<p>Some text with inline formatting, that is syntax highlighted. A <b>bold</b> word, and an <em>italic</em> word. \
|
||||||
<i>Some italic text with a <b>bold-italic</b> word in </i>the middle.</p>
|
<i>Some italic text with a <b>bold-italic</b> word in </i>the middle.</p>
|
||||||
<!-- Let's see what exotic constructs like namespace prefixes and empty attributes look like -->
|
<!-- Let's see what exotic constructs like namespace prefixes and empty attributes look like -->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user