CARVIEW |
Select Language
HTTP/2 302
date: Mon, 28 Jul 2025 00:27:35 GMT
content-type: text/html; charset=utf-8
content-length: 0
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
location: https://gist.github.com/waylan/1886026
cache-control: no-cache
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
set-cookie: _gh_sess=WKwV45SzK22OMTtNBmL1HlEFE91a%2FPxPhcrWCcr%2Flf8b6xWdSrRlJMAhuUo6myIMaHPLw%2FArSYyrN60c1uPWvn%2F14H%2B%2FoDFlPAAsISznCSFjMC5vFQ58YMiI4DKYk%2FqLHLAKHQLF2MNMROeKm1SNe%2FuFXJM1fckI1HLu1PCFUbV5kWEfR0GdvYSehsWbF1a2CbXVGZuZY%2FT%2BjT1HvN%2FZRKNBtyo%2F6TMywB96j29Ax425TFgN2lUxCyNj9f%2Fb3flQcamA%2F%2BEsaAQq5uClzZLmgQ%3D%3D--3mK7FfNJhbmUkFMR--De8nrGjBDmGt5yEhIS8djg%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.1098603014.1753662454; Path=/; Domain=github.com; Expires=Tue, 28 Jul 2026 00:27:34 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Tue, 28 Jul 2026 00:27:34 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: 92FA:37D5F1:1237571:18224D8:6886C3F6
HTTP/2 200
date: Mon, 28 Jul 2025 00:27:36 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"ca4b930eba8d2ef5672fcc7240560f8b"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
x-github-request-id: 92FA:37D5F1:123758D:1822507:6886C3F6
Math extension for Python-Markdown · GitHub
Show Gist options
Save waylan/1886026 to your computer and use it in GitHub Desktop.
{{ message }}
Instantly share code, notes, and snippets.
Created
February 22, 2012 16:59
-
Star
3
(3)
You must be signed in to star a gist -
Fork
3
(3)
You must be signed in to fork a gist
-
Save waylan/1886026 to your computer and use it in GitHub Desktop.
Math extension for Python-Markdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Math extension for Python-Markdown | |
Copied from https://freewisdom.org/projects/python-markdown/mdx_math for preservation. | |
The following description was attached by the author: | |
> This is a quick and dirty implementation of allowing <math> LaTeX </math> to do | |
> formulae in Markdown. We'll call this page right here the "official site" for this | |
> extension I think. | |
> | |
> It requires "latex" and "dvipng". I use MiKTeX on Win32 in particular, but I'm sure | |
> other types of them would work fine. | |
> | |
> Finally, I've never written any Python before so please feel free to tidy/fix. | |
> | |
> -- Scott https://h4ck3r.net | |
""" | |
import markdown | |
import os | |
import re | |
import md5 | |
BEFORE_TEX = """\\documentclass[12pt]{article} | |
\\usepackage[latin1]{inputenc} | |
\\usepackage{amsmath} | |
\\usepackage{amsfonts} | |
\\usepackage{amssymb} | |
\\pagestyle{empty} | |
\\begin{document} | |
$""" | |
AFTER_TEX = """$ | |
\\end{document} | |
""" | |
BLACKLIST = [ | |
"include", | |
"def", | |
"command", | |
"loop", | |
"repeat", | |
"open", | |
"toks", | |
"output", | |
"input", | |
"catcode", | |
"name", | |
"^^", | |
"\\every", | |
"\\errhelp", | |
"\\errorstopmode", | |
"\\scrollmode", | |
"\\nonstopmode", | |
"\\batchmode", | |
"\\read", | |
"\\write", | |
"csname", | |
"\\newhelp", | |
"\\uppercase", | |
"\\lowercase", | |
"\\relax", | |
"\\aftergroup", | |
"\\afterassignment", | |
"\\expandafter", | |
"\\noexpand", | |
"\\special" | |
] | |
class MathPattern(markdown.Pattern): | |
def __init__ (self, md): | |
markdown.Pattern.__init__(self, r'(<|<)math>(.*)(<|<)/math>') | |
self.md = md | |
def getFnFromCode(self, code): | |
hash = md5.new(code).hexdigest() | |
matches = re.match("(.)(.)(.)(.*)", hash) | |
dirs = "static\\images\\" + matches.group(1) + "\\" + matches.group(2) + "\\" + matches.group(3) + "\\" | |
file = dirs + hash | |
png = file + ".png" | |
tex = file + ".tex" | |
dvi = file + ".dvi" | |
aux = file + ".aux" | |
log = file + ".log" | |
return (dirs, png, tex, dvi, aux, log) | |
def handleMatch(self, m, doc): | |
code = m.group(3).strip() | |
code = code.replace("<", "<") | |
code = code.replace(">", ">") | |
(dirsb, pngb, texb, dvib, auxb, logb) = self.getFnFromCode(code) | |
pngf = pngb.replace("\\", "/") | |
def done(fn): | |
img = doc.createElement('img') | |
img.setAttribute("src", "/" + fn) | |
img.setAttribute("alt", code) | |
return img | |
def error(): | |
err = doc.createElement("font") | |
err.setAttribute("color", "red") | |
err.appendChild(doc.createTextNode("error rendering: " + code)) | |
return err | |
if os.path.exists(pngb): return done(pngf) | |
def checker(x,y): | |
if not x: return False | |
return code.find(y) == -1 | |
if not reduce(checker, BLACKLIST, True): | |
return error() | |
if not os.path.exists(dirsb): os.makedirs(dirsb) | |
f = open(texb, "w") | |
f.writelines([BEFORE_TEX, code, AFTER_TEX]) | |
f.close() | |
if os.system("latex -quiet -interaction=batchmode -output-directory=" + dirsb + " -aux-directory=" + dirsb + " " + texb) != 0: return error() | |
if os.system("dvipng -D 150 -o " + pngb + " -T tight " + dvib) != 0: return error() | |
os.remove(texb) | |
os.remove(auxb) | |
os.remove(dvib) | |
os.remove(logb) | |
return done(pngf) | |
class MathExtension(markdown.Extension): | |
def extendMarkdown(self, md, md_globals): | |
md.inlinePatterns.insert(0, MathPattern(md)) | |
def makeExtension(configs): | |
return MathExtension(configs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can’t perform that action at this time.