initial commit

This commit is contained in:
xenia 2021-06-06 00:59:21 -04:00
commit ab421928c6
13 changed files with 1973 additions and 0 deletions

1
ext-mathml/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

55
ext-mathml/main.rkt Normal file
View File

@ -0,0 +1,55 @@
#lang racket/base
(require racket/list racket/match racket/port racket/runtime-path racket/string
xml)
(define-runtime-path *js-path* "./mathml-render.js")
(provide transform-xexprs get-styles)
(define (mathtex-type? s)
(and (string? s) (regexp-match #rx"^math/tex" s) #t))
(define (transform-xexprs xexprs)
(map transform-xexpr xexprs))
(define (run-mathjax source block?)
(define-values [proc out in err]
(subprocess #f #f #f "/usr/bin/env" "node" (path->string *js-path*)))
(define out-str #f)
(define err-str "")
(define out-reader (thread (lambda () (set! out-str (port->string out)))))
(define err-reader (thread (lambda () (set! err-str (port->string err)))))
(write-string source in)
(flush-output in)
(close-output-port in)
(subprocess-wait proc)
(thread-wait out-reader)
(thread-wait err-reader)
(define err-trimmed (string-trim err-str))
(unless (string=? "" err-trimmed)
(error "mathjax process raised error!" err-trimmed))
(unless out-str
(error "mathjax process didn't return anything!"))
(match-define (list 'math attrs bodies ...) (string->xexpr out-str))
`(math ,(cons (list 'display (if block? "block" "inline"))
(filter (lambda (x) (not (eq? (first x) 'display))) attrs))
,@bodies))
(define (transform-xexpr xexpr)
(match xexpr
[(list 'script (list (list 'type (? mathtex-type? type)))
bodies ...)
(define body (apply string-append bodies))
(define block? (> (length (string-split type " ")) 1))
(run-mathjax body block?)]
[(list tag attrs body ...)
(cons tag (cons attrs (map transform-xexpr body)))]
[(? string? str) str]))
(define (get-styles) "")

View File

@ -0,0 +1,17 @@
const fs = require('fs');
const mjAPI = require("mathjax-node");
mjAPI.config({
MathJax: {}
});
mjAPI.start();
let data = fs.readFileSync(0, 'utf-8');
mjAPI.typeset({
math: data,
format: "TeX",
mml: true,
}, function (data) {
if (!data.errors) {console.log(data.mml)}
});

1571
ext-mathml/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

5
ext-mathml/package.json Normal file
View File

@ -0,0 +1,5 @@
{
"dependencies": {
"mathjax-node": "^2.1.1"
}
}

View File

@ -0,0 +1,31 @@
// Config -----------------------------------
$syntax-hue: 220;
$syntax-saturation: 13%;
$syntax-brightness: 18%;
// Monochrome -----------------------------------
$mono-1: hsl($syntax-hue, 14%, 71%); // default text
$mono-2: hsl($syntax-hue, 9%, 55%);
$mono-3: hsl($syntax-hue, 10%, 40%);
// Colors -----------------------------------
$hue-1: hsl(187, 47%, 55%); // <-cyan
$hue-2: hsl(207, 82%, 66%); // <-blue
$hue-3: hsl(286, 60%, 67%); // <-purple
$hue-4: hsl( 95, 38%, 62%); // <-green
$hue-5: hsl(355, 65%, 65%); // <-red 1
$hue-5-2: hsl( 5, 48%, 51%); // <-red 2
$hue-6: hsl( 29, 54%, 61%); // <-orange 1
$hue-6-2: hsl( 39, 67%, 69%); // <-orange 2
// Base colors -----------------------------------
$syntax-fg: $mono-1;
$syntax-bg: hsl($syntax-hue, $syntax-saturation, $syntax-brightness);
$syntax-gutter: darken($syntax-fg, 26%);
$syntax-guide: fade($syntax-fg, 15%);
$syntax-accent: hsl($syntax-hue, 100%, 66% );

View File

@ -0,0 +1,20 @@
Copyright (c) 2011-2021 GitHub Inc.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2016 Mihály Gyöngyösi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,56 @@
@import "colors.scss";
// Official Syntax Variables -----------------------------------
// General colors
$syntax-text-color: $syntax-fg;
$syntax-cursor-color: $syntax-accent;
$syntax-background-color: $syntax-bg;
$syntax-selection-color: lighten($syntax-background-color, 10%);
$syntax-selection-flash-color: $syntax-accent;
// Guide colors
$syntax-wrap-guide-color: $syntax-guide;
$syntax-indent-guide-color: $syntax-guide;
$syntax-invisible-character-color: $syntax-guide;
// For find and replace markers
$syntax-result-marker-color: fade($syntax-accent, 24%);
$syntax-result-marker-color-selected: $syntax-accent;
// Gutter colors
$syntax-gutter-text-color: $syntax-gutter;
$syntax-gutter-text-color-selected: $syntax-fg;
$syntax-gutter-background-color: $syntax-bg; // unused
$syntax-gutter-background-color-selected: lighten($syntax-bg, 2%);
// Git colors - For git diff info. i.e. in the gutter
$syntax-color-renamed: hsl(208, 100%, 60%);
$syntax-color-added: hsl(150, 60%, 54%);
$syntax-color-modified: hsl(40, 60%, 70%);
$syntax-color-removed: hsl(0, 70%, 60%);
// For language entity colors
$syntax-color-variable: $hue-5;
$syntax-color-constant: $hue-6;
$syntax-color-property: $syntax-fg;
$syntax-color-value: $syntax-fg;
$syntax-color-function: $hue-2;
$syntax-color-method: $hue-2;
$syntax-color-class: $hue-6-2;
$syntax-color-keyword: $hue-3;
$syntax-color-tag: $hue-5;
$syntax-color-attribute: $hue-6;
$syntax-color-import: $hue-3;
$syntax-color-snippet: $hue-4;
// Custom Syntax Variables -----------------------------------
// Don't use in packages
$syntax-cursor-line: hsla($syntax-hue, 100%, 80%, .04); // needs to be semi-transparent to show search results
$syntax-deprecated-fg: darken($syntax-color-modified, 50%);
$syntax-deprecated-bg: $syntax-color-modified;
$syntax-illegal-fg: white;
$syntax-illegal-bg: $syntax-color-removed;

View File

@ -0,0 +1,91 @@
// LESS for Pygments
@import "syntax-variables.scss";
pre.highlight, .highlight {
background: $syntax-bg;
color: $mono-1;
}
.highlight {
pre { background: $syntax-bg; }
.hll { background: $syntax-bg; }
.c { color: $mono-3; font-style: italic; } /* Comment */
.err { color: $syntax-illegal-fg; background-color: $syntax-illegal-bg; } /* Error */
.k { color: $hue-3; } /* Keyword */
.l { color: $hue-4; } /* Literal */
.n { color: $mono-1; } /* Name */
.o { color: $mono-1; } /* Operator */
.p { color: $mono-1; } /* Punctuation */
.cm { color: $mono-3; font-style: italic; } /* Comment.Multiline */
.cp { color: $mono-3; font-style: italic; } /* Comment.Preproc */
.c1 { color: $mono-3; font-style: italic; } /* Comment.Single */
.cs { color: $mono-3; font-style: italic; } /* Comment.Special */
.ge { font-style: italic } /* Generic.Emph */
.gs { font-weight: bold } /* Generic.Strong */
.kc { color: $hue-3; } /* Keyword.Constant */
.kd { color: $hue-3; } /* Keyword.Declaration */
.kn { color: $hue-3; } /* Keyword.Namespace */
.kp { color: $hue-3; } /* Keyword.Pseudo */
.kr { color: $hue-3; } /* Keyword.Reserved */
.kt { color: $hue-3; } /* Keyword.Type */
.ld { color: $hue-4; } /* Literal.Date */
.m { color: $hue-6; } /* Literal.Number */
.s { color: $hue-4; } /* Literal.String */
.na { color: $hue-6; } /* Name.Attribute */
.nb { color: $hue-6-2; } /* Name.Builtin */
.nc { color: $hue-6-2; } /* Name.Class */
.no { color: $hue-6-2; } /* Name.Constant */
.nd { color: $hue-6-2; } /* Name.Decorator */
.ni { color: $hue-6-2; } /* Name.Entity */
.ne { color: $hue-6-2; } /* Name.Exception */
.nf { color: $mono-1; } /* Name.Function */
.nl { color: $hue-6-2; } /* Name.Label */
.nn { color: $mono-1; } /* Name.Namespace */
.nx { color: $mono-1; } /* Name.Other */
.py { color: $hue-6-2; } /* Name.Property */
.nt { color: $hue-5; } /* Name.Tag */
.nv { color: $hue-6-2; } /* Name.Variable */
.ow { font-weight: bold; } /* Operator.Word */
.w { color: #f8f8f2 } /* Text.Whitespace */
.mf { color: $hue-6; } /* Literal.Number.Float */
.mh { color: $hue-6; } /* Literal.Number.Hex */
.mi { color: $hue-6; } /* Literal.Number.Integer */
.mo { color: $hue-6; } /* Literal.Number.Oct */
.sb { color: $hue-4; } /* Literal.String.Backtick */
.sc { color: $hue-4; } /* Literal.String.Char */
.sd { color: $hue-4; } /* Literal.String.Doc */
.s2 { color: $hue-4; } /* Literal.String.Double */
.se { color: $hue-4; } /* Literal.String.Escape */
.sh { color: $hue-4; } /* Literal.String.Heredoc */
.si { color: $hue-4; } /* Literal.String.Interpol */
.sx { color: $hue-4; } /* Literal.String.Other */
.sr { color: $hue-1; } /* Literal.String.Regex */
.s1 { color: $hue-4; } /* Literal.String.Single */
.ss { color: $hue-1; } /* Literal.String.Symbol */
.bp { color: $hue-6-2; } /* Name.Builtin.Pseudo */
.vc { color: $hue-6-2; } /* Name.Variable.Class */
.vg { color: $hue-6-2; } /* Name.Variable.Global */
.vi { color: $hue-5; } /* Name.Variable.Instance */
.il { color: $hue-6; } /* Literal.Number.Integer.Long */
.gh { } /* Generic Heading & Diff Header */
.gu { color: #75715e; } /* Generic.Subheading & Diff Unified/Comment? */
.gd { color: $syntax-color-removed; } /* Generic.Deleted & Diff Deleted */
.gi { color: $syntax-color-added; } /* Generic.Inserted & Diff Inserted */
::selection { background-color: $syntax-selection-color; }
.language-json {
.w + .s2 { color: $hue-5; }
.kc { color: $hue-1; }
}
.language-python {
// python related modifications
}
.language-csharp {
// csharp related modifications
}
}

57
ext-syntax/main.rkt Normal file
View File

@ -0,0 +1,57 @@
#lang racket/base
(require racket/list racket/match racket/port racket/runtime-path racket/string
xml sass)
(define-runtime-path *python-path* "syntax-render.py")
(define-runtime-path *css-path* "css")
(provide transform-xexprs get-styles)
(define (brush-class? s)
(and (string? s) (regexp-match #rx"^brush:" s) #t))
(define (transform-xexprs xexprs)
(map transform-xexpr xexprs))
(define (run-pygments lang source)
(define-values [proc out in err]
(subprocess #f #f #f "/usr/bin/env" "python3" (path->string *python-path*) lang))
(define out-str #f)
(define err-str "")
(define out-reader (thread (lambda () (set! out-str (port->string out)))))
(define err-reader (thread (lambda () (set! err-str (port->string err)))))
(write-string source in)
(flush-output in)
(close-output-port in)
(subprocess-wait proc)
(thread-wait out-reader)
(thread-wait err-reader)
(define err-trimmed (string-trim err-str))
(unless (string=? "" err-trimmed)
(error "pygments process raised error!" err-trimmed))
(unless out-str
(error "pygments process didn't return anything!"))
(string->xexpr out-str))
(define (transform-xexpr xexpr)
(match xexpr
[(list 'pre (list (list 'class (? brush-class? cls)))
(list 'code '() bodies ...))
(define lang (second (string-split cls " ")))
(define body (apply string-append bodies))
(run-pygments lang body)]
[(list 'pre '() (list 'code '() bodies ...))
(define body (apply string-append bodies))
(run-pygments "text" body)]
[(list tag attrs body ...)
(cons tag (cons attrs (map transform-xexpr body)))]
[(? string? str) str]))
(define (get-styles)
(compile/file (build-path *css-path* "syntax.scss") #t))

View File

@ -0,0 +1,17 @@
import sys
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.util import ClassNotFound
from pygments.formatters import HtmlFormatter
formatter = HtmlFormatter(linenos="table", encoding="utf-8")
try:
lexer = get_lexer_by_name(sys.argv[1], encoding="utf-8")
except IndexError:
sys.stderr.write("must provide lexer name")
except:
sys.stderr.write(f"couldn't find lexer {sys.argv[1]}\n")
sys.stdout.write(highlight(sys.stdin.read(), lexer, formatter).decode("utf-8"))

31
render.rkt Normal file
View File

@ -0,0 +1,31 @@
#lang racket
(require markdown markdown/display-xexpr
(prefix-in mathml: "ext-mathml/main.rkt")
(prefix-in syntax: "ext-syntax/main.rkt"))
(define input (port->string (current-input-port)))
(define output-raw (parse-markdown input))
(define output-cooked (mathml:transform-xexprs (syntax:transform-xexprs output-raw)))
(define styles (string-append (mathml:get-styles) (syntax:get-styles)))
(define document
`(html
((lang "en"))
(head
()
(meta ((charset "utf-8")))
(title () "meow meow meow")
(meta ((name "viewport") (content "width=device-width, initial-scale=1")))
(meta ((name "description") (content "prototype racket markdown system uwu")))
;<link rel="shortcut icon" type="image/png" href="haskal.png"/>
(style ((type "text/css")) ,styles))
(body
()
(main
()
,@output-cooked))))
(display "<!doctype html>")
(display-xexpr document)