Fixes #59: support for markdown formatting

This commit is contained in:
Olivier Keshavjee 2017-11-30 13:36:11 +01:00
commit f90a71a76f
12 changed files with 631 additions and 80 deletions

View file

@ -0,0 +1,6 @@
<svg width="128" xmlns="http://www.w3.org/2000/svg" height="128" viewBox="0 0 128 128" xmlns:xlink="http://www.w3.org/1999/xlink">
<g style="fill:#268bd2">
<path d="M 32 24 L 32 40 L 80 40 C 83.421875 40 88 44.914062 88 48 L 104 48 C 104 34.925781 93.441406 24 80 24 Z M 24 80 C 24.046875 85.765625 26.148438 91.621094 30.25 96.25 C 34.347656 100.878906 40.730469 104 48 104 L 104 104 L 104 80 L 88 80 L 88 88 L 48 88 C 44.816406 88 43.464844 87.121094 42.25 85.75 C 41.035156 84.378906 40.019531 82.234375 40 80 Z "/>
<path d="M 8 56 L 8 72 L 120 72 L 120 56 Z "/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 578 B

View file

@ -0,0 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
<g style="fill:#268bd2;line-height:normal;color:#000" transform="translate(-200.0002 -706)">
<path d="m 204,709 0,2 6,0 c 0.42816,0 1,0.61414 1,1 l 2,0 c 0,-1.63434 -1.3198,-3 -3,-3 l -6,0 z m -1,7 c 0.006,0.72062 0.26893,1.45271 0.78125,2.03125 C 204.29357,718.60979 205.09172,719 206,719 l 6,0 1,0 0,-1 0,-2 -2,0 0,1 -5,0 c -0.39787,0 -0.56691,-0.10979 -0.71875,-0.28125 C 205.12941,716.54729 205.00248,716.27938 205,716 l -2,0 z"/>
<path d="m 201,713 0,2 14,0 0,-2 -14,0 z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 552 B

View file

@ -0,0 +1,7 @@
<svg width="22" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 22" height="22">
<g style="fill:#268bd2;line-height:normal;color:#000" transform="translate(-1 -1)">
<path d="m 6,4 0,3 9,0 c 0.611657,0 1,1.382624 1,2 l 3,0 C 19,6.385056 17.257428,3.9999996 14.857143,3.9999996 z"/>
<path d="m 5,16 c 0,2 0.2413287,2.524336 0.9732144,3.45 C 6.7051001,20.375664 7.7024572,21 9,21 c 3.333333,0 6.666667,0 10,0 0,-1.6 0,-3.4 0,-5 l -3,0 0,2 -7,0 C 8.4316143,18 8.3329858,17.624336 8.1160715,17.35 7.8991572,17.075664 8.0035429,16.447008 8,16 z"/>
<path d="m 2,11 0,3 20,0 0,-3 z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 592 B

View file

@ -0,0 +1,7 @@
<svg width="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" height="24">
<g style="fill:#268bd2;line-height:normal;color:#000">
<path d="m 6,4 0,3 9,0 c 0.611657,0 1,1.382624 1,2 l 3,0 C 19,6.385056 17.257428,3.9999996 14.857143,3.9999996 z"/>
<path d="m 5,16 c 0,2 0.2413287,2.524336 0.9732144,3.45 C 6.7051001,20.375664 7.7024572,21 9,21 c 3.333333,0 6.666667,0 10,0 0,-1.6 0,-3.4 0,-5 l -3,0 0,2 -7,0 C 8.4316143,18 8.3329858,17.624336 8.1160715,17.35 7.8991572,17.075664 8.0035429,16.447008 8,16 z"/>
<path d="m 2,11 0,3 20,0 0,-3 z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 563 B

View file

@ -0,0 +1,6 @@
<svg width="256" xmlns="http://www.w3.org/2000/svg" height="256" viewBox="0 0 256 256" xmlns:xlink="http://www.w3.org/1999/xlink">
<g style="fill:#268bd2">
<path d="M 63.996094 48 L 63.996094 80 L 159.996094 80 C 166.847656 80 175.996094 89.828125 175.996094 96 L 207.996094 96 C 207.996094 69.851562 186.878906 48 159.996094 48 Z M 47.996094 160 C 48.09375 171.53125 52.300781 183.242188 60.496094 192.5 C 68.695312 201.757812 81.464844 208 95.996094 208 L 207.996094 208 L 207.996094 160 L 175.996094 160 L 175.996094 176 L 95.996094 176 C 89.632812 176 86.925781 174.242188 84.496094 171.5 C 82.066406 168.757812 80.035156 164.46875 79.996094 160 Z "/>
<path d="M 15.996094 112 L 15.996094 144 L 239.996094 144 L 239.996094 112 Z "/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 749 B

View file

@ -0,0 +1,6 @@
<svg width="32" xmlns="http://www.w3.org/2000/svg" height="32" viewBox="0 0 32 32" xmlns:xlink="http://www.w3.org/1999/xlink">
<g style="fill:#268bd2">
<path d="M 8 6 L 8 10 L 20 10 C 20.855469 10 22 11.226562 22 12 L 26 12 C 26 8.730469 23.359375 6 20 6 Z M 6 20 C 6.011719 21.441406 6.539062 22.90625 7.5625 24.0625 C 8.585938 25.21875 10.183594 26 12 26 L 26 26 L 26 20 L 22 20 L 22 22 L 12 22 C 11.203125 22 10.867188 21.78125 10.5625 21.4375 C 10.257812 21.09375 10.003906 20.558594 10 20 Z "/>
<path d="M 2 14 L 2 18 L 30 18 L 30 14 Z "/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 557 B

View file

@ -0,0 +1,7 @@
<svg width="48" xmlns="http://www.w3.org/2000/svg" height="48" viewBox="0 0 48 48" xmlns:xlink="http://www.w3.org/1999/xlink">
<g style="fill:#268bd2">
<path d="M 12 8 L 12 14 L 30 14 C 31.222656 14 32 16.765625 32 18 L 38 18 C 38 12.769531 34.515625 8 29.714844 8 Z "/>
<path d="M 10 32 C 10 36 10.484375 37.046875 11.945312 38.898438 C 13.410156 40.75 15.40625 42 18 42 C 24.667969 42 31.332031 42 38 42 C 38 38.800781 38 35.199219 38 32 L 32 32 L 32 36 L 18 36 C 16.863281 36 16.664062 35.25 16.230469 34.699219 C 15.796875 34.152344 16.007812 32.894531 16 32 Z "/>
<path d="M 4 22 L 4 28 L 44 28 L 44 22 Z "/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 626 B

View file

@ -0,0 +1,6 @@
<svg width="64" xmlns="http://www.w3.org/2000/svg" height="64" viewBox="0 0 64 64" xmlns:xlink="http://www.w3.org/1999/xlink">
<g style="fill:#268bd2">
<path d="M 16 12 L 16 20 L 40 20 C 41.710938 20 44 22.457031 44 24 L 52 24 C 52 17.460938 46.71875 12 40 12 Z M 12 40 C 12.023438 42.882812 13.074219 45.8125 15.125 48.125 C 17.171875 50.4375 20.367188 52 24 52 L 52 52 L 52 40 L 44 40 L 44 44 L 24 44 C 22.40625 44 21.730469 43.5625 21.125 42.875 C 20.515625 42.1875 20.007812 41.117188 20 40 Z "/>
<path d="M 4 28 L 4 36 L 60 36 L 60 28 Z "/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 558 B

View file

