Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
3dee5442
Commit
3dee5442
authored
Apr 01, 2012
by
Bridger Maxwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More comments on mdx_circuit.py. Incorporated some pull request feedback.
parent
d390e998
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
12 deletions
+27
-12
djangoapps/simplewiki/mdx_circuit.py
+27
-12
No files found.
djangoapps/simplewiki/mdx_circuit.py
View file @
3dee5442
...
...
@@ -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>"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment