mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
c40483eb86
commit
67a168edae
@ -31,13 +31,19 @@ from calibre.utils.titlecase import titlecase
|
|||||||
PARAGRAPH_SEPARATOR = '\u2029'
|
PARAGRAPH_SEPARATOR = '\u2029'
|
||||||
|
|
||||||
def get_highlighter(syntax):
|
def get_highlighter(syntax):
|
||||||
# Load these highlighters only on demand
|
|
||||||
try:
|
try:
|
||||||
ans = importlib.import_module('calibre.gui2.tweak_book.editor.syntax.' + syntax).Highlighter
|
ans = importlib.import_module('calibre.gui2.tweak_book.editor.syntax.' + syntax).Highlighter
|
||||||
except (ImportError, AttributeError):
|
except (ImportError, AttributeError):
|
||||||
ans = SyntaxHighlighter
|
ans = SyntaxHighlighter
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
def get_smarts(syntax):
|
||||||
|
smartsname = {'xml':'html'}.get(syntax, syntax)
|
||||||
|
try:
|
||||||
|
return importlib.import_module('calibre.gui2.tweak_book.editor.smart.' + smartsname).Smarts
|
||||||
|
except (ImportError, AttributeError):
|
||||||
|
pass
|
||||||
|
|
||||||
_dff = None
|
_dff = None
|
||||||
def default_font_family():
|
def default_font_family():
|
||||||
global _dff
|
global _dff
|
||||||
@ -210,12 +216,8 @@ class TextEdit(PlainTextEdit):
|
|||||||
self.highlighter = get_highlighter(syntax)()
|
self.highlighter = get_highlighter(syntax)()
|
||||||
self.highlighter.apply_theme(self.theme)
|
self.highlighter.apply_theme(self.theme)
|
||||||
self.highlighter.set_document(self.document(), doc_name=doc_name)
|
self.highlighter.set_document(self.document(), doc_name=doc_name)
|
||||||
smartsname = {'xml':'html'}.get(syntax, syntax)
|
sclass = get_smarts(syntax)
|
||||||
try:
|
if sclass is not None:
|
||||||
sclass = importlib.import_module('calibre.gui2.tweak_book.editor.smart.' + smartsname).Smarts
|
|
||||||
except (ImportError, AttributeError):
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
self.smarts = sclass(self)
|
self.smarts = sclass(self)
|
||||||
self.setPlainText(unicodedata.normalize('NFC', unicode(text)))
|
self.setPlainText(unicodedata.normalize('NFC', unicode(text)))
|
||||||
if process_template and QPlainTextEdit.find(self, '%CURSOR%'):
|
if process_template and QPlainTextEdit.find(self, '%CURSOR%'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user