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
93d15d15
Commit
93d15d15
authored
Aug 17, 2012
by
Bridger Maxwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added markdown extensions from 6.002x
parent
e47f3ccf
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
584 additions
and
0 deletions
+584
-0
lms/djangoapps/course_wiki/plugins/__init__.py
+0
-0
lms/djangoapps/course_wiki/plugins/markdownedx/__init__.py
+3
-0
lms/djangoapps/course_wiki/plugins/markdownedx/mdx_circuit.py
+73
-0
lms/djangoapps/course_wiki/plugins/markdownedx/mdx_image.py
+71
-0
lms/djangoapps/course_wiki/plugins/markdownedx/mdx_mathjax.py
+31
-0
lms/djangoapps/course_wiki/plugins/markdownedx/mdx_video.py
+289
-0
lms/djangoapps/course_wiki/plugins/markdownedx/mdx_wikipath.py
+92
-0
lms/djangoapps/course_wiki/plugins/markdownedx/wiki_plugin.py
+24
-0
lms/envs/common.py
+1
-0
No files found.
lms/djangoapps/course_wiki/plugins/__init__.py
0 → 100644
View file @
93d15d15
lms/djangoapps/course_wiki/plugins/markdownedx/__init__.py
0 → 100644
View file @
93d15d15
# Make sure wiki_plugin.py gets run.
from
course_wiki.plugins.markdownedx.wiki_plugin
import
ExtendMarkdownPlugin
\ No newline at end of file
lms/djangoapps/course_wiki/plugins/markdownedx/mdx_circuit.py
0 → 100755
View file @
93d15d15
#!/usr/bin/env python
'''
Image Circuit Extension for Python-Markdown
======================================
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
from
django.utils.html
import
escape
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
from
markdown.util
import
etree
except
:
from
markdown
import
etree
class
CircuitExtension
(
markdown
.
Extension
):
def
__init__
(
self
,
configs
):
for
key
,
value
in
configs
:
self
.
setConfig
(
key
,
value
)
def
extendMarkdown
(
self
,
md
,
md_globals
):
## 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
):
print
"running circuit preprocessor"
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
]
class
CircuitLink
(
markdown
.
inlinepatterns
.
Pattern
):
def
handleMatch
(
self
,
m
):
data
=
m
.
group
(
'data'
)
data
=
escape
(
data
)
return
etree
.
fromstring
(
"<div align='center'><input type='hidden' parts='' value='"
+
data
+
"' analyses='' class='schematic ctrls' width='400' height='220'/></div>"
)
def
makeExtension
(
configs
=
None
):
to_return
=
CircuitExtension
(
configs
=
configs
)
print
"circuit returning "
,
to_return
return
to_return
lms/djangoapps/course_wiki/plugins/markdownedx/mdx_image.py
0 → 100755
View file @
93d15d15
#!/usr/bin/env python
'''
Image Embedding Extension for Python-Markdown
======================================
Converts lone links to embedded images, provided the file extension is allowed.
Ex:
http://www.ericfehse.net/media/img/ef/blog/django-pony.jpg
becomes
<img src="http://www.ericfehse.net/media/img/ef/blog/django-pony.jpg">
mypic.jpg becomes <img src="/MEDIA_PATH/mypic.jpg">
Requires Python-Markdown 1.6+
'''
import
simplewiki.settings
as
settings
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
from
markdown.util
import
etree
except
:
from
markdown
import
etree
class
ImageExtension
(
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
,
'image'
,
ImageLink
,
r'^(?P<proto>([^:/?#])+://)?(?P<domain>([^/?#]*)/)?(?P<path>[^?#]*\.(?P<ext>[^?#]{3,4}))(?:\?([^#]*))?(?:#(.*))?$'
)
class
ImageLink
(
markdown
.
inlinepatterns
.
Pattern
):
def
handleMatch
(
self
,
m
):
img
=
etree
.
Element
(
'img'
)
proto
=
m
.
group
(
'proto'
)
or
"http://"
domain
=
m
.
group
(
'domain'
)
path
=
m
.
group
(
'path'
)
ext
=
m
.
group
(
'ext'
)
# A fixer upper
if
ext
.
lower
()
in
settings
.
WIKI_IMAGE_EXTENSIONS
:
if
domain
:
src
=
proto
+
domain
+
path
elif
path
:
# We need a nice way to source local attachments...
src
=
"/wiki/media/"
+
path
+
".upload"
else
:
src
=
''
img
.
set
(
'src'
,
src
)
return
img
def
makeExtension
(
configs
=
None
):
return
ImageExtension
(
configs
=
configs
)
if
__name__
==
"__main__"
:
import
doctest
doctest
.
testmod
()
lms/djangoapps/course_wiki/plugins/markdownedx/mdx_mathjax.py
0 → 100644
View file @
93d15d15
# Source: https://github.com/mayoff/python-markdown-mathjax
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
from
markdown.util
import
etree
,
AtomicString
except
:
from
markdown
import
etree
,
AtomicString
class
MathJaxPattern
(
markdown
.
inlinepatterns
.
Pattern
):
def
__init__
(
self
):
markdown
.
inlinepatterns
.
Pattern
.
__init__
(
self
,
r'(?<!\\)(\$\$?)(.+?)\2'
)
def
handleMatch
(
self
,
m
):
el
=
etree
.
Element
(
'span'
)
el
.
text
=
AtomicString
(
m
.
group
(
2
)
+
m
.
group
(
3
)
+
m
.
group
(
2
))
return
el
class
MathJaxExtension
(
markdown
.
Extension
):
def
extendMarkdown
(
self
,
md
,
md_globals
):
# Needs to come before escape matching because \ is pretty important in LaTeX
md
.
inlinePatterns
.
add
(
'mathjax'
,
MathJaxPattern
(),
'<escape'
)
def
makeExtension
(
configs
=
None
):
return
MathJaxExtension
(
configs
)
lms/djangoapps/course_wiki/plugins/markdownedx/mdx_video.py
0 → 100755
View file @
93d15d15
#!/usr/bin/env python
"""
Embeds web videos using URLs. For instance, if a URL to an youtube video is
found in the text submitted to markdown and it isn't enclosed in parenthesis
like a normal link in markdown, then the URL will be swapped with a embedded
youtube video.
All resulting HTML is XHTML Strict compatible.
>>> import markdown
Test Metacafe
>>> s = "http://www.metacafe.com/watch/yt-tZMsrrQCnx8/pycon_2008_django_sprint_room/"
>>> markdown.markdown(s, ['video'])
u'<p><object data="http://www.metacafe.com/fplayer/yt-tZMsrrQCnx8/pycon_2008_django_sprint_room.swf" height="423" type="application/x-shockwave-flash" width="498"><param name="movie" value="http://www.metacafe.com/fplayer/yt-tZMsrrQCnx8/pycon_2008_django_sprint_room.swf" /><param name="allowFullScreen" value="true" /></object></p>'
Test Metacafe with arguments
>>> markdown.markdown(s, ['video(metacafe_width=500,metacafe_height=425)'])
u'<p><object data="http://www.metacafe.com/fplayer/yt-tZMsrrQCnx8/pycon_2008_django_sprint_room.swf" height="425" type="application/x-shockwave-flash" width="500"><param name="movie" value="http://www.metacafe.com/fplayer/yt-tZMsrrQCnx8/pycon_2008_django_sprint_room.swf" /><param name="allowFullScreen" value="true" /></object></p>'
Test Link To Metacafe
>>> s = "[Metacafe link](http://www.metacafe.com/watch/yt-tZMsrrQCnx8/pycon_2008_django_sprint_room/)"
>>> markdown.markdown(s, ['video'])
u'<p><a href="http://www.metacafe.com/watch/yt-tZMsrrQCnx8/pycon_2008_django_sprint_room/">Metacafe link</a></p>'
Test Markdown Escaping
>>> s = "
\\
http://www.metacafe.com/watch/yt-tZMsrrQCnx8/pycon_2008_django_sprint_room/"
>>> markdown.markdown(s, ['video'])
u'<p>http://www.metacafe.com/watch/yt-tZMsrrQCnx8/pycon_2008_django_sprint_room/</p>'
>>> s = "`http://www.metacafe.com/watch/yt-tZMsrrQCnx8/pycon_2008_django_sprint_room/`"
>>> markdown.markdown(s, ['video'])
u'<p><code>http://www.metacafe.com/watch/yt-tZMsrrQCnx8/pycon_2008_django_sprint_room/</code></p>'
Test Youtube
>>> s = "http://www.youtube.com/watch?v=u1mA-0w8XPo&hd=1&fs=1&feature=PlayList&p=34C6046F7FEACFD3&playnext=1&playnext_from=PL&index=1"
>>> markdown.markdown(s, ['video'])
u'<p><object data="http://www.youtube.com/v/u1mA-0w8XPo&hd=1&fs=1&feature=PlayList&p=34C6046F7FEACFD3&playnext=1&playnext_from=PL&index=1" height="344" type="application/x-shockwave-flash" width="425"><param name="movie" value="http://www.youtube.com/v/u1mA-0w8XPo&hd=1&fs=1&feature=PlayList&p=34C6046F7FEACFD3&playnext=1&playnext_from=PL&index=1" /><param name="allowFullScreen" value="true" /></object></p>'
Test Youtube with argument
>>> markdown.markdown(s, ['video(youtube_width=200,youtube_height=100)'])
u'<p><object data="http://www.youtube.com/v/u1mA-0w8XPo&hd=1&fs=1&feature=PlayList&p=34C6046F7FEACFD3&playnext=1&playnext_from=PL&index=1" height="100" type="application/x-shockwave-flash" width="200"><param name="movie" value="http://www.youtube.com/v/u1mA-0w8XPo&hd=1&fs=1&feature=PlayList&p=34C6046F7FEACFD3&playnext=1&playnext_from=PL&index=1" /><param name="allowFullScreen" value="true" /></object></p>'
Test Youtube Link
>>> s = "[Youtube link](http://www.youtube.com/watch?v=u1mA-0w8XPo&feature=PlayList&p=34C6046F7FEACFD3&playnext=1&playnext_from=PL&index=1)"
>>> markdown.markdown(s, ['video'])
u'<p><a href="http://www.youtube.com/watch?v=u1mA-0w8XPo&feature=PlayList&p=34C6046F7FEACFD3&playnext=1&playnext_from=PL&index=1">Youtube link</a></p>'
Test Dailymotion
>>> s = "http://www.dailymotion.com/relevance/search/ut2004/video/x3kv65_ut2004-ownage_videogames"
>>> markdown.markdown(s, ['video'])
u'<p><object data="http://www.dailymotion.com/swf/x3kv65_ut2004-ownage_videogames" height="405" type="application/x-shockwave-flash" width="480"><param name="movie" value="http://www.dailymotion.com/swf/x3kv65_ut2004-ownage_videogames" /><param name="allowFullScreen" value="true" /></object></p>'
Test Dailymotion again (Dailymotion and their crazy URLs)
>>> s = "http://www.dailymotion.com/us/video/x8qak3_iron-man-vs-bruce-lee_fun"
>>> markdown.markdown(s, ['video'])
u'<p><object data="http://www.dailymotion.com/swf/x8qak3_iron-man-vs-bruce-lee_fun" height="405" type="application/x-shockwave-flash" width="480"><param name="movie" value="http://www.dailymotion.com/swf/x8qak3_iron-man-vs-bruce-lee_fun" /><param name="allowFullScreen" value="true" /></object></p>'
Test Yahoo! Video
>>> s = "http://video.yahoo.com/watch/1981791/4769603"
>>> markdown.markdown(s, ['video'])
u'<p><object data="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.40" height="322" type="application/x-shockwave-flash" width="512"><param name="movie" value="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.40" /><param name="allowFullScreen" value="true" /><param name="flashVars" value="id=4769603&vid=1981791" /></object></p>'
Test Veoh Video
>>> s = "http://www.veoh.com/search/videos/q/mario#watch
%3
De129555XxCZanYD"
>>> markdown.markdown(s, ['video'])
u'<p><object data="http://www.veoh.com/videodetails2.swf?permalinkId=e129555XxCZanYD" height="341" type="application/x-shockwave-flash" width="410"><param name="movie" value="http://www.veoh.com/videodetails2.swf?permalinkId=e129555XxCZanYD" /><param name="allowFullScreen" value="true" /></object></p>'
Test Veoh Video Again (More fun URLs)
>>> s = "http://www.veoh.com/group/BigCatRescuers#watch
%3
Dv16771056hFtSBYEr"
>>> markdown.markdown(s, ['video'])
u'<p><object data="http://www.veoh.com/videodetails2.swf?permalinkId=v16771056hFtSBYEr" height="341" type="application/x-shockwave-flash" width="410"><param name="movie" value="http://www.veoh.com/videodetails2.swf?permalinkId=v16771056hFtSBYEr" /><param name="allowFullScreen" value="true" /></object></p>'
Test Veoh Video Yet Again (Even more fun URLs)
>>> s = "http://www.veoh.com/browse/videos/category/anime/watch/v181645607JyXPWcQ"
>>> markdown.markdown(s, ['video'])
u'<p><object data="http://www.veoh.com/videodetails2.swf?permalinkId=v181645607JyXPWcQ" height="341" type="application/x-shockwave-flash" width="410"><param name="movie" value="http://www.veoh.com/videodetails2.swf?permalinkId=v181645607JyXPWcQ" /><param name="allowFullScreen" value="true" /></object></p>'
Test Vimeo Video
>>> s = "http://www.vimeo.com/1496152"
>>> markdown.markdown(s, ['video'])
u'<p><object data="http://vimeo.com/moogaloop.swf?clip_id=1496152&amp;server=vimeo.com" height="321" type="application/x-shockwave-flash" width="400"><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=1496152&amp;server=vimeo.com" /><param name="allowFullScreen" value="true" /></object></p>'
Test Vimeo Video with some GET values
>>> s = "http://vimeo.com/1496152?test=test"
>>> markdown.markdown(s, ['video'])
u'<p><object data="http://vimeo.com/moogaloop.swf?clip_id=1496152&amp;server=vimeo.com" height="321" type="application/x-shockwave-flash" width="400"><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=1496152&amp;server=vimeo.com" /><param name="allowFullScreen" value="true" /></object></p>'
Test Blip.tv
>>> s = "http://blip.tv/file/get/Pycon-PlenarySprintIntro563.flv"
>>> markdown.markdown(s, ['video'])
u'<p><object data="http://blip.tv/scripts/flash/showplayer.swf?file=http://blip.tv/file/get/Pycon-PlenarySprintIntro563.flv" height="300" type="application/x-shockwave-flash" width="480"><param name="movie" value="http://blip.tv/scripts/flash/showplayer.swf?file=http://blip.tv/file/get/Pycon-PlenarySprintIntro563.flv" /><param name="allowFullScreen" value="true" /></object></p>'
Test Gametrailers
>>> s = "http://www.gametrailers.com/video/console-comparison-borderlands/58079"
>>> markdown.markdown(s, ['video'])
u'<p><object data="http://www.gametrailers.com/remote_wrap.php?mid=58079" height="392" type="application/x-shockwave-flash" width="480"><param name="movie" value="http://www.gametrailers.com/remote_wrap.php?mid=58079" /><param name="allowFullScreen" value="true" /></object></p>'
"""
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
from
markdown.util
import
etree
except
:
from
markdown
import
etree
version
=
"0.1.6"
class
VideoExtension
(
markdown
.
Extension
):
def
__init__
(
self
,
configs
):
self
.
config
=
{
'bliptv_width'
:
[
'480'
,
'Width for Blip.tv videos'
],
'bliptv_height'
:
[
'300'
,
'Height for Blip.tv videos'
],
'dailymotion_width'
:
[
'480'
,
'Width for Dailymotion videos'
],
'dailymotion_height'
:
[
'405'
,
'Height for Dailymotion videos'
],
'gametrailers_width'
:
[
'480'
,
'Width for Gametrailers videos'
],
'gametrailers_height'
:
[
'392'
,
'Height for Gametrailers videos'
],
'metacafe_width'
:
[
'498'
,
'Width for Metacafe videos'
],
'metacafe_height'
:
[
'423'
,
'Height for Metacafe videos'
],
'veoh_width'
:
[
'410'
,
'Width for Veoh videos'
],
'veoh_height'
:
[
'341'
,
'Height for Veoh videos'
],
'vimeo_width'
:
[
'400'
,
'Width for Vimeo videos'
],
'vimeo_height'
:
[
'321'
,
'Height for Vimeo videos'
],
'yahoo_width'
:
[
'512'
,
'Width for Yahoo! videos'
],
'yahoo_height'
:
[
'322'
,
'Height for Yahoo! videos'
],
'youtube_width'
:
[
'425'
,
'Width for Youtube videos'
],
'youtube_height'
:
[
'344'
,
'Height for Youtube videos'
],
}
# Override defaults with user settings
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
,
'bliptv'
,
Bliptv
,
r'([^(]|^)http://(\w+\.|)blip.tv/file/get/(?P<bliptvfile>\S+.flv)'
)
self
.
add_inline
(
md
,
'dailymotion'
,
Dailymotion
,
r'([^(]|^)http://www\.dailymotion\.com/(?P<dailymotionid>\S+)'
)
self
.
add_inline
(
md
,
'gametrailers'
,
Gametrailers
,
r'([^(]|^)http://www.gametrailers.com/video/[a-z0-9-]+/(?P<gametrailersid>\d+)'
)
self
.
add_inline
(
md
,
'metacafe'
,
Metacafe
,
r'([^(]|^)http://www\.metacafe\.com/watch/(?P<metacafeid>\S+)/'
)
self
.
add_inline
(
md
,
'veoh'
,
Veoh
,
r'([^(]|^)http://www\.veoh\.com/\S*(#watch
%3
D|watch/)(?P<veohid>\w+)'
)
self
.
add_inline
(
md
,
'vimeo'
,
Vimeo
,
r'([^(]|^)http://(www.|)vimeo\.com/(?P<vimeoid>\d+)\S*'
)
self
.
add_inline
(
md
,
'yahoo'
,
Yahoo
,
r'([^(]|^)http://video\.yahoo\.com/watch/(?P<yahoovid>\d+)/(?P<yahooid>\d+)'
)
self
.
add_inline
(
md
,
'youtube'
,
Youtube
,
r'([^(]|^)http://www\.youtube\.com/watch\?\S*v=(?P<youtubeargs>[A-Za-z0-9_&=-]+)\S*'
)
class
Bliptv
(
markdown
.
inlinepatterns
.
Pattern
):
def
handleMatch
(
self
,
m
):
url
=
'http://blip.tv/scripts/flash/showplayer.swf?file=http://blip.tv/file/get/
%
s'
%
m
.
group
(
'bliptvfile'
)
width
=
self
.
ext
.
config
[
'bliptv_width'
][
0
]
height
=
self
.
ext
.
config
[
'bliptv_height'
][
0
]
return
flash_object
(
url
,
width
,
height
)
class
Dailymotion
(
markdown
.
inlinepatterns
.
Pattern
):
def
handleMatch
(
self
,
m
):
url
=
'http://www.dailymotion.com/swf/
%
s'
%
m
.
group
(
'dailymotionid'
)
.
split
(
'/'
)[
-
1
]
width
=
self
.
ext
.
config
[
'dailymotion_width'
][
0
]
height
=
self
.
ext
.
config
[
'dailymotion_height'
][
0
]
return
flash_object
(
url
,
width
,
height
)
class
Gametrailers
(
markdown
.
inlinepatterns
.
Pattern
):
def
handleMatch
(
self
,
m
):
url
=
'http://www.gametrailers.com/remote_wrap.php?mid=
%
s'
%
\
m
.
group
(
'gametrailersid'
)
.
split
(
'/'
)[
-
1
]
width
=
self
.
ext
.
config
[
'gametrailers_width'
][
0
]
height
=
self
.
ext
.
config
[
'gametrailers_height'
][
0
]
return
flash_object
(
url
,
width
,
height
)
class
Metacafe
(
markdown
.
inlinepatterns
.
Pattern
):
def
handleMatch
(
self
,
m
):
url
=
'http://www.metacafe.com/fplayer/
%
s.swf'
%
m
.
group
(
'metacafeid'
)
width
=
self
.
ext
.
config
[
'metacafe_width'
][
0
]
height
=
self
.
ext
.
config
[
'metacafe_height'
][
0
]
return
flash_object
(
url
,
width
,
height
)
class
Veoh
(
markdown
.
inlinepatterns
.
Pattern
):
def
handleMatch
(
self
,
m
):
url
=
'http://www.veoh.com/videodetails2.swf?permalinkId=
%
s'
%
m
.
group
(
'veohid'
)
width
=
self
.
ext
.
config
[
'veoh_width'
][
0
]
height
=
self
.
ext
.
config
[
'veoh_height'
][
0
]
return
flash_object
(
url
,
width
,
height
)
class
Vimeo
(
markdown
.
inlinepatterns
.
Pattern
):
def
handleMatch
(
self
,
m
):
url
=
'http://vimeo.com/moogaloop.swf?clip_id=
%
s&server=vimeo.com'
%
m
.
group
(
'vimeoid'
)
width
=
self
.
ext
.
config
[
'vimeo_width'
][
0
]
height
=
self
.
ext
.
config
[
'vimeo_height'
][
0
]
return
flash_object
(
url
,
width
,
height
)
class
Yahoo
(
markdown
.
inlinepatterns
.
Pattern
):
def
handleMatch
(
self
,
m
):
url
=
"http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.40"
width
=
self
.
ext
.
config
[
'yahoo_width'
][
0
]
height
=
self
.
ext
.
config
[
'yahoo_height'
][
0
]
obj
=
flash_object
(
url
,
width
,
height
)
param
=
etree
.
Element
(
'param'
)
param
.
set
(
'name'
,
'flashVars'
)
param
.
set
(
'value'
,
"id=
%
s&vid=
%
s"
%
(
m
.
group
(
'yahooid'
),
m
.
group
(
'yahoovid'
)))
obj
.
append
(
param
)
return
obj
class
Youtube
(
markdown
.
inlinepatterns
.
Pattern
):
def
handleMatch
(
self
,
m
):
url
=
'http://www.youtube.com/v/
%
s'
%
m
.
group
(
'youtubeargs'
)
width
=
self
.
ext
.
config
[
'youtube_width'
][
0
]
height
=
self
.
ext
.
config
[
'youtube_height'
][
0
]
return
flash_object
(
url
,
width
,
height
)
def
flash_object
(
url
,
width
,
height
):
obj
=
etree
.
Element
(
'object'
)
obj
.
set
(
'type'
,
'application/x-shockwave-flash'
)
obj
.
set
(
'width'
,
width
)
obj
.
set
(
'height'
,
height
)
obj
.
set
(
'data'
,
url
)
param
=
etree
.
Element
(
'param'
)
param
.
set
(
'name'
,
'movie'
)
param
.
set
(
'value'
,
url
)
obj
.
append
(
param
)
param
=
etree
.
Element
(
'param'
)
param
.
set
(
'name'
,
'allowFullScreen'
)
param
.
set
(
'value'
,
'true'
)
obj
.
append
(
param
)
#param = etree.Element('param')
#param.set('name', 'allowScriptAccess')
#param.set('value', 'sameDomain')
#obj.append(param)
return
obj
def
makeExtension
(
configs
=
None
):
return
VideoExtension
(
configs
=
configs
)
if
__name__
==
"__main__"
:
import
doctest
doctest
.
testmod
()
lms/djangoapps/course_wiki/plugins/markdownedx/mdx_wikipath.py
0 → 100755
View file @
93d15d15
#!/usr/bin/env python
'''
Wikipath Extension for Python-Markdown
======================================
Converts [Link Name](wiki:ArticleName) to relative links pointing to article. Requires Python-Markdown 2.0+
Basic usage:
>>> import markdown
>>> text = "Some text with a [Link Name](wiki:ArticleName)."
>>> html = markdown.markdown(text, ['wikipath(base_url="/wiki/view/")'])
>>> html
u'<p>Some text with a <a class="wikipath" href="/wiki/view/ArticleName/">Link Name</a>.</p>'
Dependencies:
* [Python 2.3+](http://python.org)
* [Markdown 2.0+](http://www.freewisdom.org/projects/python-markdown/)
'''
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
from
markdown.util
import
etree
except
:
from
markdown
import
etree
class
WikiPathExtension
(
markdown
.
Extension
):
def
__init__
(
self
,
configs
):
# set extension defaults
self
.
config
=
{
'base_url'
:
[
'/'
,
'String to append to beginning of URL.'
],
'html_class'
:
[
'wikipath'
,
'CSS hook. Leave blank for none.'
]
}
# Override defaults with user settings
for
key
,
value
in
configs
:
# self.config[key][0] = value
self
.
setConfig
(
key
,
value
)
def
extendMarkdown
(
self
,
md
,
md_globals
):
self
.
md
=
md
# append to end of inline patterns
WIKI_RE
=
r'\[(?P<linkTitle>.+?)\]\(wiki:(?P<wikiTitle>[a-zA-Z\d/_-]*)\)'
wikiPathPattern
=
WikiPath
(
WIKI_RE
,
self
.
config
)
wikiPathPattern
.
md
=
md
md
.
inlinePatterns
.
add
(
'wikipath'
,
wikiPathPattern
,
"<reference"
)
class
WikiPath
(
markdown
.
inlinepatterns
.
Pattern
):
def
__init__
(
self
,
pattern
,
config
):
markdown
.
inlinepatterns
.
Pattern
.
__init__
(
self
,
pattern
)
self
.
config
=
config
def
handleMatch
(
self
,
m
)
:
article_title
=
m
.
group
(
'wikiTitle'
)
if
article_title
.
startswith
(
"/"
):
article_title
=
article_title
[
1
:]
url
=
self
.
config
[
'base_url'
][
0
]
+
article_title
label
=
m
.
group
(
'linkTitle'
)
a
=
etree
.
Element
(
'a'
)
a
.
set
(
'href'
,
url
)
a
.
text
=
label
if
self
.
config
[
'html_class'
][
0
]:
a
.
set
(
'class'
,
self
.
config
[
'html_class'
][
0
])
return
a
def
_getMeta
(
self
):
""" Return meta data or config data. """
base_url
=
self
.
config
[
'base_url'
][
0
]
html_class
=
self
.
config
[
'html_class'
][
0
]
if
hasattr
(
self
.
md
,
'Meta'
):
if
self
.
md
.
Meta
.
has_key
(
'wiki_base_url'
):
base_url
=
self
.
md
.
Meta
[
'wiki_base_url'
][
0
]
if
self
.
md
.
Meta
.
has_key
(
'wiki_html_class'
):
html_class
=
self
.
md
.
Meta
[
'wiki_html_class'
][
0
]
return
base_url
,
html_class
def
makeExtension
(
configs
=
None
)
:
return
WikiPathExtension
(
configs
=
configs
)
if
__name__
==
"__main__"
:
import
doctest
doctest
.
testmod
()
lms/djangoapps/course_wiki/plugins/markdownedx/wiki_plugin.py
0 → 100644
View file @
93d15d15
# -*- coding: utf-8 -*-
from
django.core.urlresolvers
import
reverse
from
wiki.core
import
plugins_registry
from
wiki
import
plugins
from
course_wiki.plugins.markdownedx
import
mdx_circuit
,
mdx_wikipath
,
mdx_mathjax
,
mdx_video
class
ExtendMarkdownPlugin
(
plugins
.
BasePlugin
):
"""
This plugin simply loads all of the markdown extensions we use in edX.
"""
wiki_base_url
=
reverse
(
"wiki:get"
,
kwargs
=
{
'path'
:
""
})
markdown_extensions
=
[
mdx_circuit
.
CircuitExtension
(
configs
=
{}),
#mdx_image.ImageExtension() , #This one doesn't work. Tries to import simplewiki.settings
mdx_wikipath
.
WikiPathExtension
(
configs
=
{
'base_url'
:
wiki_base_url
}
.
iteritems
()
)
,
mdx_mathjax
.
MathJaxExtension
(
configs
=
{})
,
mdx_video
.
VideoExtension
(
configs
=
{})]
plugins_registry
.
register
(
ExtendMarkdownPlugin
)
lms/envs/common.py
View file @
93d15d15
...
...
@@ -561,6 +561,7 @@ INSTALLED_APPS = (
'sekizai'
,
'wiki.plugins.attachments'
,
'wiki.plugins.notifications'
,
'course_wiki.plugins.markdownedx'
,
# For testing
'django_jasmine'
,
...
...
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