예제 #1
0
파일: sagews2pdf.py 프로젝트: nikolas/smc
def reconstruct_math(s, tmp):
    from markdown2Mathjax import reconstructMath

    while len(tmp) > 1:
        s = reconstructMath(s, tmp[-1][0][1], equation_delims=tmp[-1][1])
        del tmp[-1]
    return s
예제 #2
0
파일: formatters.py 프로젝트: aaren/Pweave
    def format_docchunk(self, chunk):
        if chunk.has_key("number") and chunk['number'] == 1:
            chunk = self.parsetitle(chunk)

        try:
            from markdown import markdown
        except:
            try:
                from markdown2 import markdown
            except:
                raise

        #Use Mathjax if it is available
        try:
            import markdown2Mathjax as MJ
            tmp = MJ.sanitizeInput(chunk['content'])
            markedDownText = markdown(tmp[0])
            finalOutput = MJ.reconstructMath(markedDownText,
                                             tmp[1],
                                             inline_delims=["\\(", "\\)"])
            chunk['content'] = finalOutput
        except:
            sys.stderr.write(
                "WARNING: Can't import markdown2Mathjax, expect problems with math formatting.\n"
            )
            chunk['content'] = markdown(chunk['content'])
        return (chunk['content'])
예제 #3
0
def reconstruct_math(s, tmp):
    print "s ='%r'" % s
    print "tmp = '%r'" % tmp
    from markdown2Mathjax import reconstructMath
    while len(tmp) > 1:
        s = reconstructMath(s, tmp[-1][0][1], equation_delims=tmp[-1][1])
        del tmp[-1]
    return s
예제 #4
0
def markjax(text):
    tmp = sanitizeInput(text, inline_delims=inline_delims)
    mkd_text = markdown(tmp[0],
                        extras=[
                            'code-friendly', 'fenced-code-blocks', 'footnotes',
                            'metadata', 'smarty-pants', 'tables'
                        ])
    output = reconstructMath(mkd_text, tmp[1], inline_delims)
    return output
예제 #5
0
def custom_markdown(value):

    # thanks to https://github.com/constantAmateur/markdown2Mathjax
    extras = ["fenced-code-blocks", "spoiler"]
    tmp = sanitizeInput(value)
    markedDownText = markdown2.markdown(force_unicode(tmp[0]), extras = extras)
    finalOutput = reconstructMath(markedDownText,tmp[1])
    return mark_safe(finalOutput)

#old working code, save for now.
#@register.filter(is_safe=True)
#@stringfilter
#def custom_markdown(value):
#    extras = ["fenced-code-blocks"]
#
#    return mark_safe(markdown2.markdown(force_unicode(value),
#                                      extras = extras))
예제 #6
0
def custom_markdown(value):

    # thanks to https://github.com/constantAmateur/markdown2Mathjax
    extras = ["fenced-code-blocks", "spoiler"]
    tmp = sanitizeInput(value)
    markedDownText = markdown2.markdown(force_unicode(tmp[0]), extras=extras)
    finalOutput = reconstructMath(markedDownText, tmp[1])
    return mark_safe(finalOutput)


#old working code, save for now.
#@register.filter(is_safe=True)
#@stringfilter
#def custom_markdown(value):
#    extras = ["fenced-code-blocks"]
#
#    return mark_safe(markdown2.markdown(force_unicode(value),
#                                      extras = extras))
예제 #7
0
파일: formatters.py 프로젝트: aaren/Pweave
    def format_docchunk(self, chunk):
        if chunk.has_key("number") and chunk['number'] == 1:
            chunk = self.parsetitle(chunk)

        try:
            from markdown import markdown
        except:
            try:
                from markdown2 import markdown
            except:
                raise
        
        #Use Mathjax if it is available
        try:
            import markdown2Mathjax as MJ
            tmp = MJ.sanitizeInput(chunk['content'])
            markedDownText = markdown(tmp[0])
            finalOutput = MJ.reconstructMath(markedDownText,tmp[1], inline_delims=["\\(","\\)"])
            chunk['content'] = finalOutput
        except:
            sys.stderr.write("WARNING: Can't import markdown2Mathjax, expect problems with math formatting.\n")
            chunk['content'] = markdown(chunk['content'])
        return(chunk['content'])
예제 #8
0
import sys

from markdown2Mathjax import sanitizeInput, reconstructMath
from markdown2 import markdown

if (len(sys.argv)==1):
  print('no input specified')
  raise SystemExit

infile = sys.argv[1]

with open(infile, 'r') as f:
    mdfile = f.read()

tmp = sanitizeInput(mdfile)
mdtext = markdown(tmp[0])
finalOutput = reconstructMath(mdtext,tmp[1])

print finalOutput.encode('utf8')