Edit book: Insert tag button: Allow entering attributes along with the tag name to make it easy to repeatedly insert, for example, <span class="special"></span>.

This commit is contained in:
Kovid Goyal 2014-05-10 15:58:25 +05:30
parent f6e613df6a
commit d23345f696

View File

@ -272,11 +272,14 @@ class HTMLSmarts(NullSmarts):
editor.setTextCursor(c) editor.setTextCursor(c)
def insert_tag(self, editor, name): def insert_tag(self, editor, name):
name = name.lstrip()
text = self.get_smart_selection(editor, update=True) text = self.get_smart_selection(editor, update=True)
c = editor.textCursor() c = editor.textCursor()
pos = min(c.position(), c.anchor()) pos = min(c.position(), c.anchor())
c.insertText('<{0}>{1}</{0}>'.format(name, text)) m = re.match(r'[a-zA-Z0-9:-]+', name)
c.setPosition(pos + 1 + len(name)) cname = name if m is None else m.group()
c.insertText('<{0}>{1}</{2}>'.format(name, text, cname))
c.setPosition(pos + 2 + len(name))
editor.setTextCursor(c) editor.setTextCursor(c)
def verify_for_spellcheck(self, cursor, highlighter): def verify_for_spellcheck(self, cursor, highlighter):