Differences From
Artifact [f159ef53c2]:
611 611 end
612 612
613 613 function span_renderers.raw(v,b,s)
614 614 return htmlSpan(v.spans, b, s)
615 615 end
616 616
617 617 function span_renderers.link(sp,b,s)
618 + local dest_o, _, dest_s = b.origin:ref(sp.ref)
618 619 local href
619 - if b.origin.doc.sections[sp.ref] then
620 - href = '#' .. getSafeID(sp)
620 + if dest_o == nil then
621 + -- link is to the section itself
622 + href = '#' .. getSafeID(dest_s)
621 623 else
622 - if sp.addr then href = sp.addr else
623 - local r = b.origin:ref(sp.ref)
624 - if type(r) == 'table' then
625 - href = '#' .. getSafeID(r)
626 - else href = r end
624 +-- if sp.addr then href = sp.addr else
625 + if type(dest_o) == 'table' then
626 + href = '#' .. getSafeID(dest_o)
627 + else -- URI in reference
628 + local uri = ss.uri(dest_o)
629 + if uri.class[1] == 'file'
630 + or uri.class[1] == 'asset' then
631 + if uri.namespace == 'localhost' then
632 + -- emit an actual file url
633 + href = 'file://' .. uri:construct('path','frag')
634 + elseif uri.namespace == nil then
635 + -- this is gonna be tricky. first we establish the location
636 + -- of the CWD/asset base relative to the output file (if any;
637 + -- assume equivalent otherwise) then express the difference
638 + -- as a directory prefix.
639 + -- jk tho for now we just emit the path+frag sadlol TODO
640 + href = uri:construct('path','frag')
641 + else
642 + b.origin:fail('file: URI namespace must be empty or “localhost” for HTML links; others are not meaningful (offending URI: “%s”)', dest_o)
643 + end
644 + elseif uri:canfetch() == 'http' then
645 + local sc = 'http'
646 + if uri.class[1] == 'https' or uri.class[2] == 'tls' then
647 + sc = 'https'
648 + end
649 + if uri.namespace == nil and uri.auth == nil and uri.svc == nil then
650 + -- omit the scheme so we can use a relative path
651 + href = uri:construct('path','query','frag')
652 + else
653 + uri.class = {sc}
654 + href = tostring(uri)
655 + end
656 + else href = tostring(uri) end
627 657 end
628 658 end
629 659 return tag('a',{href=href},next(sp.spans) and htmlSpan(sp.spans,b,s) or href)
630 660 end
631 661
632 662 span_renderers['line-break'] = function(sp,b,s)
633 663 return elt('br')