コード例 #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
ファイル: sagews2pdf.py プロジェクト: sunny728/cocalc
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
ファイル: convert.py プロジェクト: xiexinyls/ds-notebook
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')