From d23345f69625020b9e31bf84a1d68ba30cbcf99c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 10 May 2014 15:58:25 +0530 Subject: [PATCH] Edit book: Insert tag button: Allow entering attributes along with the tag name to make it easy to repeatedly insert, for example, . --- src/calibre/gui2/tweak_book/editor/smart/html.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/tweak_book/editor/smart/html.py b/src/calibre/gui2/tweak_book/editor/smart/html.py index 40d2fe1cb5..243beb7bd8 100644 --- a/src/calibre/gui2/tweak_book/editor/smart/html.py +++ b/src/calibre/gui2/tweak_book/editor/smart/html.py @@ -272,11 +272,14 @@ def insert_hyperlink(self, editor, target, text): editor.setTextCursor(c) def insert_tag(self, editor, name): + name = name.lstrip() text = self.get_smart_selection(editor, update=True) c = editor.textCursor() pos = min(c.position(), c.anchor()) - c.insertText('<{0}>{1}'.format(name, text)) - c.setPosition(pos + 1 + len(name)) + m = re.match(r'[a-zA-Z0-9:-]+', name) + cname = name if m is None else m.group() + c.insertText('<{0}>{1}'.format(name, text, cname)) + c.setPosition(pos + 2 + len(name)) editor.setTextCursor(c) def verify_for_spellcheck(self, cursor, highlighter):