Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Feature updates #33

Closed
wants to merge 6 commits into from

2 participants

@ShadowKyogre

These commits add:

  • syntax highlighting for asciimath (for #32)
  • enable asciimathml on future notebooks (requires the python 3 version of that module) (for #32)
  • a small fix for highlighting nested lists
  • Quick navigation of notes via an autocompleting box that can be autofocused with Ctrl+G (for #19)
@rnons
Collaborator

Great, thank you for your contributions.
Would you like to take over mikidown?

@ShadowKyogre Complete mathjax support by pointing to the mathjax cdn by default.
Users can configure which mathjax they want by changing the mathJax
setting value to point to a local installation or copy.
71d05f4
@ShadowKyogre

@rnons : You're very much welcome! And if it'd make maintaining mikidown easier for you, I'd be happy to :).

@rnons
Collaborator

@ShadowKyogre What I mean is I'd like to transfer the ownership of mikidown to you, and If you take it I won't maintain mikidown anymore.

Can you please add some document on how to enable/disable asciimathml/mathjax in this PR.
On a side note, we may need a plugin mechanism and a dialog to allow user enable/disable a plugin/feature easily.

@ShadowKyogre

@rnons: Ooooh, all right. I should be able to handle maintaining it.

AsciiMathML doc stuff

Enabling

For existing notebooks, will be autoenabled on new ones. This is for enabling it on old ones:

  1. Make sure that the user has the python 3 version of asciimathml installed.
  2. in notebookPath/notebook.conf, look for the line that says "extensions =". Add asciimathml to the end of it.
  3. in notebookPath/notebook.conf, add a line that says:mathJax = /path/to/your/MathJax.js For most people, pointing to the mathjax CDN mentioned below is fine: http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML
  4. Type away some asciimathml. The script pointed to in mathJax should auto-process the MathML elements spat out by asciimathml.

Disabling asciimathml

  1. in notebookPath/notebook.conf, look for the line that says "extensions =". Remove asciimathml from it.

Enabling/Disabling plugins easily?

I definitely agree with that. It's something that I've been thinking of. Just requires a bit of thinking of how to list all the available markdown modules for the user to toggle with the GUI.

@rnons
Collaborator

It seems in order to transfer, you need to delete ShadowKyogre/mikidown or rename it temporarily.

@ShadowKyogre

@rnons: Renamed personal copy now. Should be able to transfer it.

@rnons
Collaborator

Sorry, github complains

ShadowKyogre already has a repository in the rnons/mikidown network

I believe you need to delete the online version, since you have local copy, it should not cause any trouble.

@ShadowKyogre

Deleted it and extracted the last few commits into a patch file to apply with ownership transfer. Try it now.

@rnons
Collaborator

Repository transfer to ShadowKyogre requested

Have you received any notification?

@ShadowKyogre

Yup. Clicked the repository transfer link just now.

@ShadowKyogre

Applied the commits now. Will close this issue.

@ShadowKyogre ShadowKyogre referenced this pull request
Closed

Mathjax support #32

@rnons
Collaborator
@rnons
Collaborator

@ShadowKyogre Do you have a pypi account? I'd like to make you the owner of mikidown on pypi.

@ShadowKyogre

@rnons : Just made one right now considering how odd it was I didn't have one (esp. when I tend to write in python a lot)

@rnons
Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
7 mikidown/config.py
@@ -37,6 +37,7 @@ def __init__(self, notebooks):
self.version = self.qsettings.value("version")
self.geometry = self.qsettings.value("geometry")
self.windowstate = self.qsettings.value("windowstate")
+ self.mathjax = self.qsettings.value('mathJax')
else:
self.extensions = []
self.fileExt = ""
@@ -45,6 +46,7 @@ def __init__(self, notebooks):
self.version = None
self.geometry = None
self.windowstate = None
+ self.mathjax = ''
# Default enabled python-markdown extensions.
# http://pythonhosted.org/Markdown/extensions/index.html
@@ -57,6 +59,7 @@ def __init__(self, notebooks):
, 'headerid' # add id to headers
, 'headerlink' # add anchor to headers
, 'footnotes'
+ , 'asciimathml'
]
writeListToSettings(self.qsettings, "extensions", self.extensions)
@@ -105,6 +108,10 @@ def __init__(self, notebooks):
self.version = '0'
+ if not self.mathjax:
+ self.mathjax = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'
+ self.qsettings.setValue('mathJax', self.mathjax)
+
def saveGeometry(self, geometry):
self.qsettings.setValue("geometry", geometry)
View
63 mikidown/highlighter.py
@@ -12,7 +12,7 @@ class MikiHighlighter(QSyntaxHighlighter):
def __init__(self, parent=None):
super(MikiHighlighter, self).__init__(parent)
baseFontSize = 12
- NUM = 15
+ NUM = 16
self.patterns = []
regexp = [0] * NUM
font = [0]*NUM
@@ -71,13 +71,19 @@ def __init__(self, parent=None):
color[12] = QColor("#204A87")
font[12] = QFont(None, baseFontSize, -1)
# 13: blockquotes and lists - > or - or *
- regexp[13] = r'(^>+)|(^- )|(^\* )'
+ regexp[13] = r'(^>+)|(^(?: |\t)*- )|(^(?: |\t)*\* )'
color[13] = QColor("#F57900")
font[13] = QFont(None, baseFontSize, -1)
# 14: fence - ``` or ~~~
regexp[14] = '^(?:~{3,}|`{3,}).*$'
color[14] = QColor("#F57900")
font[14] = QFont(None, baseFontSize, QFont.Bold)
+
+ # 15: math - $$
+ regexp[15] = r'^(?:\${2}).*$'
+ color[15] = QColor("#F5006E")
+ font[15] = QFont(None, baseFontSize, QFont.Bold)
+
for i in range(NUM):
p = re.compile(regexp[i])
f = QTextCharFormat()
@@ -93,6 +99,14 @@ def __init__(self, parent=None):
self.fenced_format = QTextCharFormat()
self.fenced_format.setFont(fenced_font)
+ math_font = QFont("monospace", baseFontSize, -1)
+ self.math_block = re.compile(r"^(?:\${2}).*$")
+ self.math_format = QTextCharFormat()
+ self.math_format.setFont(math_font)
+
+ self.settext_h1 = re.compile('^=+$')
+ self.settext_h2 = re.compile('^-+$')
+
def highlightSpellcheck(self, text):
for word_object in re.finditer(self.WORDS, str(text)):
@@ -114,17 +128,40 @@ def highlightBlock(self, text):
self.setFormat(
match.start(), match.end() - match.start(), p[1])
- # escape highlights in fenced_block
- m = self.fenced_block.match(text)
- self.setCurrentBlockState(0)
- if self.previousBlockState() != 1:
- if m:
- self.setCurrentBlockState(1)
+ if self.settext_h1.match(self.currentBlock().next().text()) and text != '':
+ self.setFormat(0, len(text), self.patterns[1][1])
+ self.setCurrentBlockState(3)
+ elif self.settext_h2.match(self.currentBlock().next().text()) and text != '':
+ self.setFormat(0, len(text), self.patterns[2][1])
+ self.setCurrentBlockState(4)
+ elif self.previousBlockState() == 3:
+ self.setFormat(0, len(text), self.patterns[1][1])
+ self.setCurrentBlockState(0)
+ elif self.previousBlockState() == 4:
+ self.setFormat(0, len(text), self.patterns[2][1])
+ self.setCurrentBlockState(0)
else:
- if m:
- self.setCurrentBlockState(0)
- else:
- self.setCurrentBlockState(1)
- self.setFormat(0, len(text), self.fenced_format)
+ # escape highlights in fenced_block
+ m = self.fenced_block.match(text)
+ m2 = self.math_block.match(text)
+ self.setCurrentBlockState(0)
+
+ if self.previousBlockState() < 1:
+ if m:
+ self.setCurrentBlockState(1)
+ elif m2:
+ self.setCurrentBlockState(2)
+ elif self.previousBlockState() == 1:
+ if m:
+ self.setCurrentBlockState(0)
+ else:
+ self.setCurrentBlockState(1)
+ self.setFormat(0, len(text), self.fenced_format)
+ elif self.previousBlockState() == 2:
+ if m2:
+ self.setCurrentBlockState(0)
+ else:
+ self.setCurrentBlockState(2)
+ self.setFormat(0, len(text), self.math_format)
self.highlightSpellcheck(text)
View
6 mikidown/mikiedit.py
@@ -7,8 +7,7 @@
from whoosh.index import open_dir
import html2text
-from .utils import LineEditDialog, parseTitle
-
+from .utils import LineEditDialog, parseTitle, jscript_tpl
class MikiEdit(QTextEdit):
@@ -241,7 +240,8 @@ def toHtml(self):
Previously `convert` was used, but it doens't work with fenced_code
'''
htmltext = self.toPlainText()
- return markdown.markdown(htmltext, self.settings.extensions)
+ return markdown.markdown(jscript_tpl.format(self.settings.mathjax)+
+ '\n'+htmltext, self.settings.extensions)
# md = markdown.Markdown(extensions)
# return md.convert(htmltext)
View
1  mikidown/mikiview.py
@@ -5,7 +5,6 @@
from PyQt4.QtWebKit import QWebView, QWebPage
import markdown
-
class MikiView(QWebView):
def __init__(self, parent=None):
View
20 mikidown/mikiwindow.py
@@ -17,6 +17,7 @@
from whoosh.qparser import QueryParser, RegexPlugin
import mikidown.mikidown_rc
+from .slashpleter import SlashPleter
from .config import __appname__, __version__
from .mikibook import NotebookListDialog
from .mikitree import MikiTree, TocTree
@@ -37,6 +38,11 @@ def __init__(self, settings, parent=None):
################ Setup core components ################
self.notesTree = MikiTree(self)
+ self.quickNoteNav = QLineEdit()
+ self.notesTab = QWidget()
+ self.completer = SlashPleter()
+ self.completer.setModel(self.notesTree.model())
+ self.quickNoteNav.setCompleter(self.completer)
self.notesTree.setObjectName("notesTree")
self.initTree(self.notePath, self.notesTree)
self.notesTree.sortItems(0, Qt.AscendingOrder)
@@ -176,6 +182,10 @@ def setupActions(self):
actionSortLines = self.act(self.tr('&Sort Lines'), self.sortLines)
self.actions.update(sortLines=actionSortLines)
+ actionQuickNav = self.act(self.tr("&Quick Open Note"),
+ self.quickNoteNav.setFocus, 'Ctrl+G')
+ self.addAction(actionQuickNav)
+
actionInsertImage = self.act(self.tr('&Insert Attachment'),
self.notesEdit.insertAttachmentWrapper, 'Ctrl+I')
actionInsertImage.setEnabled(False)
@@ -233,14 +243,19 @@ def setupMainWindow(self):
self.setCentralWidget(mainSplitter)
self.searchEdit.returnPressed.connect(self.searchNote)
+ self.quickNoteNav.returnPressed.connect(self.openFuncWrapper)
searchLayout = QVBoxLayout()
searchLayout.addWidget(self.searchEdit)
searchLayout.addWidget(self.searchView)
self.searchTab.setLayout(searchLayout)
self.tocTree.header().close()
+ indexLayout = QVBoxLayout(self.notesTab)
+ indexLayout.addWidget(self.quickNoteNav)
+ indexLayout.addWidget(self.notesTree)
+
self.dockIndex.setObjectName("Index")
- self.dockIndex.setWidget(self.notesTree)
+ self.dockIndex.setWidget(self.notesTab)
self.dockSearch.setObjectName("Search")
self.dockSearch.setWidget(self.searchTab)
self.dockToc.setObjectName("TOC")
@@ -338,6 +353,9 @@ def setupMainWindow(self):
item = self.notesTree.pageToItem(notes[0])
self.notesTree.setCurrentItem(item)
+ def openFuncWrapper(self):
+ self.openFunction(self.quickNoteNav.text())()
+
def setupWhoosh(self):
# Initialize whoosh index, make sure notePath/.indexdir exists
indexdir = self.settings.indexdir
View
12 mikidown/slashpleter.py
@@ -0,0 +1,12 @@
+from PyQt4 import QtGui, QtCore
+
+class SlashPleter(QtGui.QCompleter):
+ def splitPath(self, path):
+ return path.split('/')
+ def pathFromIndex(self, idx):
+ dataList=[]
+ i=idx
+ while i.isValid():
+ dataList.append(self.model().data(i, self.completionRole()))
+ i = i.parent()
+ return '/'.join(dataList[::-1])
View
1  mikidown/utils.py
@@ -4,6 +4,7 @@
from PyQt4.QtCore import Qt, QFile, QRect
from PyQt4.QtGui import (QDialog, QDialogButtonBox, QGridLayout, QIcon, QLabel, QLineEdit, QMessageBox, QPainter, QPixmap)
+jscript_tpl = '<script type="text/javascript" src="{}"></script>'
class ViewedNoteIcon(QIcon):
def __init__(self, num, parent=None):
Something went wrong with that request. Please try again.