Better compatibility with the Codemirror editor and the markdown circuit extension.
This commit is contained in:
@@ -5,12 +5,14 @@ Image Circuit Extension for Python-Markdown
|
||||
|
||||
circuit:name becomes the circuit.
|
||||
'''
|
||||
import markdown
|
||||
import re
|
||||
|
||||
import simplewiki.settings as settings
|
||||
|
||||
from mitxmako.shortcuts import render_to_response, render_to_string
|
||||
|
||||
import markdown
|
||||
|
||||
try:
|
||||
# Markdown 2.1.0 changed from 2.0.3. We try importing the new version first,
|
||||
# but import the 2.0.3 version if it fails
|
||||
@@ -22,22 +24,40 @@ class CircuitExtension(markdown.Extension):
|
||||
def __init__(self, configs):
|
||||
for key, value in configs :
|
||||
self.setConfig(key, value)
|
||||
|
||||
def add_inline(self, md, name, klass, re):
|
||||
pattern = klass(re)
|
||||
pattern.md = md
|
||||
pattern.ext = self
|
||||
md.inlinePatterns.add(name, pattern, "<reference")
|
||||
|
||||
|
||||
def extendMarkdown(self, md, md_globals):
|
||||
self.add_inline(md, 'circuit', CircuitLink, r'^circuit-schematic:(?P<data>.*)$')
|
||||
## Because Markdown treats contigous lines as one block of text, it is hard to match
|
||||
## a regex that must occupy the whole line (like the circuit regex). This is why we have
|
||||
## a preprocessor that inspects the lines and replaces the matched lines with text that is
|
||||
## easier to match
|
||||
md.preprocessors.add('circuit', CircuitPreprocessor(md), "_begin")
|
||||
|
||||
pattern = CircuitLink(r'processed-schematic:(?P<data>.*?)processed-schematic-end')
|
||||
pattern.md = md
|
||||
pattern.ext = self
|
||||
md.inlinePatterns.add('circuit', pattern, "<reference")
|
||||
|
||||
|
||||
class CircuitPreprocessor(markdown.preprocessors.Preprocessor):
|
||||
preRegex = re.compile(r'^circuit-schematic:(?P<data>.*)$')
|
||||
|
||||
def run(self, lines):
|
||||
new_lines = []
|
||||
for line in lines:
|
||||
m = self.preRegex.match(line)
|
||||
if m:
|
||||
new_lines.append('processed-schematic:{0}processed-schematic-end'.format( m.group('data') ))
|
||||
else:
|
||||
new_lines.append(line)
|
||||
return new_lines
|
||||
|
||||
|
||||
class CircuitLink(markdown.inlinepatterns.Pattern):
|
||||
def handleMatch(self, m):
|
||||
data = m.group('data')
|
||||
|
||||
##TODO: We need to html escape the data
|
||||
return etree.fromstring("<input type='hidden' parts='' value='" + data + "' analyses='' class='schematic ctrls'/>")
|
||||
return etree.fromstring("<input type='hidden' parts='' value='" + data + "' analyses='' class='schematic ctrls' width='150' height='150'/>")
|
||||
|
||||
|
||||
def makeExtension(configs=None) :
|
||||
|
||||
@@ -276,7 +276,6 @@ class Revision(models.Model):
|
||||
# Create pre-parsed contents - no need to parse on-the-fly
|
||||
ext = WIKI_MARKDOWN_EXTENSIONS
|
||||
ext += ["wikipath(base_url=%s)" % reverse('wiki_view', args=('/',))]
|
||||
print ext
|
||||
self.contents_parsed = markdown(self.contents,
|
||||
extensions=ext,
|
||||
safe_mode='escape',)
|
||||
|
||||
@@ -980,7 +980,7 @@ var CodeMirror = (function() {
|
||||
maxWidth = scroller.clientWidth;
|
||||
var curNode = lineDiv.firstChild, heightChanged = false;
|
||||
doc.iter(showingFrom, showingTo, function(line) {
|
||||
if (!line.hidden && !line.widgetFunction) { //TODO: We should handle widget blocks better here
|
||||
if (!line.hidden && !line.widgetFunction) {
|
||||
var height = Math.round(curNode.offsetHeight / th) || 1;
|
||||
if (line.widgetFunction) height = line.widgetFunction.size(line.text).height / textHeight();
|
||||
if (line.height != height) {
|
||||
|
||||
@@ -77,6 +77,8 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) {
|
||||
update_schematics();
|
||||
var schmInput = node.firstChild;
|
||||
schmInput.codeMirrorLine = line;
|
||||
schmInput.schematic.always_draw_grid = true;
|
||||
schmInput.schematic.redraw_background();
|
||||
$(node).leanModal();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
mode: 'mitx_markdown',
|
||||
matchBrackets: true,
|
||||
theme: "default",
|
||||
lineWrapping: false,
|
||||
lineWrapping: true,
|
||||
});
|
||||
|
||||
//Store the inital contents so we can compare for unsaved changes
|
||||
|
||||
Reference in New Issue
Block a user