--- a/QScintilla/MarkupProviders/RestructuredTextProvider.py Sun Jan 08 18:51:55 2017 +0100 +++ b/QScintilla/MarkupProviders/RestructuredTextProvider.py Sun Jan 08 18:52:16 2017 +0100 @@ -94,6 +94,8 @@ editor.beginUndoAction() cline, cindex = editor.getCursorPosition() + if editor.hasSelection() and cindex == 0: + cline -= 1 lineSeparator = editor.getLineSeparator() if not editor.text(cline).endswith(lineSeparator): editor.insertAt(lineSeparator, cline, len(editor.text(cline))) @@ -200,6 +202,9 @@ @param editor reference to the editor to work on @type Editor """ + if editor is None: + return + from .HyperlinkMarkupDialog import HyperlinkMarkupDialog dlg = HyperlinkMarkupDialog(False, True, noTitle=True) if dlg.exec_() == QDialog.Accepted: @@ -268,3 +273,74 @@ cline, cindex = editor.getCursorPosition() editor.setCursorPosition(cline + 3, 0) 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 + """ + if editor is None: + return + + lineSeparator = editor.getLineSeparator() + editor.beginUndoAction() + markup = "> " + sline, sindex, eline, eindex = editor.getSelection() + for line in range(sline, eline + 1 if eindex > 0 else eline): + editor.insertAt(markup, line, 0) + editor.insertAt("::{0}{0}".format(lineSeparator), sline, 0) + editor.setCursorPosition(eline + 2, eindex) + editor.endUndoAction() + + 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.RestMode) + if dlg.exec_() == QDialog.Accepted: + address, altText, title, originalSize, width, height = \ + dlg.getData() + + lineSeparator = editor.getLineSeparator() + markup = ".. image:: {0}{1}".format(address, lineSeparator) + lines = 1 + if altText: + markup += " :alt: {0}{1}".format(altText, lineSeparator) + lines += 1 + if not originalSize: + markup += " :height: {0}px{1}".format(height, lineSeparator) + markup += " :width: {0}px{1}".format(width, lineSeparator) + lines += 2 + + editor.beginUndoAction() + editor.insert(markup) + cline, cindex = editor.getCursorPosition() + editor.setCursorPosition(cline + lines, 0) + editor.endUndoAction()