diff --git a/djangoapps/simplewiki/mdx_circuit.py b/djangoapps/simplewiki/mdx_circuit.py index 33377eb019..72e432012f 100755 --- a/djangoapps/simplewiki/mdx_circuit.py +++ b/djangoapps/simplewiki/mdx_circuit.py @@ -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, ".*)$') + ## 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.*?)processed-schematic-end') + pattern.md = md + pattern.ext = self + md.inlinePatterns.add('circuit', pattern, ".*)$') + + 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("") + return etree.fromstring("") def makeExtension(configs=None) : diff --git a/djangoapps/simplewiki/models.py b/djangoapps/simplewiki/models.py index 33c9b0403e..71a57c601c 100644 --- a/djangoapps/simplewiki/models.py +++ b/djangoapps/simplewiki/models.py @@ -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',) diff --git a/static/js/CodeMirror/codemirror.js b/static/js/CodeMirror/codemirror.js index ed92bc8378..c840de05b7 100644 --- a/static/js/CodeMirror/codemirror.js +++ b/static/js/CodeMirror/codemirror.js @@ -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) { diff --git a/static/js/CodeMirror/mitx_markdown.js b/static/js/CodeMirror/mitx_markdown.js index 9b95d96d19..9991a4f05c 100644 --- a/static/js/CodeMirror/mitx_markdown.js +++ b/static/js/CodeMirror/mitx_markdown.js @@ -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(); } }; diff --git a/templates/simplewiki_edit.html b/templates/simplewiki_edit.html index 75e1fec325..85059a1766 100644 --- a/templates/simplewiki_edit.html +++ b/templates/simplewiki_edit.html @@ -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