Skip to content

Instantly share code, notes, and snippets.

@zr-tex8r
Created November 10, 2019 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zr-tex8r/f08cc9bf1f520d641382ebe9f4c30473 to your computer and use it in GitHub Desktop.
Save zr-tex8r/f08cc9bf1f520d641382ebe9f4c30473 to your computer and use it in GitHub Desktop.
1から始めるSATySFI「1SATySFi」
% 1satysfi.satyh: A kiritampo-oriented md-docuemnt class for SATySFi
%
% Copyright (c) 2019 Takayuki YATO (aka. "ZR")
% GitHub: https://github.com/zr-tex8r
% Twitter: @zr_tex8r
% Distributed under the MIT License.
@require: pervasives
@require: list
%=========================================================== module OneSaty
module OneSaty : sig
val document : 'a -> block-text -> document
direct +one : [string] block-cmd
direct +unit : [] block-cmd
direct +string : [string] block-cmd
direct +text : [inline-text] block-cmd
direct +block : [block-text] block-cmd
direct +section : [inline-text; block-text] block-cmd
direct \string : [string] inline-cmd
direct \text : [inline-text] inline-cmd
direct \block : [block-text] inline-cmd
direct \math : [math] inline-cmd
direct \link : [string; inline-text] inline-cmd
direct \image : [string; string; string] inline-cmd
direct \reference : [string; string; (string * string) option] inline-cmd
end = struct
%--------------------------------------- parameters
let paper = A4Paper
let text-origin = (20mm, 20mm)
let text-width = 170mm
let text-height = 244mm
let footer-origin = (20mm, 280mm)
let font-size-main = 14pt
let font-latin = (`Junicode`, 1., 0.)
let font-cjk = (`ipaexm`, 0.92126, 0.)
%--------------------------------------- empty elements
let-block ctx +unit = block-nil
let-block ctx +string _ = block-nil
let-block ctx +text _ = block-nil
let-block ctx +block _ = block-nil
let-block ctx +section _ _ = block-nil
let-inline ctx \string _ = inline-nil
let-inline ctx \text _ = inline-nil
let-inline ctx \block _ = inline-nil
let-inline ctx \math _ = inline-nil
let-inline ctx \link _ _ = inline-nil
let-inline ctx \image _ _ _ = inline-nil
let-inline ctx \reference _ _ _ = inline-nil
%--------------------------------------- onecode
let iota n =
let-rec iter | 0 rs = rs
| k rs = iter (k - 1) ((k - 1) :: rs) in
iter n []
let trim-empty-lines ls =
let-rec aux | [] = []
| ((l :: tls) as ls) =
if (string-length l) == 0 then aux tls else ls
in
ls |> List.reverse |> aux |> List.reverse |> aux
let x-split-into-lines s =
let spaces k =
let-rec aux sp k =
if k <= string-length s then string-sub sp 0 k
else aux (sp ^ sp) k in
aux #` `# k in
split-into-lines s |> List.map (fun (i, s) -> spaces i ^ s)
let decode-onecode stroc =
let count-ones s =
let aux k = if string-same `1` (string-sub s k 1) then 1 else 0 in
iota (string-length s) |> List.map aux |> List.fold-left (+) 0
in
stroc |> x-split-into-lines |> List.map count-ones
|> List.map (fun c -> (if (c == 13) || (c == 0) then 10 else c))
|> string-unexplode |> x-split-into-lines
|> trim-empty-lines
%let decode-onecode oc =
% split-into-lines oc |> List.map (fun (_, s) -> s)
% |> trim-empty-lines
%--------------------------------------- document
let initial-context =
get-initial-context text-width (command \math)
|> set-dominant-narrow-script Latin
|> set-dominant-wide-script Kana
|> set-font HanIdeographic font-cjk
|> set-font Kana font-cjk
|> set-font Latin font-latin
|> set-hyphen-penalty 1000
let footer pbinfo =
let itno = embed-string (arabic pbinfo#page-number) in
let ctx = initial-context in
line-break true true ctx
(inline-fil ++ read-inline ctx {#itno;} ++ inline-fil)
let-block ctx +one s =
let lines = decode-onecode s in
let ctx = initial-context in
let gather ibacc lin _ optnlin =
let ibsep = match optnlin with
| (Some _) -> inline-fil ++ mandatory-break ctx
| None -> inline-fil in
ibacc ++ read-inline ctx (embed-string lin) ++ ibsep
in
let ibcod = decode-onecode s
|> List.fold-left-adjacent gather inline-nil in
line-break true true ctx ibcod
let document _ bt =
let ctx = initial-context in
let bbmain = read-block ctx bt in
let pglayout _ = (|
text-origin = text-origin; text-height = text-height;
|) in
let pgextra pbinfo = (|
header-origin = (0pt, 0pt); header-content = block-nil;
footer-origin = footer-origin; footer-content = footer pbinfo;
|) in
page-break paper pglayout pgextra bbmain
end
%=========================================================== all done
%% EOF
{
"depends": ["1satysfi"],
"document": "OneSaty.document",
"header-default": "(| |)",
"paragraph": "+text",
"hr": "+unit",
"h1": "+section",
"h2": "+section",
"h3": "+section",
"h4": "+section",
"h5": "+section",
"h6": "+section",
"ul-inline": "+text",
"ul-block": "+block",
"ol-inline": "+text",
"ol-block": "+block",
"code-block": [],
"code-block-default": "+one",
"blockquote": "+text",
"err-block": "+string",
"emph": "\\text",
"bold": "\\text",
"hard-break": <None>,
"code": [],
"code-default": "\\string",
"url": "\\link",
"reference": "\\reference",
"img": "\\image",
"embed-block": "\\block",
"err-inline": "\\string"
}
111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111
11111111111111111111111111111111
1111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111
@zr-tex8r
Copy link
Author

インストール

  • 1satysfi.satyh$LIBROOT/dist/packages/
  • 1satysfi.satysfi-md$LIBROOT/dist/md/

$LIBROOTはライブラリルート

コンパイル

例えば、hello.1satyをコンパイルするには次のコマンドを実行する。

satysfi --markdown 1satysfi hello.1saty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment