diff --git a/src/calibre/gui2/tweak_book/editor/syntax/css.py b/src/calibre/gui2/tweak_book/editor/syntax/css.py new file mode 100644 index 0000000000..4b6a432384 --- /dev/null +++ b/src/calibre/gui2/tweak_book/editor/syntax/css.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +# vim:fileencoding=utf-8 +from __future__ import (unicode_literals, division, absolute_import, + print_function) + +__license__ = 'GPL v3' +__copyright__ = '2013, Kovid Goyal ' + +from calibre.gui2.tweak_book.editor.syntax.base import SyntaxHighlighter + +class State(object): + + NORMAL = 0 + + def __init__(self, num): + self.parse = num & 0b1111 + self.blocks = num >> 4 + + @property + def value(self): + return ((self.parse & 0b1111) | (max(0, self.blocks) << 4)) + + +def normal(state, text, i, formats): + ' The normal state (outside everything) ' + return [(len(text), None)] + +state_map = { + State.NORMAL:normal, +} + +class CSSHighlighter(SyntaxHighlighter): + + state_map = state_map + state_class = State + + def __init__(self, parent): + SyntaxHighlighter.__init__(self, parent) + + def create_formats(self): + # t = self.theme + self.formats = { + } + +if __name__ == '__main__': + from calibre.gui2.tweak_book.editor.text import launch_editor + launch_editor('''\ +@charset "utf-8"; +/* A demonstration css sheet */ +''', path_is_raw=True, syntax='css') + diff --git a/src/calibre/gui2/tweak_book/editor/syntax/html.py b/src/calibre/gui2/tweak_book/editor/syntax/html.py index 2883e84eee..dccb4f7043 100644 --- a/src/calibre/gui2/tweak_book/editor/syntax/html.py +++ b/src/calibre/gui2/tweak_book/editor/syntax/html.py @@ -314,4 +314,4 @@ if __name__ == '__main__':

Some\xa0words\xa0separated\xa0by\xa0non-breaking\xa0spaces.

-''') +''', path_is_raw=True) diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index c6d521e89a..78a40606c8 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -17,6 +17,7 @@ from calibre.gui2.tweak_book import tprefs from calibre.gui2.tweak_book.editor.themes import THEMES, DEFAULT_THEME, theme_color from calibre.gui2.tweak_book.editor.syntax.base import SyntaxHighlighter from calibre.gui2.tweak_book.editor.syntax.html import HTMLHighlighter +from calibre.gui2.tweak_book.editor.syntax.css import CSSHighlighter _dff = None def default_font_family(): @@ -93,7 +94,7 @@ class TextEdit(QPlainTextEdit): # }}} def load_text(self, text, syntax='html'): - self.highlighter = {'html':HTMLHighlighter}.get(syntax, SyntaxHighlighter)(self) + self.highlighter = {'html':HTMLHighlighter, 'css':CSSHighlighter}.get(syntax, SyntaxHighlighter)(self) self.highlighter.apply_theme(self.theme) self.highlighter.setDocument(self.document()) self.setPlainText(text) @@ -199,49 +200,23 @@ class TextEdit(QPlainTextEdit): ev.ignore() # }}} -def launch_editor(path_to_edit): - if ' - - Page title - - - - a -

A heading

-

A single &. An proper entity &. - A single < and a single >. - These cases are perfectly simple and easy to - distinguish. In a free hour, when our power of choice is - untrammelled and when nothing prevents our being able to do - what we like best, every pleasure is to be welcomed and every - pain avoided.

- -

- But in certain circumstances and owing to the claims of duty or the obligations - of business it will frequently occur that pleasures have to be - repudiated and annoyances accepted. The wise man therefore - always holds in these matters to this principle of selection: - he rejects pleasures to secure other greater pleasures, or else - he endures pains.

- - - '''))