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
f95aa496
Commit
f95aa496
authored
Mar 28, 2012
by
Bridger Maxwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better compatibility with the Codemirror editor and the markdown circuit extension.
parent
99b8a511
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
11 deletions
+32
-11
djangoapps/simplewiki/mdx_circuit.py
+28
-8
djangoapps/simplewiki/models.py
+0
-1
static/js/CodeMirror/codemirror.js
+1
-1
static/js/CodeMirror/mitx_markdown.js
+2
-0
templates/simplewiki_edit.html
+1
-1
No files found.
djangoapps/simplewiki/mdx_circuit.py
View file @
f95aa496
...
@@ -5,12 +5,14 @@ Image Circuit Extension for Python-Markdown
...
@@ -5,12 +5,14 @@ Image Circuit Extension for Python-Markdown
circuit:name becomes the circuit.
circuit:name becomes the circuit.
'''
'''
import
markdown
import
re
import
simplewiki.settings
as
settings
import
simplewiki.settings
as
settings
from
mitxmako.shortcuts
import
render_to_response
,
render_to_string
from
mitxmako.shortcuts
import
render_to_response
,
render_to_string
import
markdown
try
:
try
:
# Markdown 2.1.0 changed from 2.0.3. We try importing the new version first,
# 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
# but import the 2.0.3 version if it fails
...
@@ -22,22 +24,40 @@ class CircuitExtension(markdown.Extension):
...
@@ -22,22 +24,40 @@ class CircuitExtension(markdown.Extension):
def
__init__
(
self
,
configs
):
def
__init__
(
self
,
configs
):
for
key
,
value
in
configs
:
for
key
,
value
in
configs
:
self
.
setConfig
(
key
,
value
)
self
.
setConfig
(
key
,
value
)
def
add_inline
(
self
,
md
,
name
,
klass
,
re
):
def
extendMarkdown
(
self
,
md
,
md_globals
):
pattern
=
klass
(
re
)
## 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
.
md
=
md
pattern
.
ext
=
self
pattern
.
ext
=
self
md
.
inlinePatterns
.
add
(
name
,
pattern
,
"<reference"
)
md
.
inlinePatterns
.
add
(
'circuit'
,
pattern
,
"<reference"
)
class
CircuitPreprocessor
(
markdown
.
preprocessors
.
Preprocessor
):
preRegex
=
re
.
compile
(
r'^circuit-schematic:(?P<data>.*)$'
)
def
extendMarkdown
(
self
,
md
,
md_globals
):
def
run
(
self
,
lines
):
self
.
add_inline
(
md
,
'circuit'
,
CircuitLink
,
r'^circuit-schematic:(?P<data>.*)$'
)
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
):
class
CircuitLink
(
markdown
.
inlinepatterns
.
Pattern
):
def
handleMatch
(
self
,
m
):
def
handleMatch
(
self
,
m
):
data
=
m
.
group
(
'data'
)
data
=
m
.
group
(
'data'
)
##TODO: We need to html escape the 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
)
:
def
makeExtension
(
configs
=
None
)
:
...
...
djangoapps/simplewiki/models.py
View file @
f95aa496
...
@@ -276,7 +276,6 @@ class Revision(models.Model):
...
@@ -276,7 +276,6 @@ class Revision(models.Model):
# Create pre-parsed contents - no need to parse on-the-fly
# Create pre-parsed contents - no need to parse on-the-fly
ext
=
WIKI_MARKDOWN_EXTENSIONS
ext
=
WIKI_MARKDOWN_EXTENSIONS
ext
+=
[
"wikipath(base_url=
%
s)"
%
reverse
(
'wiki_view'
,
args
=
(
'/'
,))]
ext
+=
[
"wikipath(base_url=
%
s)"
%
reverse
(
'wiki_view'
,
args
=
(
'/'
,))]
print
ext
self
.
contents_parsed
=
markdown
(
self
.
contents
,
self
.
contents_parsed
=
markdown
(
self
.
contents
,
extensions
=
ext
,
extensions
=
ext
,
safe_mode
=
'escape'
,)
safe_mode
=
'escape'
,)
...
...
static/js/CodeMirror/codemirror.js
View file @
f95aa496
...
@@ -980,7 +980,7 @@ var CodeMirror = (function() {
...
@@ -980,7 +980,7 @@ var CodeMirror = (function() {
maxWidth
=
scroller
.
clientWidth
;
maxWidth
=
scroller
.
clientWidth
;
var
curNode
=
lineDiv
.
firstChild
,
heightChanged
=
false
;
var
curNode
=
lineDiv
.
firstChild
,
heightChanged
=
false
;
doc
.
iter
(
showingFrom
,
showingTo
,
function
(
line
)
{
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
;
var
height
=
Math
.
round
(
curNode
.
offsetHeight
/
th
)
||
1
;
if
(
line
.
widgetFunction
)
height
=
line
.
widgetFunction
.
size
(
line
.
text
).
height
/
textHeight
();
if
(
line
.
widgetFunction
)
height
=
line
.
widgetFunction
.
size
(
line
.
text
).
height
/
textHeight
();
if
(
line
.
height
!=
height
)
{
if
(
line
.
height
!=
height
)
{
...
...
static/js/CodeMirror/mitx_markdown.js
View file @
f95aa496
...
@@ -77,6 +77,8 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) {
...
@@ -77,6 +77,8 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) {
update_schematics
();
update_schematics
();
var
schmInput
=
node
.
firstChild
;
var
schmInput
=
node
.
firstChild
;
schmInput
.
codeMirrorLine
=
line
;
schmInput
.
codeMirrorLine
=
line
;
schmInput
.
schematic
.
always_draw_grid
=
true
;
schmInput
.
schematic
.
redraw_background
();
$
(
node
).
leanModal
();
$
(
node
).
leanModal
();
}
}
};
};
...
...
templates/simplewiki_edit.html
View file @
f95aa496
...
@@ -39,7 +39,7 @@
...
@@ -39,7 +39,7 @@
mode
:
'mitx_markdown'
,
mode
:
'mitx_markdown'
,
matchBrackets
:
true
,
matchBrackets
:
true
,
theme
:
"default"
,
theme
:
"default"
,
lineWrapping
:
fals
e
,
lineWrapping
:
tru
e
,
});
});
//Store the inital contents so we can compare for unsaved changes
//Store the inital contents so we can compare for unsaved changes
...
...
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