Overview
| Comment: | beginnings of some support for captions/subtitles, excise dumb ideas from readme and fix typo, black pharaoh but this codebase needs a rewrite |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
435c29db6bd7070b43184954c64101d7 |
| User & Date: | lexi on 2024-07-17 22:21:07 |
| Other Links: | manifest | tags |
Context
|
2024-07-17
| ||
| 22:29 | cleanup check-in: d85fbc448f user: lexi tags: trunk | |
| 22:21 | beginnings of some support for captions/subtitles, excise dumb ideas from readme and fix typo, black pharaoh but this codebase needs a rewrite check-in: 435c29db6b user: lexi tags: trunk | |
| 20:10 | add missing subtitle support check-in: 362f9a6647 user: lexi tags: trunk | |
Changes
Modified cortav.ct from [4b83863e2a] to [7452348c5b].
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 |
* [*html]: emit HTML and CSS code to typeset the document. [!in progress]
* [*svg]: emit SVG, taking advantage of its precise layout features to produce a nicely formatted and paginated document. pagination can perhaps be accomplished through emitting multiple files (somewhat problematic) or by assigning one layer to each page. [!long term]
* [*groff]: the most important output backend, rivalling [*html]. will allow the document to be typeset in a wide variety of formats, including PDF and manpage. [!in progress]
* [*gemtext]: essentially a downrezzing of cortav to make it readable to Gemini clients
* [*ast]: produces a human- and/or machine-readable dump of the document's syntax tree, to aid in debugging or for interoperation with systems that do not support `cortav` direcly. mode [`ast:repr] wil allow selecting formats for the dump. [`ast:rel] can be [`tree] (the default) to emit a hierarchical representation, or [`flat] to emit an array of nodes that convey hierarchy [^flatdoc by naming one another], rather than being placed inside one another. [`tree] is easier for humans to parse; [`flat] is easier for computers. origin information can be included for each node with the flag [`ast:debug-syms], but be aware this will greatly increase file size.
** [`tabtree] [!(default)]: a hierarchical tree view, with the number of tabs preceding an item showing its depth in the tree
** [`sexp]
** [`binary]: emit a raw binary format that is easier for programs to read. maybe an lmdb or cdb file?
** [`json]: obligatory, alas
flatdoc: ~~~flat sexp example output [scheme]~~~
(nodes
(section (id . "section1")
(anchor "introduction")
(kind . "ordinary")
|
| |
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 |
* [*html]: emit HTML and CSS code to typeset the document. [!in progress]
* [*svg]: emit SVG, taking advantage of its precise layout features to produce a nicely formatted and paginated document. pagination can perhaps be accomplished through emitting multiple files (somewhat problematic) or by assigning one layer to each page. [!long term]
* [*groff]: the most important output backend, rivalling [*html]. will allow the document to be typeset in a wide variety of formats, including PDF and manpage. [!in progress]
* [*gemtext]: essentially a downrezzing of cortav to make it readable to Gemini clients
* [*ast]: produces a human- and/or machine-readable dump of the document's syntax tree, to aid in debugging or for interoperation with systems that do not support `cortav` direcly. mode [`ast:repr] wil allow selecting formats for the dump. [`ast:rel] can be [`tree] (the default) to emit a hierarchical representation, or [`flat] to emit an array of nodes that convey hierarchy [^flatdoc by naming one another], rather than being placed inside one another. [`tree] is easier for humans to parse; [`flat] is easier for computers. origin information can be included for each node with the flag [`ast:debug-syms], but be aware this will greatly increase file size.
** [`tabtree] [!(default)]: a hierarchical tree view, with the number of tabs preceding an item showing its depth in the tree
** [`sexp]
** [`binary]: emit a raw binary format that is easier for programs to read. maybe a msgpack file?
** [`json]: obligatory, alas
flatdoc: ~~~flat sexp example output [scheme]~~~
(nodes
(section (id . "section1")
(anchor "introduction")
(kind . "ordinary")
|
Modified cortav.lua from [76257c7c34] to [f6f6b80f21].
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
....
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
|
if l:sub(1,1) == '.' then l = l:sub(2) end
return {
kind = "paragraph";
spans = ct.parse_span(l, c);
}
end)
local insert_subtitle = blockwrap(function(l,c)
return {
kind = "subtitle";
spans = ct.parse_span(l:sub(3), c);
}
end)
local function
insert_section(skind) return function(l,c,j)
local depth, id, t = l:match '^([#§^]+)([^%s]*)%s*(.-)$'
if id and id ~= "" then
if c.doc.sections[id] then
................................................................................
ct.ctlseqs = {
{seq = '.', fn = insert_paragraph};
{seq = '¶', fn = insert_paragraph};
{seq = '❡', fn = insert_paragraph};
{seq = '#', fn = insert_section()};
{seq = '§', fn = insert_section()};
{seq = '^', fn = insert_section 'namespace'};
{seq = '--',fn = insert_subtitle};
{seq = '+', fn = insert_table_row};
{seq = '|', fn = insert_table_row};
{seq = '│', fn = insert_table_row};
{seq = '!', fn = function(l,c,j,d)
local last = d[#d]
local txt = l:match '^%s*!%s*(.-)$'
if (not last) or last.kind ~= 'aside' then
|
|
|
>
>
>
>
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
....
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
|
if l:sub(1,1) == '.' then l = l:sub(2) end
return {
kind = "paragraph";
spans = ct.parse_span(l, c);
}
end)
local insert_caption = blockwrap(function(l,c,j,d)
if next(d) == nil then
c:fail 'subtitle in an unlabeled section is meaningless'
end
local last = d[#d]
local me = {
kind = 'subtitle';
spans = ct.parse_span(l:sub(3):gsub("^%s+",""), c);
}
local captionable = {
quote=true, aside=true,
table=true, code=true,
embed=true, link=true,
}
if last.kind == 'label' then
me.attach = last;
elseif last.kind == 'subtitle' then
me.attach = last.attach;
elseif captionable[last.kind] then
me.kind = 'label'
me.captions = last
last.label_node = me
else
c:fail 'subtitle/attribution syntax in improper context'
end
return me
end)
local function
insert_section(skind) return function(l,c,j)
local depth, id, t = l:match '^([#§^]+)([^%s]*)%s*(.-)$'
if id and id ~= "" then
if c.doc.sections[id] then
................................................................................
ct.ctlseqs = {
{seq = '.', fn = insert_paragraph};
{seq = '¶', fn = insert_paragraph};
{seq = '❡', fn = insert_paragraph};
{seq = '#', fn = insert_section()};
{seq = '§', fn = insert_section()};
{seq = '^', fn = insert_section 'namespace'};
{seq = '--',fn = insert_caption};
{seq = '+', fn = insert_table_row};
{seq = '|', fn = insert_table_row};
{seq = '│', fn = insert_table_row};
{seq = '!', fn = function(l,c,j,d)
local last = d[#d]
local txt = l:match '^%s*!%s*(.-)$'
if (not last) or last.kind ~= 'aside' then
|
Modified render/groff.lua from [599907d26e] to [b6c7f1e8a6].
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 ... 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 ... 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 ... 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
sreq = function(me, r)
me:flush()
table.insert(me.lines, "'"..r)
end;
esc = function(me, e)
me:raw('\\' .. e)
end;
draw = function(me, args)
for _,v in ipairs(args) do
me:esc("D'" .. v .. "'")
end
end;
flush = function(me)
if me.linbuf ~= nil then
local line = me.linbuf:compile()
local first = line:sub(1,1)
-- make sure our lines aren't accidentally interpreted
-- as groff requests. groff is kinda hostile to script
-- generation, huh?
................................................................................
end
local blockRenderers = {}
blockRenderers['horiz-rule'] = function(rc, b, sec)
rc.prop.margin = { top = 0.3 }
rc.prop.underline = 0.1
end
function blockRenderers.label(rc, b, sec)
if ct.sec.is(b.captions) then
local visDepth = b.captions.depth + (b.origin.docDepth or 0)
local sizes = {36,24,12,8,4,2}
local margins = {0,3}
local dedents = {2.5,1.3,0.8,0.4}
local uls = {3,1.5,0.5,0.25}
rc.prop.dsz = sizes[visDepth] or 10
................................................................................
rc.prop.breakBefore = true
end
rs.renderSpans(rc, b.spans, b, sec)
else
ss.bug 'tried to render label for an unknown object type':throw()
end
end
function blockRenderers.paragraph(rc, b, sec)
rs.renderSpans(rc, b.spans, b, sec)
end
function blockRenderers.macro(rc, b, sec)
local rc = rc.parent:clone()
rs.renderDoc(rc, b.doc)
end
function blockRenderers.quote(rc, b, sec)
local rc = rc.parent:clone()
rc.prop.indent = (rc.prop.indent or 0) + 1
local added = rs.renderDoc(rc, b.doc)
-- select last block of last section and increase bottom margin
local ap = added[#added].blocks
ap = ap[#ap].prop
if ap.margin then
................................................................................
else
ap.margin.bottom = 1.1
end
else
ap.margin = {bottom = 1.1}
end
end
function blockRenderers.table(rc, b, sec)
function rc:begin(g)
g:req 'TS'
local aligns = {}
for i, c in ipairs(b.rows[1]) do
aligns[i] = ({
left = 'l';
center = 'c';
|
| | | | | | > > > > > | | | |
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 ... 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 ... 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 ... 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
sreq = function(me, r)
me:flush()
table.insert(me.lines, "'"..r)
end;
esc = function(me, e)
me:raw('\\' .. e)
end;
draw = function(me, args)
for _,v in ipairs(args) do
me:esc("D'" .. v .. "'")
end
end;
flush = function(me)
if me.linbuf ~= nil then
local line = me.linbuf:compile()
local first = line:sub(1,1)
-- make sure our lines aren't accidentally interpreted
-- as groff requests. groff is kinda hostile to script
-- generation, huh?
................................................................................
end
local blockRenderers = {}
blockRenderers['horiz-rule'] = function(rc, b, sec)
rc.prop.margin = { top = 0.3 }
rc.prop.underline = 0.1
end
function blockRenderers.label(rc, b, sec)
if ct.sec.is(b.captions) then
local visDepth = b.captions.depth + (b.origin.docDepth or 0)
local sizes = {36,24,12,8,4,2}
local margins = {0,3}
local dedents = {2.5,1.3,0.8,0.4}
local uls = {3,1.5,0.5,0.25}
rc.prop.dsz = sizes[visDepth] or 10
................................................................................
rc.prop.breakBefore = true
end
rs.renderSpans(rc, b.spans, b, sec)
else
ss.bug 'tried to render label for an unknown object type':throw()
end
end
function blockRenderers.paragraph(rc, b, sec)
rs.renderSpans(rc, b.spans, b, sec)
end
function blockRenderers.subtitle(rc, b, sec)
rc.prop.dsz = 16 -- TODO base on "parent" label
rc.prop.emph = true
rs.renderSpans(rc, b.spans, b, sec)
end
function blockRenderers.macro(rc, b, sec)
local rc = rc.parent:clone()
rs.renderDoc(rc, b.doc)
end
function blockRenderers.quote(rc, b, sec)
local rc = rc.parent:clone()
rc.prop.indent = (rc.prop.indent or 0) + 1
local added = rs.renderDoc(rc, b.doc)
-- select last block of last section and increase bottom margin
local ap = added[#added].blocks
ap = ap[#ap].prop
if ap.margin then
................................................................................
else
ap.margin.bottom = 1.1
end
else
ap.margin = {bottom = 1.1}
end
end
function blockRenderers.table(rc, b, sec)
function rc:begin(g)
g:req 'TS'
local aligns = {}
for i, c in ipairs(b.rows[1]) do
aligns[i] = ({
left = 'l';
center = 'c';
|
Modified render/html.lua from [e689cbb41c] to [e178fd542c].
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 ... 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 .... 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 .... 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 .... 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 |
subtitle = [[
.subtitle {
color: @tone(0.3 20);
font-size: 1.2em;
font-style: italic;
margin-left: 1em;
}
blockquote + .subtitle {
&::before {
content: "— ";
}
}
]];
accent = [[
@media screen {
body { background: @bg; color: @fg }
a[href] {
color: @tone(0.7 30);
text-decoration-color: @tone/0.4(0.7 30);
................................................................................
}
section > aside p:first-child {
margin: 0;
}
section aside + aside {
margin-top: 0.5em;
}
]];
code = [[
code {
display: inline-block;
background: @tone(-1);
color: @tone(0.7);
font-family: monospace;
font-size: 90%;
................................................................................
return htmlURI(s.uri)
elseif s.mode == 'embed' then
local mime = s.mime:clone()
mime.opts = {}
return string.format('data:%s;base64,%s', mime, ss.str.b64e(s.raw))
end
end
--figure out how to embed the given object
local function P(p) -- get prop
if b.props and b.props[p] then
return b.props[p]
end
return obj.props[p]
end
local embedActs = {
{ss.mime'image/*', function(s,ctr)
if s == nil then
return {tag = "picture", nodes = {}}
else
local uri = uriForSource(s)
local fbimg, idx
................................................................................
goto compatFound
end
end
end
-- nothing found; install fallback link
if fallback then
local lnk = htmlURI(fallback.uri)
return tag('a', {href=lnk},
tag('div',{class=xref},
string.format("→ %s [%s]", b.cap or '', tostring(fallback.mime))))
else
addStyle 'docmeta'
return tag('div',{class="render-warn"},
'could not embed object type ' .. tostring(obj.srcs.mime))
end
::compatFound::
................................................................................
local top = rtype[2]() -- create container
for n, src in ipairs(obj.srcs) do
if rtype[1] < src.mime then
rtype[2](src, top)
end
end
local ft = flatten(top)
local cap = b.cap or P'desc' or P'detail'
if b.mode == 'inline' then
-- TODO insert caption
return ft
else
local prop = {}
if b.mode == 'open' then
prop.open = true
end
return tag('details', prop, catenate {
tag('summary', {},
cap and (
-- the block here should really be the relevant
-- ref definition if an override caption isn't
-- specified, but oh well
sr.htmlSpan(spanparse(
cap, b.origin
), b, s)
) or '');
ft;
})
end
end
function block_renderers.macro(b,s)
local all = renderSubdoc(b.doc)
local cat = catenate(ss.map(flatten,all))
return tag(nil, {}, cat)
end
function block_renderers.quote(b,s)
local ir = renderSubdoc(b.doc)
return tag('blockquote', b.id and {id=getSafeID(b)} or {}, catenate(ss.map(flatten,ir)))
end
return block_renderers
end
local function getRenderers(procs)
|
< < < < < | > > > > > > > > > < > > > > > > > > > > > > > > > > | | > | > < | < < < < < < < < > > > > > |
259 260 261 262 263 264 265 266 267 268 269 270 271 272 ... 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 .... 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 .... 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 .... 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 |
subtitle = [[
.subtitle {
color: @tone(0.3 20);
font-size: 1.2em;
font-style: italic;
margin-left: 1em;
}
]];
accent = [[
@media screen {
body { background: @bg; color: @fg }
a[href] {
color: @tone(0.7 30);
text-decoration-color: @tone/0.4(0.7 30);
................................................................................
}
section > aside p:first-child {
margin: 0;
}
section aside + aside {
margin-top: 0.5em;
}
]];
quoteCaption = [[
blockquote > div.caption {
text-align: right;
font-style: italic;
&::before {
content: "— ";
}
}
]];
code = [[
code {
display: inline-block;
background: @tone(-1);
color: @tone(0.7);
font-family: monospace;
font-size: 90%;
................................................................................
return htmlURI(s.uri)
elseif s.mode == 'embed' then
local mime = s.mime:clone()
mime.opts = {}
return string.format('data:%s;base64,%s', mime, ss.str.b64e(s.raw))
end
end
local function P(p) -- get prop
if b.props and b.props[p] then
return b.props[p]
end
return obj.props[p]
end
local cap = b.cap or P'desc' or P'detail'
local capIR = '';
if b.label_node then
local ln = b.label_node
capIR = sr.htmlSpan(ln.spans, ln, s)
elseif cap then
-- the block here should really be the relevant
-- ref definition if an override caption isn't
-- specified, but oh well
capIR = sr.htmlSpan(spanparse(
cap, b.origin
), b, s)
end
--figure out how to embed the given object
local embedActs = {
{ss.mime'image/*', function(s,ctr)
if s == nil then
return {tag = "picture", nodes = {}}
else
local uri = uriForSource(s)
local fbimg, idx
................................................................................
goto compatFound
end
end
end
-- nothing found; install fallback link
if fallback then
local lnk = htmlURI(fallback.uri)
return tag('a', {href=lnk}, catenate {
tag('div',{class=xref}, catenate {
'→ '; capIR;
string.format(" [%s]", tostring(fallback.mime));
})})
else
addStyle 'docmeta'
return tag('div',{class="render-warn"},
'could not embed object type ' .. tostring(obj.srcs.mime))
end
::compatFound::
................................................................................
local top = rtype[2]() -- create container
for n, src in ipairs(obj.srcs) do
if rtype[1] < src.mime then
rtype[2](src, top)
end
end
local ft = flatten(top)
if b.mode == 'inline' then
-- TODO insert caption
return ft
else
local prop = {}
if b.mode == 'open' then
prop.open = true
end
return tag('details', prop, catenate {
tag('summary', {}, capIR);
ft;
})
end
end
function block_renderers.macro(b,s)
local all = renderSubdoc(b.doc)
local cat = catenate(ss.map(flatten,all))
return tag(nil, {}, cat)
end
function block_renderers.quote(b,s)
local ir = renderSubdoc(b.doc)
if b.label_node then
addStyle 'quoteCaption'
table.insert(ir, tag('div', {class='caption'},
sr.htmlSpan(b.label_node.spans, b.label_node, s)))
end
return tag('blockquote', b.id and {id=getSafeID(b)} or {}, catenate(ss.map(flatten,ir)))
end
return block_renderers
end
local function getRenderers(procs)
|