@ -28,6 +28,7 @@ from manuskript.ui.mainWindow import Ui_MainWindow
from manuskript.ui.tools.frequencyAnalyzer import frequencyAnalyzer
from manuskript.ui.views.outlineDelegates import outlineCharacterDelegate
from manuskript.ui.views.plotDelegate import plotDelegate
from manuskript.ui.views.MDEditView import MDEditView
# Spellcheck support
from manuskript.ui.views.textEditView import textEditView
@ -57,6 +58,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# Var
self.currentProject = None
self._lastFocus = None
self._lastMDEditView = None
self._defaultCursorFlashTime = 1000 # Overriden at startup with system
# value. In manuskript.main.
@ -113,19 +115,43 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.actSaveAs.triggered.connect(self.welcome.saveAsFile)
self.actImport.triggered.connect(self.doImport)
self.actCompile.triggered.connect(self.doCompile)
self.actLabels.triggered.connect(self.settingsLabel)
self.actStatus.triggered.connect(self.settingsStatus)
self.actSettings.triggered.connect(self.settingsWindow)
self.actCloseProject.triggered.connect(self.closeProject)
self.actQuit.triggered.connect(self.close)
# Main menu:: Documents
# Main menu:: Edit
self.actCopy.triggered.connect(self.documentsCopy)
self.actCut.triggered.connect(self.documentsCut)
self.actPaste.triggered.connect(self.documentsPaste)
self.actRename.triggered.connect(self.documentsRename)
self.actDuplicate.triggered.connect(self.documentsDuplicate)
self.actDelete.triggered.connect(self.documentsDelete)
self.actLabels.triggered.connect(self.settingsLabel)
self.actStatus.triggered.connect(self.settingsStatus)
self.actSettings.triggered.connect(self.settingsWindow)
# Main menu:: Edit:: Format
self.actHeaderSetextL1.triggered.connect(self.formatSetext1)
self.actHeaderSetextL2.triggered.connect(self.formatSetext2)
self.actHeaderAtxL1.triggered.connect(self.formatAtx1)
self.actHeaderAtxL2.triggered.connect(self.formatAtx2)
self.actHeaderAtxL3.triggered.connect(self.formatAtx3)
self.actHeaderAtxL4.triggered.connect(self.formatAtx4)
self.actHeaderAtxL5.triggered.connect(self.formatAtx5)
self.actHeaderAtxL6.triggered.connect(self.formatAtx6)
self.actFormatBold.triggered.connect(self.formatBold)
self.actFormatItalic.triggered.connect(self.formatItalic)
self.actFormatStrike.triggered.connect(self.formatStrike)
self.actFormatVerbatim.triggered.connect(self.formatVerbatim)
self.actFormatSuperscript.triggered.connect(self.formatSuperscript)
self.actFormatSubscript.triggered.connect(self.formatSubscript)
self.actFormatCommentLines.triggered.connect(self.formatCommentLines)
self.actFormatList.triggered.connect(self.formatList)
self.actFormatOrderedList.triggered.connect(self.formatOrderedList)
self.actFormatBlockquote.triggered.connect(self.formatBlockquote)
self.actFormatCommentBlock.triggered.connect(self.formatCommentBlock)
self.actFormatClear.triggered.connect(self.formatClear)
# Main menu:: Organize
self.actMoveUp.triggered.connect(self.documentsMoveUp)
self.actMoveDown.triggered.connect(self.documentsMoveDown)
self.actSplitDialog.triggered.connect(self.documentsSplitDialog)
@ -225,6 +251,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
We get notified by qApp when focus changes, from old to new widget.
"""
# If new is a MDEditView, we keep it in memory
if issubclass(type(new), MDEditView):
self._lastMDEditView = new
else:
self._lastMDEditView = None
# Determine which view had focus last, to send the keyboard shortcuts
# to the right place
@ -443,12 +475,14 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def openIndexes(self, indexes, newTab=True):
self.mainEditor.openIndexes(indexes, newTab=True)
# Menu Documents #############################################################
# Menu #############################################################
# Functions called by the menu Documents
# Functions called by the menus
# self._lastFocus is the last editor that had focus (either treeView or
# mainEditor). So we just pass along the signal.
# Edit
def documentsCopy(self):
"Copy selected item(s)."
if self._lastFocus: self._lastFocus.copy()
@ -467,6 +501,38 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def documentsDelete(self):
"Delete selected item(s)."
if self._lastFocus: self._lastFocus.delete()
# Formats
def callLastMDEditView(self, functionName, param=[]):
"""
If last focused widget was MDEditView, call the given function.
"""
if self._lastMDEditView:
function = getattr(self._lastMDEditView, functionName)
function(*param)
def formatSetext1(self): self.callLastMDEditView("titleSetext", [1])
def formatSetext2(self): self.callLastMDEditView("titleSetext", [2])
def formatAtx1(self): self.callLastMDEditView("titleATX", [1])
def formatAtx2(self): self.callLastMDEditView("titleATX", [2])
def formatAtx3(self): self.callLastMDEditView("titleATX", [3])
def formatAtx4(self): self.callLastMDEditView("titleATX", [4])
def formatAtx5(self): self.callLastMDEditView("titleATX", [5])
def formatAtx6(self): self.callLastMDEditView("titleATX", [6])
def formatBold(self): self.callLastMDEditView("bold")
def formatItalic(self): self.callLastMDEditView("italic")
def formatStrike(self): self.callLastMDEditView("strike")
def formatVerbatim(self): self.callLastMDEditView("verbatim")
def formatSuperscript(self): self.callLastMDEditView("superscript")
def formatSubscript(self): self.callLastMDEditView("subscript")
def formatCommentLines(self): self.callLastMDEditView("commentLine")
def formatList(self): self.callLastMDEditView("unorderedList")
def formatOrderedList(self): self.callLastMDEditView("orderedList")
def formatBlockquote(self): self.callLastMDEditView("blockquote")
def formatCommentBlock(self): self.callLastMDEditView("comment")
def formatClear(self): self.callLastMDEditView("clearFormat")
# Organize
def documentsMoveUp(self):
"Move up selected item(s)."
if self._lastFocus: self._lastFocus.moveUp()

View file

@ -378,7 +378,7 @@ class Ui_MainWindow(object):
self.scrollAreaPersoInfos.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
self.scrollAreaPersoInfos.setObjectName("scrollAreaPersoInfos")
self.scrollAreaPersoInfosWidget = QtWidgets.QWidget()
self.scrollAreaPersoInfosWidget.setGeometry(QtCore.QRect(0, 0, 426, 688))
self.scrollAreaPersoInfosWidget.setGeometry(QtCore.QRect(0, 0, 204, 606))
self.scrollAreaPersoInfosWidget.setObjectName("scrollAreaPersoInfosWidget")
self.formLayout_8 = QtWidgets.QFormLayout(self.scrollAreaPersoInfosWidget)
self.formLayout_8.setFieldGrowthPolicy(QtWidgets.QFormLayout.AllNonFixedFieldsGrow)
@ -1040,6 +1040,12 @@ class Ui_MainWindow(object):
self.menuTools.setObjectName("menuTools")
self.menuEdit = QtWidgets.QMenu(self.menubar)
self.menuEdit.setObjectName("menuEdit")
self.mnuFormat = QtWidgets.QMenu(self.menuEdit)
icon = QtGui.QIcon.fromTheme("format-text-bold")
self.mnuFormat.setIcon(icon)
self.mnuFormat.setObjectName("mnuFormat")
self.mnuHeader = QtWidgets.QMenu(self.mnuFormat)
self.mnuHeader.setObjectName("mnuHeader")
self.menuView = QtWidgets.QMenu(self.menubar)
self.menuView.setObjectName("menuView")
self.menuMode = QtWidgets.QMenu(self.menuView)
@ -1214,6 +1220,56 @@ class Ui_MainWindow(object):
icon = QtGui.QIcon.fromTheme("edit-rename")
self.actRename.setIcon(icon)
self.actRename.setObjectName("actRename")
self.actHeaderSetextL1 = QtWidgets.QAction(MainWindow)
self.actHeaderSetextL1.setObjectName("actHeaderSetextL1")
self.actHeaderSetextL2 = QtWidgets.QAction(MainWindow)
self.actHeaderSetextL2.setObjectName("actHeaderSetextL2")
self.actHeaderAtxL1 = QtWidgets.QAction(MainWindow)
self.actHeaderAtxL1.setObjectName("actHeaderAtxL1")
self.actHeaderAtxL2 = QtWidgets.QAction(MainWindow)
self.actHeaderAtxL2.setObjectName("actHeaderAtxL2")
self.actHeaderAtxL3 = QtWidgets.QAction(MainWindow)
self.actHeaderAtxL3.setObjectName("actHeaderAtxL3")
self.actHeaderAtxL4 = QtWidgets.QAction(MainWindow)
self.actHeaderAtxL4.setObjectName("actHeaderAtxL4")
self.actHeaderAtxL5 = QtWidgets.QAction(MainWindow)
self.actHeaderAtxL5.setObjectName("actHeaderAtxL5")
self.actHeaderAtxL6 = QtWidgets.QAction(MainWindow)
self.actHeaderAtxL6.setObjectName("actHeaderAtxL6")
self.actFormatBold = QtWidgets.QAction(MainWindow)
icon = QtGui.QIcon.fromTheme("format-text-bold")
self.actFormatBold.setIcon(icon)
self.actFormatBold.setObjectName("actFormatBold")
self.actFormatItalic = QtWidgets.QAction(MainWindow)
icon = QtGui.QIcon.fromTheme("format-text-italic")
self.actFormatItalic.setIcon(icon)
self.actFormatItalic.setObjectName("actFormatItalic")
self.actFormatStrike = QtWidgets.QAction(MainWindow)
icon = QtGui.QIcon.fromTheme("format-text-strikethrough")
self.actFormatStrike.setIcon(icon)
self.actFormatStrike.setObjectName("actFormatStrike")
self.actFormatVerbatim = QtWidgets.QAction(MainWindow)
self.actFormatVerbatim.setObjectName("actFormatVerbatim")
self.actFormatSuperscript = QtWidgets.QAction(MainWindow)
self.actFormatSuperscript.setObjectName("actFormatSuperscript")
self.actFormatSubscript = QtWidgets.QAction(MainWindow)
self.actFormatSubscript.setObjectName("actFormatSubscript")
self.actFormatCommentBlock = QtWidgets.QAction(MainWindow)
self.actFormatCommentBlock.setObjectName("actFormatCommentBlock")
self.actFormatClear = QtWidgets.QAction(MainWindow)
icon = QtGui.QIcon.fromTheme("format-text-none")
self.actFormatClear.setIcon(icon)
self.actFormatClear.setObjectName("actFormatClear")
self.actFormatCommentLines = QtWidgets.QAction(MainWindow)
self.actFormatCommentLines.setObjectName("actFormatCommentLines")
self.actFormatOrderedList = QtWidgets.QAction(MainWindow)
self.actFormatOrderedList.setObjectName("actFormatOrderedList")
self.actFormatList = QtWidgets.QAction(MainWindow)
icon = QtGui.QIcon.fromTheme("view-list")
self.actFormatList.setIcon(icon)
self.actFormatList.setObjectName("actFormatList")
self.actFormatBlockquote = QtWidgets.QAction(MainWindow)
self.actFormatBlockquote.setObjectName("actFormatBlockquote")
self.menuFile.addAction(self.actOpen)
self.menuFile.addAction(self.menuRecents.menuAction())
self.menuFile.addAction(self.actSave)
@ -1228,12 +1284,39 @@ class Ui_MainWindow(object):
self.menuHelp.addAction(self.actAbout)
self.menuTools.addAction(self.actSpellcheck)
self.menuTools.addAction(self.actToolFrequency)
self.mnuHeader.addAction(self.actHeaderSetextL1)
self.mnuHeader.addAction(self.actHeaderSetextL2)
self.mnuHeader.addSeparator()
self.mnuHeader.addAction(self.actHeaderAtxL1)
self.mnuHeader.addAction(self.actHeaderAtxL2)
self.mnuHeader.addAction(self.actHeaderAtxL3)
self.mnuHeader.addAction(self.actHeaderAtxL4)
self.mnuHeader.addAction(self.actHeaderAtxL5)
self.mnuHeader.addAction(self.actHeaderAtxL6)
self.mnuFormat.addAction(self.mnuHeader.menuAction())
self.mnuFormat.addSeparator()
self.mnuFormat.addAction(self.actFormatBold)
self.mnuFormat.addAction(self.actFormatItalic)
self.mnuFormat.addAction(self.actFormatStrike)
self.mnuFormat.addAction(self.actFormatVerbatim)
self.mnuFormat.addAction(self.actFormatSuperscript)
self.mnuFormat.addAction(self.actFormatSubscript)
self.mnuFormat.addAction(self.actFormatCommentLines)
self.mnuFormat.addSeparator()
self.mnuFormat.addAction(self.actFormatList)
self.mnuFormat.addAction(self.actFormatOrderedList)
self.mnuFormat.addAction(self.actFormatBlockquote)
self.mnuFormat.addAction(self.actFormatCommentBlock)
self.mnuFormat.addSeparator()
self.mnuFormat.addAction(self.actFormatClear)
self.menuEdit.addAction(self.actCut)
self.menuEdit.addAction(self.actCopy)
self.menuEdit.addAction(self.actPaste)
self.menuEdit.addAction(self.actDelete)
self.menuEdit.addAction(self.actRename)
self.menuEdit.addSeparator()
self.menuEdit.addAction(self.mnuFormat.menuAction())
self.menuEdit.addSeparator()
self.menuEdit.addAction(self.actLabels)
self.menuEdit.addAction(self.actStatus)
self.menuEdit.addAction(self.actSettings)
@ -1366,6 +1449,8 @@ class Ui_MainWindow(object):
self.menuHelp.setTitle(_translate("MainWindow", "&Help"))
self.menuTools.setTitle(_translate("MainWindow", "&Tools"))
self.menuEdit.setTitle(_translate("MainWindow", "&Edit"))
self.mnuFormat.setTitle(_translate("MainWindow", "&Format"))
self.mnuHeader.setTitle(_translate("MainWindow", "&Header"))
self.menuView.setTitle(_translate("MainWindow", "&View"))
self.menuMode.setTitle(_translate("MainWindow", "&Mode"))
self.menuOrganize.setTitle(_translate("MainWindow", "Organi&ze"))
@ -1415,7 +1500,6 @@ class Ui_MainWindow(object):
self.actMerge.setText(_translate("MainWindow", "M&erge"))
self.actMerge.setShortcut(_translate("MainWindow", "Ctrl+M"))
self.actDuplicate.setText(_translate("MainWindow", "Dupl&icate"))
self.actDuplicate.setShortcut(_translate("MainWindow", "Ctrl+D"))
self.actDelete.setText(_translate("MainWindow", "&Delete"))
self.actDelete.setShortcut(_translate("MainWindow", "Del"))
self.actMoveUp.setText(_translate("MainWindow", "&Move Up"))
@ -1424,6 +1508,41 @@ class Ui_MainWindow(object):
self.actMoveDown.setShortcut(_translate("MainWindow", "Ctrl+Shift+Down"))
self.actRename.setText(_translate("MainWindow", "&Rename"))
self.actRename.setShortcut(_translate("MainWindow", "F2"))
self.actHeaderSetextL1.setText(_translate("MainWindow", "&Level 1 (setext)"))
self.actHeaderSetextL1.setShortcut(_translate("MainWindow", "Ctrl+Alt+1"))
self.actHeaderSetextL2.setText(_translate("MainWindow", "Level &2"))
self.actHeaderSetextL2.setShortcut(_translate("MainWindow", "Ctrl+Alt+2"))
self.actHeaderAtxL1.setText(_translate("MainWindow", "Level &1 (atx)"))
self.actHeaderAtxL1.setShortcut(_translate("MainWindow", "Ctrl+1"))
self.actHeaderAtxL2.setText(_translate("MainWindow", "L&evel 2"))
self.actHeaderAtxL2.setShortcut(_translate("MainWindow", "Ctrl+2"))
self.actHeaderAtxL3.setText(_translate("MainWindow", "Level &3"))
self.actHeaderAtxL3.setShortcut(_translate("MainWindow", "Ctrl+3"))
self.actHeaderAtxL4.setText(_translate("MainWindow", "Level &4"))
self.actHeaderAtxL4.setShortcut(_translate("MainWindow", "Ctrl+4"))
self.actHeaderAtxL5.setText(_translate("MainWindow", "Level &5"))
self.actHeaderAtxL5.setShortcut(_translate("MainWindow", "Ctrl+5"))
self.actHeaderAtxL6.setText(_translate("MainWindow", "Level &6"))
self.actHeaderAtxL6.setShortcut(_translate("MainWindow", "Ctrl+6"))
self.actFormatBold.setText(_translate("MainWindow", "&Bold"))
self.actFormatBold.setShortcut(_translate("MainWindow", "Ctrl+B"))
self.actFormatItalic.setText(_translate("MainWindow", "&Italic"))
self.actFormatItalic.setShortcut(_translate("MainWindow", "Ctrl+I"))
self.actFormatStrike.setText(_translate("MainWindow", "&Strike"))
self.actFormatVerbatim.setText(_translate("MainWindow", "&Verbatim"))
self.actFormatSuperscript.setText(_translate("MainWindow", "Su&perscript"))
self.actFormatSuperscript.setShortcut(_translate("MainWindow", "Ctrl++"))
self.actFormatSubscript.setText(_translate("MainWindow", "Subsc&ript"))
self.actFormatSubscript.setShortcut(_translate("MainWindow", "Ctrl+-"))
self.actFormatCommentBlock.setText(_translate("MainWindow", "Co&mment block"))
self.actFormatCommentBlock.setShortcut(_translate("MainWindow", "Ctrl+Shift+C"))
self.actFormatClear.setText(_translate("MainWindow", "Clear &formats"))
self.actFormatClear.setShortcut(_translate("MainWindow", "Ctrl+0"))
self.actFormatCommentLines.setText(_translate("MainWindow", "&Comment line(s)"))
self.actFormatCommentLines.setShortcut(_translate("MainWindow", "Ctrl+D"))
self.actFormatOrderedList.setText(_translate("MainWindow", "&Ordered list"))
self.actFormatList.setText(_translate("MainWindow", "&Unordered list"))
self.actFormatBlockquote.setText(_translate("MainWindow", "B&lockquote"))
from manuskript.ui.cheatSheet import cheatSheet
from manuskript.ui.editors.mainEditor import mainEditor

View file

@ -629,7 +629,7 @@
</property>
<property name="icon">
<iconset theme="go-next">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
@ -640,7 +640,7 @@
</property>
<property name="icon">
<iconset theme="go-next">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
@ -651,7 +651,7 @@
</property>
<property name="icon">
<iconset theme="go-next">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
@ -662,7 +662,7 @@
</property>
<property name="icon">
<iconset theme="go-next">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
@ -737,7 +737,7 @@
</property>
<property name="icon">
<iconset theme="list-add">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="flat">
<bool>true</bool>
@ -751,7 +751,7 @@
</property>
<property name="icon">
<iconset theme="list-remove">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="flat">
<bool>true</bool>
@ -815,8 +815,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>426</width>
<height>688</height>
<width>204</width>
<height>606</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout_8">
@ -905,7 +905,7 @@
</property>
<property name="icon">
<iconset theme="go-next">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="flat">
<bool>true</bool>
@ -988,7 +988,7 @@
</property>
<property name="icon">
<iconset theme="go-next">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
@ -1033,7 +1033,7 @@
</property>
<property name="icon">
<iconset theme="list-add">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
@ -1044,7 +1044,7 @@
</property>
<property name="icon">
<iconset theme="list-remove">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
@ -1075,7 +1075,7 @@
</property>
<property name="icon">
<iconset theme="go-next">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
@ -1136,7 +1136,7 @@
</property>
<property name="icon">
<iconset theme="list-add">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="flat">
<bool>true</bool>
@ -1150,7 +1150,7 @@
</property>
<property name="icon">
<iconset theme="list-remove">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="flat">
<bool>true</bool>
@ -1264,7 +1264,7 @@
</property>
<property name="icon">
<iconset theme="list-add">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="flat">
<bool>true</bool>
@ -1281,7 +1281,7 @@
</property>
<property name="icon">
<iconset theme="list-remove">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="flat">
<bool>true</bool>
@ -1355,7 +1355,7 @@
</property>
<property name="icon">
<iconset theme="list-add">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="shortcut">
<string>Ctrl+Return</string>
@ -1375,7 +1375,7 @@
</property>
<property name="icon">
<iconset theme="list-remove">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="shortcut">
<string>Ctrl+Backspace</string>
@ -1405,7 +1405,7 @@
</property>
<property name="icon">
<iconset theme="text-x-generic">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="checkable">
<bool>true</bool>
@ -1557,7 +1557,7 @@
</property>
<property name="icon">
<iconset theme="list-add">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="flat">
<bool>true</bool>
@ -1571,7 +1571,7 @@
</property>
<property name="icon">
<iconset theme="list-remove">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="flat">
<bool>true</bool>
@ -1770,7 +1770,7 @@
</property>
<property name="icon">
<iconset theme="folder-new">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="flat">
<bool>true</bool>
@ -1784,7 +1784,7 @@
</property>
<property name="icon">
<iconset theme="document-new">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="flat">
<bool>true</bool>
@ -1798,7 +1798,7 @@
</property>
<property name="icon">
<iconset theme="list-remove">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="flat">
<bool>true</bool>
@ -1825,7 +1825,7 @@
</property>
<property name="icon">
<iconset theme="text-x-generic">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="checkable">
<bool>true</bool>
@ -1917,7 +1917,7 @@
</property>
<property name="icon">
<iconset theme="folder-new">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="flat">
<bool>true</bool>
@ -1931,7 +1931,7 @@
</property>
<property name="icon">
<iconset theme="document-new">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="flat">
<bool>true</bool>
@ -1945,7 +1945,7 @@
</property>
<property name="icon">
<iconset theme="list-remove">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="flat">
<bool>true</bool>
@ -2137,12 +2137,53 @@
<property name="title">
<string>&amp;Edit</string>
</property>
<widget class="QMenu" name="mnuFormat">
<property name="title">
<string>&amp;Format</string>
</property>
<property name="icon">
<iconset theme="format-text-bold">
<normaloff>.</normaloff>.</iconset>
</property>
<widget class="QMenu" name="mnuHeader">
<property name="title">
<string>&amp;Header</string>
</property>
<addaction name="actHeaderSetextL1"/>
<addaction name="actHeaderSetextL2"/>
<addaction name="separator"/>
<addaction name="actHeaderAtxL1"/>
<addaction name="actHeaderAtxL2"/>
<addaction name="actHeaderAtxL3"/>
<addaction name="actHeaderAtxL4"/>
<addaction name="actHeaderAtxL5"/>
<addaction name="actHeaderAtxL6"/>
</widget>
<addaction name="mnuHeader"/>
<addaction name="separator"/>
<addaction name="actFormatBold"/>
<addaction name="actFormatItalic"/>
<addaction name="actFormatStrike"/>
<addaction name="actFormatVerbatim"/>
<addaction name="actFormatSuperscript"/>
<addaction name="actFormatSubscript"/>
<addaction name="actFormatCommentLines"/>
<addaction name="separator"/>
<addaction name="actFormatList"/>
<addaction name="actFormatOrderedList"/>
<addaction name="actFormatBlockquote"/>
<addaction name="actFormatCommentBlock"/>
<addaction name="separator"/>
<addaction name="actFormatClear"/>
</widget>
<addaction name="actCut"/>
<addaction name="actCopy"/>
<addaction name="actPaste"/>
<addaction name="actDelete"/>
<addaction name="actRename"/>
<addaction name="separator"/>
<addaction name="mnuFormat"/>
<addaction name="separator"/>
<addaction name="actLabels"/>
<addaction name="actStatus"/>
<addaction name="actSettings"/>
@ -2286,7 +2327,7 @@
<action name="actOpen">
<property name="icon">
<iconset theme="document-open">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Open</string>
@ -2298,7 +2339,7 @@
<action name="actSave">
<property name="icon">
<iconset theme="document-save">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Save</string>
@ -2310,7 +2351,7 @@
<action name="actSaveAs">
<property name="icon">
<iconset theme="document-save-as">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Sa&amp;ve as...</string>
@ -2322,7 +2363,7 @@
<action name="actQuit">
<property name="icon">
<iconset theme="application-exit">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Quit</string>
@ -2340,7 +2381,7 @@
</property>
<property name="icon">
<iconset theme="system-help">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Show help texts</string>
@ -2358,7 +2399,7 @@
</property>
<property name="icon">
<iconset theme="tools-check-spelling">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Spellcheck</string>
@ -2430,7 +2471,7 @@
<action name="actSettings">
<property name="icon">
<iconset theme="preferences-system">
<normaloff>../../../../../../../.designer/backup</normaloff>../../../../../../../.designer/backup</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>S&amp;ettings</string>
@ -2569,9 +2610,6 @@
<property name="text">
<string>Dupl&amp;icate</string>
</property>
<property name="shortcut">
<string>Ctrl+D</string>
</property>
</action>
<action name="actDelete">
<property name="icon">
@ -2621,18 +2659,178 @@
<string>F2</string>
</property>
</action>
<action name="actHeaderSetextL1">
<property name="text">
<string>&amp;Level 1 (setext)</string>
</property>
<property name="shortcut">
<string>Ctrl+Alt+1</string>
</property>
</action>
<action name="actHeaderSetextL2">
<property name="text">
<string>Level &amp;2</string>
</property>
<property name="shortcut">
<string>Ctrl+Alt+2</string>
</property>
</action>
<action name="actHeaderAtxL1">
<property name="text">
<string>Level &amp;1 (atx)</string>
</property>
<property name="shortcut">
<string>Ctrl+1</string>
</property>
</action>
<action name="actHeaderAtxL2">
<property name="text">
<string>L&amp;evel 2</string>
</property>
<property name="shortcut">
<string>Ctrl+2</string>
</property>
</action>
<action name="actHeaderAtxL3">
<property name="text">
<string>Level &amp;3</string>
</property>
<property name="shortcut">
<string>Ctrl+3</string>
</property>
</action>
<action name="actHeaderAtxL4">
<property name="text">
<string>Level &amp;4</string>
</property>
<property name="shortcut">
<string>Ctrl+4</string>
</property>
</action>
<action name="actHeaderAtxL5">
<property name="text">
<string>Level &amp;5</string>
</property>
<property name="shortcut">
<string>Ctrl+5</string>
</property>
</action>
<action name="actHeaderAtxL6">
<property name="text">
<string>Level &amp;6</string>
</property>
<property name="shortcut">
<string>Ctrl+6</string>
</property>
</action>
<action name="actFormatBold">
<property name="icon">
<iconset theme="format-text-bold">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Bold</string>
</property>
<property name="shortcut">
<string>Ctrl+B</string>
</property>
</action>
<action name="actFormatItalic">
<property name="icon">
<iconset theme="format-text-italic">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Italic</string>
</property>
<property name="shortcut">
<string>Ctrl+I</string>
</property>
</action>
<action name="actFormatStrike">
<property name="icon">
<iconset theme="format-text-strikethrough">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Strike</string>
</property>
</action>
<action name="actFormatVerbatim">
<property name="text">
<string>&amp;Verbatim</string>
</property>
</action>
<action name="actFormatSuperscript">
<property name="text">
<string>Su&amp;perscript</string>
</property>
<property name="shortcut">
<string>Ctrl++</string>
</property>
</action>
<action name="actFormatSubscript">
<property name="text">
<string>Subsc&amp;ript</string>
</property>
<property name="shortcut">
<string>Ctrl+-</string>
</property>
</action>
<action name="actFormatCommentBlock">
<property name="text">
<string>Co&amp;mment block</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+C</string>
</property>
</action>
<action name="actFormatClear">
<property name="icon">
<iconset theme="format-text-none">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Clear &amp;formats</string>
</property>
<property name="shortcut">
<string>Ctrl+0</string>
</property>
</action>
<action name="actFormatCommentLines">
<property name="text">
<string>&amp;Comment line(s)</string>
</property>
<property name="shortcut">
<string>Ctrl+D</string>
</property>
</action>
<action name="actFormatOrderedList">
<property name="text">
<string>&amp;Ordered list</string>
</property>
</action>
<action name="actFormatList">
<property name="icon">
<iconset theme="view-list">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Unordered list</string>
</property>
</action>
<action name="actFormatBlockquote">
<property name="text">
<string>B&amp;lockquote</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>textEditView</class>
<class>MDEditCompleter</class>
<extends>QTextEdit</extends>
<header>manuskript.ui.views.textEditView.h</header>
<header>manuskript.ui.views.MDEditCompleter.h</header>
</customwidget>
<customwidget>
<class>MDEditCompleter</class>
<extends>QTextEdit</extends>
<header>manuskript.ui.views.MDEditCompleter.h</header>
</customwidget>
<customwidget>
<class>lineEditView</class>
<extends>QLineEdit</extends>

View file

@ -10,11 +10,14 @@ from PyQt5.QtGui import QTextCursor
from manuskript.ui.views.textEditView import textEditView
from manuskript.ui.highlighters import MarkdownHighlighter
from manuskript import settings
# from manuskript.ui.editors.textFormat import textFormat
# from manuskript.ui.editors.MDFunctions import MDFormatSelection
from manuskript.ui.highlighters.markdownEnums import MarkdownState as MS
class MDEditView(textEditView):
blockquoteRegex = QRegExp("^ {0,3}(>\\s*)+")
listRegex = QRegExp("^(\\s*)([+*-]|([0-9a-z])+([.\)]))(\\s+)")
def __init__(self, parent=None, index=None, html=None, spellcheck=True,
highlighting=False, dict="", autoResize=False):
textEditView.__init__(self, parent, index, html, spellcheck,
@ -33,19 +36,131 @@ class MDEditView(textEditView):
self.verticalScrollBar().rangeChanged.connect(
self.scrollBarRangeChanged)
# def focusInEvent(self, event):
# """Finds textFormatter and attach them to that view."""
# textEditView.focusInEvent(self, event)
#
# p = self.parent()
# while p.parent():
# p = p.parent()
#
# if self._index:
# for tF in p.findChildren(textFormat, QRegExp(".*"),
# Qt.FindChildrenRecursively):
# tF.updateFromIndex(self._index)
# tF.setTextEdit(self)
###########################################################################
# KEYPRESS
###########################################################################
def keyPressEvent(self, event):
k = event.key()
m = event.modifiers()
cursor = self.textCursor()
# RETURN
if k == Qt.Key_Return:
if not cursor.hasSelection():
if m & Qt.ShiftModifier:
# Insert Markdown-style line break
cursor.insertText(" ")
if m & Qt.ControlModifier:
cursor.insertText("\n")
else:
self.handleCarriageReturn()
else:
textEditView.keyPressEvent(self, event)
# TAB
elif k == Qt.Key_Tab:
#self.indentText()
# FIXME
textEditView.keyPressEvent(self, event)
elif k == Qt.Key_Backtab:
#self.unindentText()
# FIXME
textEditView.keyPressEvent(self, event)
else:
textEditView.keyPressEvent(self, event)
# Thanks to GhostWriter, mainly
def handleCarriageReturn(self):
autoInsertText = "";
cursor = self.textCursor()
endList = False
moveBack = False
text = cursor.block().text()
if cursor.positionInBlock() < cursor.block().length() - 1:
autoInsertText = self.getPriorIndentation()
if cursor.positionInBlock() < len(autoInsertText):
autoInsertText = autoInsertText[:cursor.positionInBlock()]
else:
s = cursor.block().userState()
if s in [MS.MarkdownStateNumberedList,
MS.MarkdownStateBulletPointList]:
self.listRegex.indexIn(text)
g = self.listRegex.capturedTexts()
# 0 = " a. " or " * "
# 1 = " " " "
# 2 = "a." "*"
# 3 = "a" ""
# 4 = "." ""
# 5 = " " " "
# If the line of text is an empty list item, end the list.
if len(g[0].strip()) == len(text.strip()):
endList = True
# Else increment the list number
elif g[3]: # Numbered list
try: # digit
i = int(g[3])+1
except: # letter
i = chr(ord(g[3])+1)
autoInsertText = "{}{}{}{}".format(
g[1], i, g[4], g[5])
else: # Bullet list
autoInsertText = g[0]
if text[-2:] == " ":
autoInsertText = " " * len(autoInsertText)
elif s == MS.MarkdownStateBlockquote:
self.blockquoteRegex.indexIn(text)
g = self.blockquoteRegex.capturedTexts()
autoInsertText = g[0]
elif s in [MS.MarkdownStateInGithubCodeFence,
MS.MarkdownStateInPandocCodeFence] and \
cursor.block().previous().userState() != s:
autoInsertText = "\n" + text
moveBack = True
else:
autoInsertText = self.getPriorIndentation()
# Clear the list
if endList:
autoInsertText = self.getPriorIndentation()
cursor.movePosition(QTextCursor.StartOfBlock)
cursor.movePosition(QTextCursor.EndOfBlock, QTextCursor.KeepAnchor)
cursor.insertText(autoInsertText)
autoInsertText = ""
# Finally, we insert
cursor.insertText("\n" + autoInsertText)
if moveBack:
cursor.movePosition(QTextCursor.PreviousBlock)
self.setTextCursor(cursor)
self.ensureCursorVisible()
def getPriorIndentation(self):
text = self.textCursor().block().text()
l = len(text) - len(text.lstrip())
return text[:l]
def getPriorMarkdownBlockItemStart(self, itemRegex):
text = self.textCursor().block().text()
if itemRegex.indexIn(text) >= 0:
return text[itemRegex.matchedLength():]
return ""
###########################################################################
# TypeWriterScrolling
@ -79,23 +194,18 @@ class MDEditView(textEditView):
self.verticalScrollBar().blockSignals(False)
###########################################################################
# FORMATTING (#FIXME)
# FORMATTING
###########################################################################
def applyFormat(self, _format):
if self._textFormat == "md":
if _format == "Bold": self.bold()
elif _format == "Italic": self.italic()
elif _format == "Code": self.verbatim()
elif _format == "Clear": self.clearFormat()
def bold(self): self.insertFormattingMarkup("**")
def italic(self): self.insertFormattingMarkup("*")
def strike(self): self.insertFormattingMarkup("~~")
def verbatim(self): self.insertFormattingMarkup("`")
def superscript(self): self.insertFormattingMarkup("^")
def subscript(self): self.insertFormattingMarkup("~")
def blockquote(self): self.lineFormattingMarkup("> ")
def orderedList(self): self.lineFormattingMarkup(" 1. ")
def unorderedList(self): self.lineFormattingMarkup(" - ")
def selectWord(self, cursor):
if cursor.selectedText():
@ -161,6 +271,14 @@ class MDEditView(textEditView):
self.selectBlock(cursor)
cursor.insertText(text2)
def lineFormattingMarkup(self, markup):
"""
Adds `markup` at the begining of block.
"""
cursor = self.textCursor()
cursor.movePosition(cursor.StartOfBlock)
cursor.insertText(markup)
def insertFormattingMarkup(self, markup):
cursor = self.textCursor()
@ -211,8 +329,7 @@ class MDEditView(textEditView):
("~~(.*?)~~", "\\1", None), # strike
("\^(.*?)\^", "\\1", None), # superscript
("~(.*?)~", "\\1", None), # subscript
("<!--(.*)-->", "\\1", re.S), # comments
("<!--\s*(.*?)\s*-->", "\\1", re.S), # comments
# LINES OR BLOCKS
(r"^#*\s*(.+?)\s*", "\\1", re.M), # ATX