--- a/QScintilla/MarkupProviders/MarkdownProvider.py Sat Jan 07 19:00:58 2017 +0100 +++ b/QScintilla/MarkupProviders/MarkdownProvider.py Sat Jan 07 19:35:40 2017 +0100 @@ -9,6 +9,8 @@ from __future__ import unicode_literals +from PyQt5.QtWidgets import QDialog + from .MarkupBase import MarkupBase @@ -130,6 +132,37 @@ """ self.__insertMarkup("`", editor) + def hasCodeBlock(self): + """ + Public method to indicate the availability of code block markup. + + @return flag indicating the availability of code block markup + @rtype bool + """ + return True + + def codeBlock(self, editor): + """ + Public method to generate code block text. + + @param editor reference to the editor to work on + @type Editor + """ + if editor is None: + return + + lineSeparator = editor.getLineSeparator() + editor.beginUndoAction() + if editor.hasSelectedText(): + newText = "```{0}{1}```{0}".format( + lineSeparator, editor.selectedText()) + editor.replaceSelectedText(newText) + else: + editor.insert("```{0}{0}```{0}".format(lineSeparator)) + cline, cindex = editor.getCursorPosition() + editor.setCursorPosition(cline + 1, 0) + editor.endUndoAction() + def __insertMarkup(self, markup, editor): """ Private method to insert the specified markup. @@ -155,3 +188,65 @@ cline, cindex = editor.getCursorPosition() editor.setCursorPosition(cline, cindex + len(markup)) editor.endUndoAction() + + def hasHyperlink(self): + """ + Public method to indicate the availability of hyperlink markup. + + @return flag indicating the availability of hyperlink markup + @rtype bool + """ + return True + + def hyperlink(self, editor): + """ + Public method to generate hyperlink text. + + @param editor reference to the editor to work on + @type Editor + """ + from .HyperlinkMarkupDialog import HyperlinkMarkupDialog + dlg = HyperlinkMarkupDialog(False, True) + if dlg.exec_() == QDialog.Accepted: + text, target, title = dlg.getData() + + link = "[{0}]".format(text) + if target and title: + link = '{0}({1} "{2}")'.format(link, target, title) + elif target: + link = '{0}({1})'.format(link, target) + elif title: + link = '{0}("{1}")'.format(link, title) + + editor.beginUndoAction() + cline, cindex = editor.getCursorPosition() + editor.insert(link) + editor.setCursorPosition(cline, cindex + len(link)) + editor.endUndoAction() + + def hasLine(self): + """ + Public method to indicate the availability of a horizontal line markup. + + @return flag indicating the availability of a horizontal line markup + @rtype bool + """ + return True + + def line(self, editor): + """ + Public method to generate a horizontal line text. + + @param editor reference to the editor to work on + @type Editor + """ + if editor is None: + return + + lineSeparator = editor.getLineSeparator() + editor.beginUndoAction() + markup = "{0}-----{0}{0}".format(lineSeparator) + editor.insert(markup) + cline, cindex = editor.getCursorPosition() + editor.setCursorPosition(cline + 3, 0) + editor.endUndoAction()