crab it 🦀

This commit is contained in:
xenia 2021-06-11 22:55:13 -04:00
parent 1f100b6a24
commit d51e965908
30 changed files with 2377 additions and 1913 deletions

View File

@ -14,8 +14,7 @@ NIH syndrome :3
```bash ```bash
# external dependencies (unfortunately i could not reasonably replace these with racket) # external dependencies (unfortunately i could not reasonably replace these with racket)
(cd ext-mathml && npm install) (cd ext && cargo build)
pip3 install --user pygments
# install the package # install the package
raco pkg install $PWD raco pkg install $PWD
# ensure your PATH has racket stuff on it. replace 8.1 with your version # ensure your PATH has racket stuff on it. replace 8.1 with your version

11
doc/todo.md Normal file
View File

@ -0,0 +1,11 @@
# todo
- prefers-color-scheme
- firefox alternative stylesheets too maybe
- rss/atom
- webmentions
- reject brave (lol)
- support tor and opennic
- activitypub
- gopher and gemini variants
- nginx caching headers

View File

@ -1 +0,0 @@
node_modules

View File

@ -1,35 +0,0 @@
#lang racket/base
(require racket/list racket/match racket/runtime-path racket/string xml
"../util.rkt")
(define-runtime-path *js-path* "mathml-render.js")
(provide transform-xexprs scss-files)
(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 out-str (run-external (list "node" (path->string *js-path*)) source))
(match-define (list 'math attrs bodies ...) (string->xexpr out-str))
`(math ,(cons (list 'display (if block? "block" "inline"))
(filter (λ (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 scss-files '())

View File

@ -1,17 +0,0 @@
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)}
});

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -1,31 +0,0 @@
// 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

@ -1,20 +0,0 @@
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

@ -1,56 +0,0 @@
@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

@ -1,106 +0,0 @@
// LESS for Pygments
@import "syntax-variables.scss";
pre.highlight, .highlight {
background: $syntax-bg;
color: $mono-1;
}
.highlighttable {
background: $syntax-gutter-background-color;
color: $syntax-gutter-text-color;
margin: 0.5em;
pre {
margin: 0;
}
.linenos {
user-select: none;
}
}
.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: $hue-2; } /* 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
}
}

View File

@ -1,36 +0,0 @@
#lang racket/base
(require racket/list racket/match racket/runtime-path racket/string xml
"../util.rkt")
(define-runtime-path *python-path* "syntax-render.py")
(define-runtime-path *css-path* "css")
(provide transform-xexprs scss-files)
(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 out-str
(run-external (list "python3" (path->string *python-path*) lang) source))
(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 scss-files (list (build-path *css-path* "syntax.scss")))

View File

@ -1,17 +0,0 @@
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"))

1
ext/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
target

1200
ext/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

7
ext/Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[workspace]
members = [
"syntax",
"mathml",
"fulltext",
"capybara-ext"
]

View File

@ -0,0 +1,19 @@
[package]
name = "capybara-ext"
version = "0.1.0"
authors = ["haskal <haskal@awoo.systems>"]
edition = "2018"
[lib]
name = "capybara"
crate_type = ["dylib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde-lexpr = "0.1.2"
syntax = { path = "../syntax" }
mathml = { path = "../mathml" }
fulltext = { path = "../fulltext" }

View File

@ -0,0 +1,4 @@
#[no_mangle]
pub extern "C" fn meow() -> u64 {
1337
}

View File

@ -0,0 +1,29 @@
use serde::{Serialize, Deserialize};
use syntax::{highlight, get_css};
use mathml::convert;
#[derive(Serialize, Deserialize, Debug)]
enum Command {
Highlight { language: String, source: String },
HighlightCss,
Mathml { source: String, blockp: bool }
}
fn main() {
let stdin = std::io::stdin();
let stdout = std::io::stdout();
let result = (||{
match serde_lexpr::from_reader(stdin) {
Ok(Command::Highlight { ref language, ref source }) =>
highlight(&language, &source),
Ok(Command::HighlightCss) =>
Ok(get_css()),
Ok(Command::Mathml { ref source, blockp }) =>
convert(&source, blockp),
Err(err) =>
Err(format!("parse error: {}", err))
}
})();
serde_lexpr::to_writer(&stdout, &result).unwrap();
}

10
ext/fulltext/Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "fulltext"
version = "0.1.0"
authors = ["haskal <haskal@awoo.systems>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tantivy = "0.15.0"

86
ext/fulltext/src/lib.rs Normal file
View File

@ -0,0 +1,86 @@
#[macro_use]
extern crate tantivy;
use tantivy::collector::TopDocs;
use tantivy::query::QueryParser;
use tantivy::schema::*;
use tantivy::Index;
use tantivy::ReloadPolicy;
pub fn make_index() -> tantivy::Result<()> {
let mut schema_builder = Schema::builder();
schema_builder.add_text_field("title", TEXT | STORED);
schema_builder.add_text_field("body", TEXT);
let schema = schema_builder.build();
let index = Index::create_in_ram(schema.clone());
let mut index_writer = index.writer(50_000_000)?;
let title = schema.get_field("title").unwrap();
let body = schema.get_field("body").unwrap();
let mut old_man_doc = Document::default();
old_man_doc.add_text(title, "The Old Man and the Sea");
old_man_doc.add_text(
body,
"He was an old man who fished alone in a skiff in the Gulf Stream and \
he had gone eighty-four days now without taking a fish.",
);
index_writer.add_document(old_man_doc);
index_writer.add_document(doc!(
title => "Of Mice and Men",
body => "A few miles south of Soledad, the Salinas River drops in close to the hillside \
bank and runs deep and green. The water is warm too, for it has slipped twinkling \
over the yellow sands in the sunlight before reaching the narrow pool. On one \
side of the river the golden foothill slopes curve up to the strong and rocky \
Gabilan Mountains, but on the valley side the water is lined with treeswillows \
fresh and green with every spring, carrying in their lower leaf junctures the \
debris of the winters flooding; and sycamores with mottled, white, recumbent \
limbs and branches that arch over the pool"
));
index_writer.add_document(doc!(
title => "Of Mice and Men",
body => "A few miles south of Soledad, the Salinas River drops in close to the hillside \
bank and runs deep and green. The water is warm too, for it has slipped twinkling \
over the yellow sands in the sunlight before reaching the narrow pool. On one \
side of the river the golden foothill slopes curve up to the strong and rocky \
Gabilan Mountains, but on the valley side the water is lined with treeswillows \
fresh and green with every spring, carrying in their lower leaf junctures the \
debris of the winters flooding; and sycamores with mottled, white, recumbent \
limbs and branches that arch over the pool"
));
index_writer.add_document(doc!(
title => "Frankenstein",
title => "The Modern Prometheus",
body => "You will rejoice to hear that no disaster has accompanied the commencement of an \
enterprise which you have regarded with such evil forebodings. I arrived here \
yesterday, and my first task is to assure my dear sister of my welfare and \
increasing confidence in the success of my undertaking."
));
index_writer.commit()?;
let reader = index
.reader_builder()
.reload_policy(ReloadPolicy::OnCommit)
.try_into()?;
let searcher = reader.searcher();
let query_parser = QueryParser::for_index(&index, vec![title, body]);
let query = query_parser.parse_query("sea whale")?;
let top_docs = searcher.search(&query, &TopDocs::with_limit(10))?;
for (_score, doc_address) in top_docs {
let retrieved_doc = searcher.doc(doc_address)?;
println!("{}", schema.to_json(&retrieved_doc));
}
Ok(())
}

58
ext/main.rkt Normal file
View File

@ -0,0 +1,58 @@
#lang racket/base
(require racket/list racket/match racket/runtime-path racket/string xml
"../util.rkt")
(define-runtime-path *ext-path* "target/debug/capybara-ext")
(provide transform-xexprs get-scss-include)
(define (mathtex-type? s)
(and (string? s) (regexp-match #rx"^math/tex" s) #t))
(define (brush-class? s)
(and (string? s) (regexp-match #rx"^brush:" s) #t))
(define (transform-xexprs xexprs)
(map transform-xexpr xexprs))
(define (run-highlight lang source)
(match
(run-external
(path->string *ext-path*)
`(Highlight (language . ,lang) (source . ,source)))
[`(Ok . ,result) (string->xexpr result)]
[`(Err . ,err) (error "syntax highlighting error:" err)]))
(define (run-mathml source block?)
(match
(run-external
(path->string *ext-path*)
`(Mathml (source . ,source) (blockp . ,block?)))
[`(Ok . ,result) (string->xexpr result)]
[`(Err . ,err) (error "mathml rendering error:" err)]))
(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-mathml body block?)]
[(list 'pre (list (list 'class (? brush-class? cls)))
(list 'code '() bodies ...))
(define lang (second (string-split cls " ")))
(define body (apply string-append bodies))
(run-highlight lang body)]
[(list 'pre '() (list 'code '() bodies ...))
(define body (apply string-append bodies))
(run-highlight "txt" body)]
[(list tag attrs body ...)
(cons tag (cons attrs (map transform-xexpr body)))]
[(? string? str) str]))
(define (get-scss-include)
(match
(run-external (path->string *ext-path*) '(HighlightCss))
[`(Ok . ,result) result]
[`(Err . ,err) (error "syntax highlighting error:" err)]))

10
ext/mathml/Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "mathml"
version = "0.1.0"
authors = ["haskal <haskal@awoo.systems>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
latex2mathml = "0.2.3"

8
ext/mathml/src/lib.rs Normal file
View File

@ -0,0 +1,8 @@
use std::result::Result;
use latex2mathml::{DisplayStyle, latex_to_mathml};
pub fn convert(source: &str, blockp: bool) -> Result<String, String> {
latex_to_mathml(source, if blockp { DisplayStyle::Block } else { DisplayStyle::Inline })
.map_err(|err| format!("latex error: {}", err))
}

10
ext/syntax/Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "syntax"
version = "0.1.0"
authors = ["haskal <haskal@awoo.systems>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
syntect = "4.4"

View File

@ -1,6 +1,6 @@
MIT License The MIT License (MIT)
Copyright (c) 2016 Mihály Gyöngyösi Copyright (c) 2016 Andres Michel
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -0,0 +1,876 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>author</key>
<string>IceTimux / Andres Michel</string>
<key>name</key>
<string>One Dark</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#6c7079</string>
<key>background</key>
<string>#2B303B</string>
<key>invisibles</key>
<string>#747369</string>
<key>caret</key>
<string>#528bff</string>
<key>lineHighlight</key>
<string>#8cc2fc0b</string>
<key>bracketContentsOptions</key>
<string>underline</string>
<key>bracketContentsForeground</key>
<string>#528bff</string>
<key>bracketsOptions</key>
<string>underline</string>
<key>bracketsForeground</key>
<string>#528bff</string>
<key>tagsOptions</key>
<string>underline</string>
<key>tagsForeground</key>
<string>#528bff</string>
<key>findHighlight</key>
<string>#314365</string>
<key>findHighlightForeground</key>
<string>#528bff</string>
<key>gutter</key>
<string>#2B303B</string>
<key>gutterForeground</key>
<string>#636d8388</string>
<key>selection</key>
<string>#bbccf51b</string>
<key>selectionBorder</key>
<string>#bbccf51b</string>
<key>inactiveSelection</key>
<string>#bbccf51b</string>
<key>guide</key>
<string>#464c55</string>
<key>activeGuide</key>
<string>#464c55</string>
<key>stackGuide</key>
<string>#464c55</string>
<key>highlight</key>
<string>#528bff80</string>
<key>highlightForeground</key>
<string>#528bff</string>
<key>shadow</key>
<string>#2B303B</string>
<key>shadowWidth</key>
<string>1</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Text and source</string>
<key>scope</key>
<string>text, source</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#abb2bf</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Text</string>
<key>scope</key>
<string>variable.parameter.function</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#adb7c9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Comments</string>
<key>scope</key>
<string>comment, punctuation.definition.comment</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#5f697a</string>
<key>fontStyle</key>
<string> italic</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Delimiters</string>
<key>scope</key>
<string>none</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#adb7c9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Operators</string>
<key>scope</key>
<string>keyword.operator</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#adb7c9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Keywords</string>
<key>scope</key>
<string>keyword</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#cd74e8</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Variables</string>
<key>scope</key>
<string>variable</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#eb6772</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Functions</string>
<key>scope</key>
<string>entity.name.function, meta.require, support.function.any-method</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#5cb3fa</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Classes</string>
<key>scope</key>
<string>support.class, entity.name.class, entity.name.type.class</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#f0c678</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Classes</string>
<key>scope</key>
<string>meta.class</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#adb7c9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Methods</string>
<key>scope</key>
<string>keyword.other.special-method</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#5cb3fa</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Storage</string>
<key>scope</key>
<string>storage</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#cd74e8</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Support</string>
<key>scope</key>
<string>support.function</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#5ebfcc</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Strings, Inherited Class</string>
<key>scope</key>
<string>string, constant.other.symbol, entity.other.inherited-class</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#9acc76</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Integers</string>
<key>scope</key>
<string>constant.numeric</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#db9d63</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Floats</string>
<key>scope</key>
<string>none</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#db9d63</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Boolean</string>
<key>scope</key>
<string>none</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#db9d63</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Constants</string>
<key>scope</key>
<string>constant</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#db9d63</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Tags</string>
<key>scope</key>
<string>entity.name.tag</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#eb6772</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Attributes</string>
<key>scope</key>
<string>entity.other.attribute-name</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#db9d63</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Attribute IDs</string>
<key>scope</key>
<string>entity.other.attribute-name.id, punctuation.definition.entity</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#db9d63</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Selector</string>
<key>scope</key>
<string>meta.selector</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#cd74e8</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Values</string>
<key>scope</key>
<string>none</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#db9d63</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Headings</string>
<key>scope</key>
<string>markup.heading punctuation.definition.heading, entity.name.section</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#5cb3fa</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Units</string>
<key>scope</key>
<string>keyword.other.unit</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#db9d63</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Bold</string>
<key>scope</key>
<string>markup.bold, punctuation.definition.bold</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#f0c678</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Italic</string>
<key>scope</key>
<string>markup.italic, punctuation.definition.italic</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#cd74e8</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Code</string>
<key>scope</key>
<string>markup.raw.inline</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#9acc76</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Link Text</string>
<key>scope</key>
<string>string.other.link, punctuation.definition.string.end.markdown</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#eb6772</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Link Url</string>
<key>scope</key>
<string>meta.link</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#db9d63</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Lists</string>
<key>scope</key>
<string>markup.list</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#eb6772</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Quotes</string>
<key>scope</key>
<string>markup.quote</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#db9d63</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Separator</string>
<key>scope</key>
<string>meta.separator</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#515151</string>
<key>foreground</key>
<string>#adb7c9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Inserted</string>
<key>scope</key>
<string>markup.inserted</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#9acc76</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Deleted</string>
<key>scope</key>
<string>markup.deleted</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#eb6772</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Changed</string>
<key>scope</key>
<string>markup.changed</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#cd74e8</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Colors</string>
<key>scope</key>
<string>constant.other.color</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#5ebfcc</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Regular Expressions</string>
<key>scope</key>
<string>string.regexp</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#5ebfcc</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Escape Characters</string>
<key>scope</key>
<string>constant.character.escape</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#5ebfcc</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Embedded</string>
<key>scope</key>
<string>punctuation.section.embedded, variable.interpolation</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#c94e42</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Illegal</string>
<key>scope</key>
<string>invalid.illegal</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ffffff</string>
<key>background</key>
<string>#e05252</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Broken</string>
<key>scope</key>
<string>invalid.broken</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#f99157</string>
<key>foreground</key>
<string>#2d2d2d</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Deprecated</string>
<key>scope</key>
<string>invalid.deprecated</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#d27b53</string>
<key>foreground</key>
<string>#2c323d</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Unimplemented</string>
<key>scope</key>
<string>invalid.unimplemented</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#747369</string>
<key>foreground</key>
<string>#2c323d</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Json key</string>
<key>scope</key>
<string>source.json meta.structure.dictionary.json string.quoted.double.json</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#eb6772</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Json value</string>
<key>scope</key>
<string>source.json meta.structure.dictionary.json meta.structure.dictionary.value.json string.quoted.double.json</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#9acc76</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>json sub key</string>
<key>scope</key>
<string>source.json meta.structure.dictionary.json meta.structure.dictionary.value.json meta.structure.dictionary.json string.quoted.double.json</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#eb6772</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Json sub value</string>
<key>scope</key>
<string>source.json meta.structure.dictionary.json meta.structure.dictionary.value.json meta.structure.dictionary.json meta.structure.dictionary.value.json string.quoted.double.json</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#9acc76</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>laravel blade tag</string>
<key>scope</key>
<string>text.html.laravel-blade source.php.embedded.line.html entity.name.tag.laravel-blade</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#cd74e8</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>laravel blade @</string>
<key>scope</key>
<string>text.html.laravel-blade source.php.embedded.line.html support.constant.laravel-blade</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#cd74e8</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>python function parameter</string>
<key>scope</key>
<string>source.python meta.function.python meta.function.parameters.python variable.parameter.function.python</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#db9d63</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>python meta function</string>
<key>scope</key>
<string>source.python meta.function-call.python support.type.python</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#5ebfcc</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>python logical keyword</string>
<key>scope</key>
<string>source.python keyword.operator.logical.python</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#cd74e8</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>python class ( begin</string>
<key>scope</key>
<string>source.python meta.class.python punctuation.definition.inheritance.begin.python</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#f0c678</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>python class ) end</string>
<key>scope</key>
<string>source.python meta.class.python punctuation.definition.inheritance.end.python</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#f0c678</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>python function call parameter name</string>
<key>scope</key>
<string>source.python meta.function-call.python meta.function-call.arguments.python variable.parameter.function.python</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#db9d63</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>php fcuntion constants</string>
<key>scope</key>
<string>text.html.basic source.php.embedded.block.html support.constant.std.php</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#db9d63</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>php namespace name</string>
<key>scope</key>
<string>text.html.basic source.php.embedded.block.html meta.namespace.php entity.name.type.namespace.php</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#f0c678</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>javascript meta constant</string>
<key>scope</key>
<string>source.js meta.function.js support.constant.js</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#db9d63</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>php namespace in top</string>
<key>scope</key>
<string>text.html.basic` source.php.embedded.block.html constant.other.php</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#cd74e8</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>php namespace name in top</string>
<key>scope</key>
<string>text.html.basic source.php.embedded.block.html support.other.namespace.php</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#db9d63</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>latex label names</string>
<key>scope</key>
<string>text.tex.latex meta.function.environment.math.latex string.other.math.block.environment.latex meta.definition.label.latex variable.parameter.definition.label.latex</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#adb7c9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>latex italic emph</string>
<key>scope</key>
<string>text.tex.latex meta.function.emph.latex markup.italic.emph.latex</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string> italic</string>
<key>foreground</key>
<string>#cd74e8</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>subl_new js vars</string>
<key>scope</key>
<string>source.js variable.other.readwrite.js</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#adb7c9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>new_subl js $</string>
<key>scope</key>
<string>source.js meta.function-call.with-arguments.js variable.function.js</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#adb7c9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>new_subl js call method</string>
<key>scope</key>
<string>source.js meta.group.braces.round meta.group.braces.curly meta.function-call.method.without-arguments.js variable.function.js</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#adb7c9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>new_subl e js</string>
<key>scope</key>
<string>source.js meta.group.braces.round meta.group.braces.curly variable.other.object.js</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#adb7c9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>new_subl js key</string>
<key>scope</key>
<string>source.js meta.group.braces.round meta.group.braces.curly constant.other.object.key.js string.unquoted.label.js</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#adb7c9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>new_subl obejct key</string>
<key>scope</key>
<string>source.js meta.group.braces.round meta.group.braces.curly constant.other.object.key.js punctuation.separator.key-value.js</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#adb7c9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>new_subl js method with args</string>
<key>scope</key>
<string>source.js meta.group.braces.round meta.group.braces.curly meta.function-call.method.with-arguments.js variable.function.js</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#adb7c9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>new_subl js variable function</string>
<key>scope</key>
<string>source.js meta.function-call.method.with-arguments.js variable.function.js</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#adb7c9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>new_subl variabel function method</string>
<key>scope</key>
<string>source.js meta.function-call.method.without-arguments.js variable.function.js</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#adb7c9</string>
</dict>
</dict>
</array>
</dict>
</plist>

29
ext/syntax/src/lib.rs Normal file
View File

@ -0,0 +1,29 @@
use std::result::Result;
use syntect::html::{ClassedHTMLGenerator, ClassStyle, css_for_theme_with_class_style};
use syntect::parsing::SyntaxSet;
use syntect::highlighting::ThemeSet;
use syntect::util::LinesWithEndings;
pub fn highlight(syntax_name: &str, source: &str) -> Result<String, String> {
let syntax_set = SyntaxSet::load_defaults_newlines();
let syntax = syntax_set.find_syntax_by_token(syntax_name)
.ok_or(format!("couldn't find syntax {}", syntax_name))?;
let mut html_generator =
ClassedHTMLGenerator::new_with_class_style(&syntax, &syntax_set, ClassStyle::Spaced);
for line in LinesWithEndings::from(source) {
html_generator.parse_html_for_line_which_includes_newline(&line);
}
let result = html_generator.finalize();
Ok(format!("<pre class=\"code\">{}</pre>", result))
}
// const ONEDARK_THEME: &'static str = include_str!("../assets/One_Dark.tmTheme");
pub fn get_css() -> String {
// let mut reader = std::io::Cursor::new(ONEDARK_THEME);
// let theme = ThemeSet::load_from_reader(&mut reader).unwrap();
let theme = &ThemeSet::load_defaults().themes["base16-ocean.dark"];
css_for_theme_with_class_style(&theme, ClassStyle::Spaced)
}

View File

@ -6,8 +6,7 @@
"compiler.rkt" "defs.rkt" "fetch.rkt" "compiler.rkt" "defs.rkt" "fetch.rkt"
threading threading
(prefix-in sass: sass) (prefix-in sass: sass)
(prefix-in mathml: "ext-mathml/main.rkt") (prefix-in ext: "ext/main.rkt")
(prefix-in syntax: "ext-syntax/main.rkt")
(prefix-in page: "templates/page.html.rkt")) (prefix-in page: "templates/page.html.rkt"))
(provide scan-for-rules) (provide scan-for-rules)
@ -20,7 +19,9 @@
(define *index.md* (build-path "index.md")) (define *index.md* (build-path "index.md"))
(define *config.rktd* (build-path "config.rktd")) (define *config.rktd* (build-path "config.rktd"))
(define *reserved-slugs* (set (build-path "hashtag") (build-path "user") (build-path "tech"))) (define *reserved-slugs*
(apply set (map build-path '("hashtag" "user" "tech" "capybara" "dynamic" "robots.txt"
"sitemap.xml" "feeds"))))
(define (read-input-doc xref-name [port (current-input-port)]) (define (read-input-doc xref-name [port (current-input-port)])
(define metadata (read port)) (define metadata (read port))
@ -103,7 +104,7 @@
(match-define (input-doc md xref-name text) doc) (match-define (input-doc md xref-name text) doc)
(define output-raw (parse-markdown text)) (define output-raw (parse-markdown text))
(define output-cooked (define output-cooked
(~> output-raw syntax:transform-xexprs mathml:transform-xexprs (~> output-raw ext:transform-xexprs
(extract-text-starting-with/many *hashtag-char* 'hashtag) (extract-text-starting-with/many *hashtag-char* 'hashtag)
(extract-text-starting-with/many *user-char* 'user) (extract-text-starting-with/many *user-char* 'user)
(extract-prefixed-links/many *xref-char* 'xref) (extract-prefixed-links/many *xref-char* 'xref)
@ -190,10 +191,11 @@
(with-output-to-string (λ () (display "<!doctype html>") (display-xexpr document))))) (with-output-to-string (λ () (display "<!doctype html>") (display-xexpr document)))))
(define (compile-index-scss index.scss) (define (compile-index-scss index.scss)
(define scss-files (cons *render.scss* (append mathml:scss-files syntax:scss-files))) (define scss-files (list *render.scss*))
(define top-level-style (define top-level-style
(string-join (string-join
(cons index.scss (map (λ (x) (format "@import \"~a\";" (path->string x))) scss-files)) (apply list index.scss (ext:get-scss-include)
(map (λ (x) (format "@import \"~a\";" (path->string x))) scss-files))
"\n")) "\n"))
(sass:compile/string top-level-style #t)) (sass:compile/string top-level-style #t))

View File

@ -11,16 +11,16 @@
(define (~r/pad num pad-to) (define (~r/pad num pad-to)
(~r num #:min-width pad-to #:pad-string "0")) (~r num #:min-width pad-to #:pad-string "0"))
(define (run-external argv source) (define (run-external prog input)
(printf " running external program: ~a\n" argv) (printf " running external program: ~a\n" prog)
(define-values [proc out in err] (define-values [proc out in err]
(apply subprocess #f #f #f "/usr/bin/env" argv)) (subprocess #f #f #f prog))
(define out-str #f) (define out-val #f)
(define err-str "") (define err-str "")
(define out-reader (thread (λ () (set! out-str (port->string out))))) (define out-reader (thread (λ () (set! out-val (read out)))))
(define err-reader (thread (λ () (set! err-str (port->string err))))) (define err-reader (thread (λ () (set! err-str (port->string err)))))
(write-string source in) (write input in)
(flush-output in) (flush-output in)
(close-output-port in) (close-output-port in)
@ -32,7 +32,7 @@
(unless (string=? "" err-trimmed) (unless (string=? "" err-trimmed)
(error "child process raised error!" err-trimmed)) (error "child process raised error!" err-trimmed))
(unless out-str (unless out-val
(error "child process didn't return anything!")) (error "child process didn't return anything!"))
out-str) out-val)