Commit 3dee5442 by Bridger Maxwell

More comments on mdx_circuit.py. Incorporated some pull request feedback.

parent d390e998
......@@ -3,7 +3,16 @@
Image Circuit Extension for Python-Markdown
======================================
circuit:name becomes the circuit.
Any single line beginning with circuit-schematic: and followed by data (which should be json data, but this
is not enforced at this level) will be displayed as a circuit schematic. This is simply an input element with
the value set to the data. It is left to javascript on the page to render that input as a circuit schematic.
ex:
circuit-schematic:[["r",[128,48,0],{"r":"1","_json_":0},["2","1"]],["view",0,0,2,null,null,null,null,null,null,null],["dc",{"0":0,"1":1,"I(_3)":-1}]]
(This is a schematic with a single one-ohm resistor. Note that this data is not meant to be user-editable.)
'''
import markdown
import re
......@@ -11,8 +20,6 @@ import re
import simplewiki.settings as settings
from django.utils.html import escape
from mitxmako.shortcuts import render_to_response, render_to_string
try:
# Markdown 2.1.0 changed from 2.0.3. We try importing the new version first,
......@@ -44,21 +51,29 @@ 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
def convertLine(line):
m = self.preRegex.match(line)
if m:
return 'processed-schematic:{0}processed-schematic-end'.format( m.group('data') )
else:
return line
return [ convertLine(line) for line in lines ]
new_lines = []
for line in lines:
m = self.preRegex.match(line)
if m:
new_lines.append()
else:
new_lines.append(line)
return new_lines
class CircuitLink(markdown.inlinepatterns.Pattern):
def handleMatch(self, m):
data = m.group('data')
data = escape(data)
##TODO: We need to html escape the data
return etree.fromstring("<div align='center'><input type='hidden' parts='' value='" + data + "' analyses='' class='schematic ctrls' width='500' height='300'/></div>")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment