--- a/QScintilla/MarkupProviders/HtmlProvider.py Sun Jan 08 18:51:55 2017 +0100 +++ b/QScintilla/MarkupProviders/HtmlProvider.py Sun Jan 08 18:52:16 2017 +0100 @@ -158,7 +158,7 @@ editor.setCursorPosition(cline + 1, 0) editor.endUndoAction() - def __insertMarkup(self, markup, editor): + def __insertMarkup(self, markup, editor, addEol=False): """ Private method to insert the specified markup. @@ -170,18 +170,28 @@ @type str @param editor reference to the editor to work on @type Editor + @param addEol flag indicating to add an eol string after the tag + @type bool """ if editor is None: return + if addEol: + lineSeparator = editor.getLineSeparator() + else: + lineSeparator = "" editor.beginUndoAction() if editor.hasSelectedText(): - newText = "<{0}>{1}</{0}>".format(markup, editor.selectedText()) + newText = "<{0}>{2}{1}</{0}>{2}".format( + markup, editor.selectedText(), lineSeparator) editor.replaceSelectedText(newText) else: - editor.insert("<{0}></{0}>".format(markup)) + editor.insert("<{0}>{1}{1}</{0}>{1}".format(markup, lineSeparator)) cline, cindex = editor.getCursorPosition() - editor.setCursorPosition(cline, cindex + len(markup) + 2) + if addEol: + editor.setCursorPosition(cline + 1, 0) + else: + editor.setCursorPosition(cline, cindex + len(markup) + 2) editor.endUndoAction() def hasHyperlink(self): @@ -200,6 +210,9 @@ @param editor reference to the editor to work on @type Editor """ + if editor is None: + return + from .HyperlinkMarkupDialog import HyperlinkMarkupDialog dlg = HyperlinkMarkupDialog(True, False) if dlg.exec_() == QDialog.Accepted: @@ -244,3 +257,62 @@ cline, cindex = editor.getCursorPosition() editor.setCursorPosition(cline, cindex + len(markup)) editor.endUndoAction() + + def hasQuote(self): + """ + Public method to indicate the availability of block quote markup. + + @return flag indicating the availability of block quote markup + @rtype bool + """ + return True + + def quote(self, editor): + """ + Public method to generate block quote text. + + @param editor reference to the editor to work on + @type Editor + """ + self.__insertMarkup("blockquote", editor, True) + + def hasImage(self): + """ + Public method to indicate the availability of image markup. + + @return flag indicating the availability of image markup + @rtype bool + """ + return True + + def image(self, editor): + """ + Public method to generate image text. + + @param editor reference to the editor to work on + @type Editor + """ + if editor is None: + return + + from .ImageMarkupDialog import ImageMarkupDialog + dlg = ImageMarkupDialog(ImageMarkupDialog.HtmlMode) + if dlg.exec_() == QDialog.Accepted: + address, altText, title, originalSize, width, height = \ + dlg.getData() + + markup = '<img src="{0}"'.format(address) + if altText: + markup = '{0} alt="{1}"'.format(markup, altText) + if title: + markup = '{0} title="{1}"'.format(markup, title) + if not originalSize: + markup = '{0} width="{1}" height="{2}"'.format( + markup, width, height) + markup = '{0} />'.format(markup) + + editor.beginUndoAction() + editor.insert(markup) + cline, cindex = editor.getCursorPosition() + editor.setCursorPosition(cline, cindex + len(markup)) + editor.endUndoAction()