def create_formats(highlighter, add_css=True): t = highlighter.theme formats = { 'tag': t['Function'], 'end_tag': t['Function'], 'attr': t['Type'], 'tag_name' : t['Statement'], 'entity': t['Special'], 'error': t['Error'], 'comment': t['Comment'], 'special': t['Special'], 'string': t['String'], 'nsprefix': t['Constant'], 'preproc': t['PreProc'], 'nbsp': t['SpecialCharacter'], 'spell': t['SpellError'], } for name, msg in { '<': _('An unescaped < is not allowed. Replace it with <'), '&': _('An unescaped ampersand is not allowed. Replace it with &'), '>': _('An unescaped > is not allowed. Replace it with >'), '/': _('/ not allowed except at the end of the tag'), '?': _('Unknown character'), 'bad-closing': _('A closing tag must contain only the tag name and nothing else'), 'no-attr-value': _('Expecting an attribute value'), 'only-prefix': _('A tag name cannot end with a colon'), }.iteritems(): f = formats[name] = syntax_text_char_format(formats['error']) f.setToolTip(msg) f = formats['title'] = syntax_text_char_format() f.setFontWeight(QFont.Bold) if add_css: formats['css_sub_formats'] = create_css_formats(highlighter) formats['spell'].setProperty(SPELL_PROPERTY, True) return formats
def create_formats(highlighter): theme = highlighter.theme formats = { 'comment': theme['Comment'], 'error': theme['Error'], 'string': theme['String'], 'colorname': theme['Constant'], 'number': theme['Number'], 'operator': theme['Function'], 'bracket': theme['Special'], 'identifier': theme['Identifier'], 'id_selector': theme['Special'], 'class_selector': theme['Special'], 'pseudo_selector': theme['Special'], 'tag': theme['Identifier'], } for name, msg in { 'unknown-normal': _('Invalid text'), 'unterminated-string': _('Unterminated string'), }.iteritems(): f = formats[name] = syntax_text_char_format(formats['error']) f.setToolTip(msg) formats['link'] = syntax_text_char_format(theme['Link']) formats['link'].setToolTip(_('Hold down the Ctrl key and click to open this link')) formats['link'].setProperty(LINK_PROPERTY, True) formats['bad_link'] = syntax_text_char_format(theme['BadLink']) formats['bad_link'].setProperty(LINK_PROPERTY, True) formats['bad_link'].setToolTip(_('This link points to a file that is not present in the book')) formats['preproc'] = f = syntax_text_char_format(theme['PreProc']) f.setProperty(CSS_PROPERTY, True) formats['keyword'] = f = syntax_text_char_format(theme['Keyword']) f.setProperty(CSS_PROPERTY, True) return formats
def create_formats(highlighter, add_css=True): t = highlighter.theme formats = { 'tag': t['Function'], 'end_tag': t['Function'], 'attr': t['Type'], 'entity': t['Special'], 'error': t['Error'], 'comment': t['Comment'], 'special': t['Special'], 'string': t['String'], 'nsprefix': t['Constant'], 'preproc': t['PreProc'], 'nbsp': t['SpecialCharacter'], 'spell': t['SpellError'], } for name, msg in { '<': _('An unescaped < is not allowed. Replace it with <'), '&': _('An unescaped ampersand is not allowed. Replace it with &'), '>': _('An unescaped > is not allowed. Replace it with >'), '/': _('/ not allowed except at the end of the tag'), '?': _('Unknown character'), 'bad-closing': _('A closing tag must contain only the tag name and nothing else'), 'no-attr-value': _('Expecting an attribute value'), 'only-prefix': _('A tag name cannot end with a colon'), }.iteritems(): f = formats[name] = syntax_text_char_format(formats['error']) f.setToolTip(msg) f = formats['title'] = syntax_text_char_format() f.setFontWeight(QFont.Bold) if add_css: formats['css_sub_formats'] = create_css_formats(highlighter) formats['spell'].setProperty(SPELL_PROPERTY, True) 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')) formats['bad_link'] = syntax_text_char_format(t['BadLink']) formats['bad_link'].setProperty(LINK_PROPERTY, True) formats['bad_link'].setToolTip( _('This link points to a file that is not present in the book')) formats['tag_name'] = f = syntax_text_char_format(t['Statement']) f.setProperty(TAG_NAME_PROPERTY, True) return formats
def create_formats(highlighter): theme = highlighter.theme formats = { 'comment': theme['Comment'], 'error': theme['Error'], 'string': theme['String'], 'preproc': theme['PreProc'], 'keyword': theme['Keyword'], 'colorname': theme['Constant'], 'number': theme['Number'], 'operator': theme['Function'], 'bracket': theme['Special'], 'identifier': theme['Identifier'], 'id_selector': theme['Special'], 'class_selector': theme['Special'], 'pseudo_selector': theme['Special'], 'tag': theme['Identifier'], } for name, msg in { 'unknown-normal': _('Invalid text'), 'unterminated-string': _('Unterminated string'), }.iteritems(): f = formats[name] = syntax_text_char_format(formats['error']) f.setToolTip(msg) return formats
def create_formats(highlighter, add_css=True): t = highlighter.theme formats = { "tag": t["Function"], "end_tag": t["Function"], "attr": t["Type"], "entity": t["Special"], "error": t["Error"], "comment": t["Comment"], "special": t["Special"], "string": t["String"], "nsprefix": t["Constant"], "preproc": t["PreProc"], "nbsp": t["SpecialCharacter"], "spell": t["SpellError"], } for name, msg in { "<": _("An unescaped < is not allowed. Replace it with <"), "&": _("An unescaped ampersand is not allowed. Replace it with &"), ">": _("An unescaped > is not allowed. Replace it with >"), "/": _("/ not allowed except at the end of the tag"), "?": _("Unknown character"), "bad-closing": _("A closing tag must contain only the tag name and nothing else"), "no-attr-value": _("Expecting an attribute value"), "only-prefix": _("A tag name cannot end with a colon"), }.iteritems(): f = formats[name] = syntax_text_char_format(formats["error"]) f.setToolTip(msg) f = formats["title"] = syntax_text_char_format() f.setFontWeight(QFont.Bold) if add_css: formats["css_sub_formats"] = create_css_formats(highlighter) formats["spell"].setProperty(SPELL_PROPERTY, True) 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")) formats["bad_link"] = syntax_text_char_format(t["BadLink"]) formats["bad_link"].setProperty(LINK_PROPERTY, True) formats["bad_link"].setToolTip(_("This link points to a file that is not present in the book")) formats["tag_name"] = f = syntax_text_char_format(t["Statement"]) f.setProperty(TAG_NAME_PROPERTY, True) return formats
def highlight_to_char_format(h): ans = syntax_text_char_format() if h.bold: ans.setFontWeight(QFont.Weight.Bold) if h.italic: ans.setFontItalic(True) if h.fg is not None: ans.setForeground(h.fg) if h.bg is not None: ans.setBackground(h.bg) if h.underline: ans.setUnderlineStyle(underline_styles[h.underline]) if h.underline_color is not None: ans.setUnderlineColor(h.underline_color.color()) return ans
def highlight_to_char_format(h): ans = syntax_text_char_format() if h.bold: ans.setFontWeight(QFont.Bold) if h.italic: ans.setFontItalic(True) if h.fg is not None: ans.setForeground(h.fg) if h.bg is not None: ans.setBackground(h.bg) if h.underline: ans.setUnderlineStyle(underline_styles[h.underline]) if h.underline_color is not None: ans.setUnderlineColor(h.underline_color.color()) return ans
def process_text(state, text, nbsp_format, spell_format, user_data): ans = [] fmt = None if state.is_bold or state.is_italic: fmt = syntax_text_char_format() if state.is_bold: fmt.setFontWeight(QFont.Weight.Bold) if state.is_italic: fmt.setFontItalic(True) last = 0 for m in nbsp_pat.finditer(text): ans.extend([(m.start() - last, fmt), (m.end() - m.start(), nbsp_format)]) last = m.end() if not ans: ans = [(len(text), fmt)] elif last < len(text): ans.append((len(text) - last, fmt)) if do_spell_check and state.tags and user_data.tag_ok_for_spell( state.tags[-1].name): split_ans = [] locale = state.current_lang or dictionaries.default_locale sfmt = QTextCharFormat(spell_format) if fmt is not None: sfmt.merge(fmt) tpos = 0 for tlen, fmt in ans: if fmt is nbsp_format: split_ans.append((tlen, fmt)) else: split_ans.extend( check_spelling(text[tpos:tpos + tlen], tlen, fmt, locale, sfmt, store_locale.enabled)) tpos += tlen ans = split_ans return ans
def process_text(state, text, nbsp_format, spell_format, user_data): ans = [] fmt = None if state.is_bold or state.is_italic: fmt = syntax_text_char_format() if state.is_bold: fmt.setFontWeight(QFont.Bold) if state.is_italic: fmt.setFontItalic(True) last = 0 for m in nbsp_pat.finditer(text): ans.extend([(m.start() - last, fmt), (m.end() - m.start(), nbsp_format)]) last = m.end() if not ans: ans = [(len(text), fmt)] elif last < len(text): ans.append((len(text) - last, fmt)) if do_spell_check and state.tags and user_data.tag_ok_for_spell(state.tags[-1].name): split_ans = [] locale = state.current_lang or dictionaries.default_locale sfmt = QTextCharFormat(spell_format) if fmt is not None: sfmt.merge(fmt) tpos = 0 for tlen, fmt in ans: if fmt is nbsp_format: split_ans.append((tlen, fmt)) else: split_ans.extend( check_spelling(text[tpos : tpos + tlen], tlen, fmt, locale, sfmt, store_locale.enabled) ) tpos += tlen ans = split_ans return ans
def create_formats(highlighter, add_css=True): t = highlighter.theme formats = { 'tag': t['Function'], 'end_tag': t['Function'], 'attr': t['Type'], 'entity': t['Special'], 'error': t['Error'], 'comment': t['Comment'], 'special': t['Special'], 'string': t['String'], 'nsprefix': t['Constant'], 'preproc': t['PreProc'], 'nbsp': t['SpecialCharacter'], 'spell': t['SpellError'], } for name, msg in iteritems({ '<': _('An unescaped < is not allowed. Replace it with <'), '&': _('An unescaped ampersand is not allowed. Replace it with &'), '>': _('An unescaped > is not allowed. Replace it with >'), '/': _('/ not allowed except at the end of the tag'), '?': _('Unknown character'), 'bad-closing': _('A closing tag must contain only the tag name and nothing else'), 'no-attr-value': _('Expecting an attribute value'), 'only-prefix': _('A tag name cannot end with a colon'), }): f = formats[name] = syntax_text_char_format(formats['error']) f.setToolTip(msg) f = formats['title'] = syntax_text_char_format() f.setFontWeight(QFont.Bold) 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['Special']) formats['class_attr'].setProperty(CLASS_ATTRIBUTE_PROPERTY, True) 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')) formats['bad_link'] = syntax_text_char_format(t['BadLink']) formats['bad_link'].setProperty(LINK_PROPERTY, True) formats['bad_link'].setToolTip(_('This link points to a file that is not present in the book')) formats['tag_name'] = f = syntax_text_char_format(t['Statement']) f.setProperty(TAG_NAME_PROPERTY, True) return formats