Commit 238ed768 by Bridger Maxwell

The new markdown framework version was not backwards compatible. Now the wiki…

The new markdown framework version was not backwards compatible. Now the wiki source can use either version of the API.
parent e4831106
...@@ -69,6 +69,13 @@ Dependencies: ...@@ -69,6 +69,13 @@ Dependencies:
''' '''
import 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 CamelCaseExtension(markdown.Extension): class CamelCaseExtension(markdown.Extension):
def __init__(self, configs): def __init__(self, configs):
...@@ -97,14 +104,14 @@ class CamelCaseExtension(markdown.Extension): ...@@ -97,14 +104,14 @@ class CamelCaseExtension(markdown.Extension):
class CamelCaseLinks(markdown.inlinepatterns.Pattern): class CamelCaseLinks(markdown.inlinepatterns.Pattern):
def handleMatch(self, m) : def handleMatch(self, m) :
if m.group('escape') == '\\': if m.group('escape') == '\\':
a = markdown.etree.Element('a')#doc.createTextNode(m.group('camelcase')) a = etree.Element('a')#doc.createTextNode(m.group('camelcase'))
else : else :
url = m.group('camelcase') url = m.group('camelcase')
#'%s%s%s'% (self.md.wiki_config['base_url'][0], \ #'%s%s%s'% (self.md.wiki_config['base_url'][0], \
#m.group('camelcase'), \ #m.group('camelcase'), \
#self.md.wiki_config['end_url'][0]) #self.md.wiki_config['end_url'][0])
label = m.group('camelcase').replace('_', ' ') label = m.group('camelcase').replace('_', ' ')
a = markdown.etree.Element('a') a = etree.Element('a')
a.set('href', url) a.set('href', url)
a.text = label a.text = label
a.set('class', 'wikilink') a.set('class', 'wikilink')
......
...@@ -7,12 +7,16 @@ circuit:name becomes the circuit. ...@@ -7,12 +7,16 @@ circuit:name becomes the circuit.
''' '''
import simplewiki.settings as settings import simplewiki.settings as settings
import markdown
from markdown import etree_loader
from djangomako.shortcuts import render_to_response, render_to_string from djangomako.shortcuts import render_to_response, render_to_string
ElementTree=etree_loader.importETree() 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 CircuitExtension(markdown.Extension): class CircuitExtension(markdown.Extension):
def __init__(self, configs): def __init__(self, configs):
...@@ -33,9 +37,9 @@ class CircuitLink(markdown.inlinepatterns.Pattern): ...@@ -33,9 +37,9 @@ class CircuitLink(markdown.inlinepatterns.Pattern):
def handleMatch(self, m): def handleMatch(self, m):
name = m.group('name') name = m.group('name')
if not name.isalnum(): if not name.isalnum():
return ElementTree.fromstring("<div>Circuit name must be alphanumeric</div>") return etree.fromstring("<div>Circuit name must be alphanumeric</div>")
return ElementTree.fromstring(render_to_string('show_circuit.html', {'name':name})) return etree.fromstring(render_to_string('show_circuit.html', {'name':name}))
def makeExtension(configs=None) : def makeExtension(configs=None) :
......
...@@ -16,7 +16,15 @@ Requires Python-Markdown 1.6+ ...@@ -16,7 +16,15 @@ Requires Python-Markdown 1.6+
''' '''
import simplewiki.settings as settings import simplewiki.settings as settings
import 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 ImageExtension(markdown.Extension): class ImageExtension(markdown.Extension):
def __init__(self, configs): def __init__(self, configs):
...@@ -35,7 +43,7 @@ class ImageExtension(markdown.Extension): ...@@ -35,7 +43,7 @@ class ImageExtension(markdown.Extension):
class ImageLink(markdown.inlinepatterns.Pattern): class ImageLink(markdown.inlinepatterns.Pattern):
def handleMatch(self, m): def handleMatch(self, m):
img = markdown.etree.Element('img') img = etree.Element('img')
proto = m.group('proto') or "http://" proto = m.group('proto') or "http://"
domain = m.group('domain') domain = m.group('domain')
path = m.group('path') path = m.group('path')
......
# Source: https://github.com/mayoff/python-markdown-mathjax # Source: https://github.com/mayoff/python-markdown-mathjax
print "Hello"
import 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, AtomicString
except:
from markdown import etree, AtomicString
class MathJaxPattern(markdown.inlinepatterns.Pattern): class MathJaxPattern(markdown.inlinepatterns.Pattern):
...@@ -10,7 +14,9 @@ class MathJaxPattern(markdown.inlinepatterns.Pattern): ...@@ -10,7 +14,9 @@ class MathJaxPattern(markdown.inlinepatterns.Pattern):
markdown.inlinepatterns.Pattern.__init__(self, r'(?<!\\)(\$\$?)(.+?)\2') markdown.inlinepatterns.Pattern.__init__(self, r'(?<!\\)(\$\$?)(.+?)\2')
def handleMatch(self, m): def handleMatch(self, m):
return markdown.AtomicString(m.group(2) + m.group(3) + m.group(2)) el = etree.Element('span')
el.text = AtomicString(m.group(2) + m.group(3) + m.group(2))
return el
class MathJaxExtension(markdown.Extension): class MathJaxExtension(markdown.Extension):
def extendMarkdown(self, md, md_globals): def extendMarkdown(self, md, md_globals):
......
...@@ -128,6 +128,13 @@ u'<p><object data="http://www.gametrailers.com/remote_wrap.php?mid=58079" height ...@@ -128,6 +128,13 @@ u'<p><object data="http://www.gametrailers.com/remote_wrap.php?mid=58079" height
""" """
import 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
version = "0.1.6" version = "0.1.6"
...@@ -229,7 +236,7 @@ class Yahoo(markdown.inlinepatterns.Pattern): ...@@ -229,7 +236,7 @@ class Yahoo(markdown.inlinepatterns.Pattern):
width = self.ext.config['yahoo_width'][0] width = self.ext.config['yahoo_width'][0]
height = self.ext.config['yahoo_height'][0] height = self.ext.config['yahoo_height'][0]
obj = flash_object(url, width, height) obj = flash_object(url, width, height)
param = markdown.etree.Element('param') param = etree.Element('param')
param.set('name', 'flashVars') param.set('name', 'flashVars')
param.set('value', "id=%s&vid=%s" % (m.group('yahooid'), param.set('value', "id=%s&vid=%s" % (m.group('yahooid'),
m.group('yahoovid'))) m.group('yahoovid')))
...@@ -244,20 +251,20 @@ class Youtube(markdown.inlinepatterns.Pattern): ...@@ -244,20 +251,20 @@ class Youtube(markdown.inlinepatterns.Pattern):
return flash_object(url, width, height) return flash_object(url, width, height)
def flash_object(url, width, height): def flash_object(url, width, height):
obj = markdown.etree.Element('object') obj = etree.Element('object')
obj.set('type', 'application/x-shockwave-flash') obj.set('type', 'application/x-shockwave-flash')
obj.set('width', width) obj.set('width', width)
obj.set('height', height) obj.set('height', height)
obj.set('data', url) obj.set('data', url)
param = markdown.etree.Element('param') param = etree.Element('param')
param.set('name', 'movie') param.set('name', 'movie')
param.set('value', url) param.set('value', url)
obj.append(param) obj.append(param)
param = markdown.etree.Element('param') param = etree.Element('param')
param.set('name', 'allowFullScreen') param.set('name', 'allowFullScreen')
param.set('value', 'true') param.set('value', 'true')
obj.append(param) obj.append(param)
#param = markdown.etree.Element('param') #param = etree.Element('param')
#param.set('name', 'allowScriptAccess') #param.set('name', 'allowScriptAccess')
#param.set('value', 'sameDomain') #param.set('value', 'sameDomain')
#obj.append(param) #obj.append(param)
......
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