Javascript 自定义数学方程的随钻测量
嗨 我想定制WMD编辑器(or),将$\frac{2}{3}$等TeX方程转换为Google Charts API图像() 是否可以自定义HTML的生成方式 我决定与我编写的扩展一起使用。以下是Google应用程序引擎解析器的代码:Javascript 自定义数学方程的随钻测量,javascript,math,latex,markdown,wmd,Javascript,Math,Latex,Markdown,Wmd,嗨 我想定制WMD编辑器(or),将$\frac{2}{3}$等TeX方程转换为Google Charts API图像() 是否可以自定义HTML的生成方式 我决定与我编写的扩展一起使用。以下是Google应用程序引擎解析器的代码: import markdown from urllib import urlencode from markdown.inlinepatterns import Pattern from google.appengine.ext import webapp LA
import markdown
from urllib import urlencode
from markdown.inlinepatterns import Pattern
from google.appengine.ext import webapp
LATEX_RE = r'\${2}([^$]+)\${2}'
API_URL = 'http://chart.apis.google.com/chart?'
class LatexPattern(Pattern):
"""
Searchs for LaTex equations $$\latex$$ and
returns img tags using google charts API
"""
def handleMatch(self, m):
el = markdown.etree.Element('img')
src = API_URL + urlencode({
'chl': m.group(2),
'cht': 'tx'
})
el.set('src', src)
el.set('alt', m.group(2))
return el
class LatexExtension(markdown.Extension):
def extendMarkdown(self, md, md_globals):
md.inlinePatterns.add(
'latex',
LatexPattern(LATEX_RE, self),
'<automail'
)
class MarkdownHandler(webapp.RequestHandler):
def post(self):
data = self.request.get('data')
extension = LatexExtension(configs=[])
md = markdown.Markdown(extensions=[extension])
html = md.convert(data)
self.response.out.write(html)
导入降价
从urllib导入urlencode
从markdown.inlinepatterns导入模式
从google.appengine.ext导入webapp
LATEX\u RE=r'\${2}([^$]+)\${2}'
美国石油学会http://chart.apis.google.com/chart?'
类LatexPattern(模式):
"""
搜索LaTex方程$$\LaTex$$和
使用GoogleCharts API返回img标记
"""
def手柄匹配(自身,m):
el=markdown.etree.Element('img')
src=API_URL+urlencode({
“chl”:m组(2),
“cht”:“tx”
})
标高集('src',src)
el.set('alt',m.group(2))
返回el
类LatexExtension(markdown.Extension):
def扩展标记(自我、md、md_全局):
md.inlinePatterns.add(
“乳胶”,
LatexPattern(LATEX_RE,self),
'