cortav  Diff

Differences From Artifact [78b49cf252]:

To Artifact [8ab06e9795]:


401
402
403
404
405
406
407








































408
409
410
411
412
413
414
...
447
448
449
450
451
452
453


















































454
455
456
457
458
459
460
...
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
...
773
774
775
776
777
778
779












780
781
782
783
784
785
786
...
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
			h1 {
				page-break-before: always;
			}
			h1,h2,h3,h4,h5,h6 {
				page-break-after: avoid;
			}
		]];








































	}

	local stylesNeeded = {
		flags = {};
		order = {};
	}
	local function addStyle(sty)
................................................................................

	local renderJob = doc:job('render_html', nil, render_state_handle)
	doc.stage.job = renderJob;

	local runhook = function(h, ...)
		return renderJob:hook(h, render_state_handle, ...)
	end



















































	local tagproc do
		local html_open = function(t,attrs)
			if attrs then
				return t .. ss.reduce(function(a,b) return a..b end, '',
					ss.map(function(v,k)
						if v == true
................................................................................
		end

		function span_renderers.raw(v,b,s)
			return htmlSpan(v.spans, b, s)
		end

		function span_renderers.link(sp,b,s)
			local dest_o, _, dest_s = b.origin:ref(sp.ref)
			local href
			if dest_o == nil then
				-- link is to the section itself
				href = '#' .. getSafeID(dest_s)
			else
-- 				if sp.addr then href = sp.addr else
				if type(dest_o) == 'table' then
					href = '#' .. getSafeID(dest_o)
				else -- URI in reference
					local uri = ss.uri(dest_o)
					if uri.class[1] == 'file'
					or uri.class[1] == 'asset' then
						if uri.namespace == 'localhost' then
							-- emit an actual file url
							href = 'file://' .. uri:construct('path','frag')
						elseif uri.namespace == nil then
							-- this is gonna be tricky. first we establish the location
							-- of the CWD/asset base relative to the output file (if any;
							-- assume equivalent otherwise) then express the difference
							-- as a directory prefix.
							-- jk tho for now we just emit the path+frag sadlol TODO
							href = uri:construct('path','frag')
						else
							b.origin:fail('file: URI namespace must be empty or “localhost” for HTML links; others are not meaningful (offending URI: “%s”)', dest_o)
						end
					elseif uri:canfetch() == 'http' then
						local sc = 'http'
						if uri.class[1] == 'https' or uri.class[2] == 'tls' then
							sc = 'https'
						end
						if uri.namespace == nil and uri.auth == nil and uri.svc == nil then
							-- omit the scheme so we can use a relative path
							href = uri:construct('path','query','frag')
						else
							uri.class = {sc}
							href = tostring(uri)
						end
					else href = tostring(uri) end
				end
			end
			return tag('a',{href=href},next(sp.spans) and htmlSpan(sp.spans,b,s) or href)
		end

		span_renderers['line-break'] = function(sp,b,s)
			return elt('br')
		end

		function span_renderers.macro(m,b,s)
................................................................................
				else
					-- handle other uses of labels here
				end
			end;
			['list-item'] = function(b,s)
				return tag('li', nil, sr.htmlSpan(b.spans, b, s), b)
			end;












			table = function(b,s)
				local tb = {}
				for i, r in ipairs(b.rows) do
					local row = {}
					for i, c in ipairs(r) do
						table.insert(row, tag(c.header and 'th' or 'td',
						{align=c.align}, sr.htmlSpan(c.spans, b)))
................................................................................

		function block_renderers.embed(b,s)
			local obj
			if b.rsrc
				then obj = b.rsrc
				else obj = b.origin:ref(b.ref)
			end
			local function htmlURI(u)
				local family = u:canfetch()
				if  family == 'file' or
					(family == 'http' and u.namespace == nil) then
					-- TODO asset:
					return u.path
				else
					return tostring(u)
				end
			end
			local function uriForSource(s)
				if s.mode == 'link' or s.mode == 'auto' then
					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))







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|







 







>
>
>
>
>
>
>
>
>
>
>
>







 







<
<
<
<
<
<
<
<
<
<







401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
...
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
...
701
702
703
704
705
706
707

708







































709
710
711
712
713
714
715
716
...
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
...
925
926
927
928
929
930
931










932
933
934
935
936
937
938
			h1 {
				page-break-before: always;
			}
			h1,h2,h3,h4,h5,h6 {
				page-break-after: avoid;
			}
		]];
		linkBlock = [[
			a[href].link {
				position: relative;
				display: block;
				padding: .5em;
				padding-right: 1.5em;
				border: 1px solid @tone(0.2 30);
				background: @tone(0.05 30);
				font-size: 1.1em;
				margin: 0 1em;
				text-decoration: none;
				color: @tone(0.8 30);
			}
			a[href].link + a[href].link {
				margin-top: -1px;
			}
			a[href].link:hover {
				border-color: @tone(0.3 30);
				background: @tone(0.2 30);
				color: @tone(0.95 30);
			}
			a[href].link:hover + a[href].link {
				margin-top: 0;
				border-top: none;
			}
			a[href].link::after {
				display: block;
				position: absolute;
				right: .5em;
				content: "→";
				top: 50%;
				margin-left: 1em;
				font-size: 1.8em;
				transform: translateY(-50%);
				color: @tone(0.3 30);
			}
			a[href].link:hover::after {
				color: @tone(0.7 30);
			}
		]];
	}

	local stylesNeeded = {
		flags = {};
		order = {};
	}
	local function addStyle(sty)
................................................................................

	local renderJob = doc:job('render_html', nil, render_state_handle)
	doc.stage.job = renderJob;

	local runhook = function(h, ...)
		return renderJob:hook(h, render_state_handle, ...)
	end

	local function htmlURI(uri)
		local family = uri:canfetch()
		if family == 'file' then
			if uri.namespace == 'localhost' then
				-- emit an actual file url
				return 'file://' .. uri:construct('path','frag')
			elseif uri.namespace == nil then
				-- this is gonna be tricky. first we establish the location
				-- of the CWD/asset base relative to the output file (if any;
				-- assume equivalent otherwise) then express the difference
				-- as a directory prefix.
				-- jk tho for now we just emit the path+frag sadlol TODO
				if uri.path == nil and uri.frag then
					-- file:#sec links to #sec within the current document
					return uri:part 'frag'
				else
					return uri:construct('path','frag')
				end
			else
				b.origin:fail('file: URI namespace must be empty or “localhost” for HTML links; others are not meaningful (offending URI: “%s”)', uri.raw)
			end
		elseif family == 'http' then
			local sc = 'http'
			if uri.class[1] == 'https' or uri.class[2] == 'tls' then
				sc = 'https'
			end
			if uri.namespace == nil and uri.auth == nil and uri.svc == nil then
				-- omit the scheme so we can use a relative path
				return uri:construct('path','query','frag')
			else
				uri.class = {sc}
				return tostring(uri)
			end
		else return tostring(uri) end
	end

	local function idLink(id,b)
		local dest_o, _, dest_s = b.origin:ref(id)
		if dest_o == nil then
			-- link is to the section itself
			return '#' .. getSafeID(dest_s)
		else
			if type(dest_o) == 'table' then
				return '#' .. getSafeID(dest_o)
			else -- URI in reference
				return htmlURI(ss.uri(dest_o))
			end
		end
	end

	local tagproc do
		local html_open = function(t,attrs)
			if attrs then
				return t .. ss.reduce(function(a,b) return a..b end, '',
					ss.map(function(v,k)
						if v == true
................................................................................
		end

		function span_renderers.raw(v,b,s)
			return htmlSpan(v.spans, b, s)
		end

		function span_renderers.link(sp,b,s)

			local href = idLink(sp.ref,b)







































			return tag('a',{href=href}, next(sp.spans) and htmlSpan(sp.spans,b,s) or href)
		end

		span_renderers['line-break'] = function(sp,b,s)
			return elt('br')
		end

		function span_renderers.macro(m,b,s)
................................................................................
				else
					-- handle other uses of labels here
				end
			end;
			['list-item'] = function(b,s)
				return tag('li', nil, sr.htmlSpan(b.spans, b, s), b)
			end;
			link = function(b,s)
				addStyle 'linkBlock'
				local href
				if b.uri then
					href = htmlURI(b.uri)
				elseif b.ref then
					href = idLink(b.ref, b)
				end
				local sp = sr.htmlSpan(b.spans, b, s)
				return tag('div', {},
					catenate{tag('a',{class='link', href=href},sp)})
			end;
			table = function(b,s)
				local tb = {}
				for i, r in ipairs(b.rows) do
					local row = {}
					for i, c in ipairs(r) do
						table.insert(row, tag(c.header and 'th' or 'td',
						{align=c.align}, sr.htmlSpan(c.spans, b)))
................................................................................

		function block_renderers.embed(b,s)
			local obj
			if b.rsrc
				then obj = b.rsrc
				else obj = b.origin:ref(b.ref)
			end










			local function uriForSource(s)
				if s.mode == 'link' or s.mode == 'auto' then
					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))