cortav  Check-in [84b6c875fb]

Overview
Comment:"fix" macro bullshit
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 84b6c875fb1e61e1abeef0b4338e9e1cfb52b577b9fb4b5923a70cda5695155f
User & Date: lexi on 2022-09-30 18:57:32
Other Links: manifest | tags
Context
2022-09-30
20:15
let the flayings commence check-in: 89a6dd28ef user: lexi tags: trunk
18:57
"fix" macro bullshit check-in: 84b6c875fb user: lexi tags: trunk
2022-09-14
12:22
various improvements check-in: dd5c3bfcb9 user: lexi tags: trunk
Changes

Modified cortav.lua from [2184d83e7b] to [ea1fbe20dd].

   449    449   	fns = {
   450    450   		fork = function(me, name, pred, ...)
   451    451   			-- generate a branch job linked to this job
   452    452   			local branch = getmetatable(me)(name, me.doc, pred, ...)
   453    453   			branch.parent = me
   454    454   			return branch
   455    455   		end;
   456         -		delegate = function(me, ext) -- creates a delegate for state access
          456  +		delegate = function(me, ext) -- creates a delegate for hierarchical state access
   457    457   			local submethods = {
   458    458   				unwind = function(self, n)
   459    459   					local function
   460    460   					climb(dlg, job, n)
   461    461   						if n == 0 then
   462    462   							return job:delegate(dlg.extension)
   463    463   						else
................................................................................
   485    485   					return D.target[key]
   486    486   				end;
   487    487   				__newindex = function(self, key, value)
   488    488   					local D = self._delegate_state
   489    489   					if key == 'state' then
   490    490   						D.target.states[D.extension] = value
   491    491   					else
   492         -						D.target[D.extension] = value
          492  +						D.target[D.extension] = value -- FIXME?? is this right???
   493    493   					end
   494    494   				end;
   495         -			});
   496         -			return d;
          495  +			})
          496  +			return d
   497    497   		end;
   498    498   		each = function(me, ...)
   499    499   			local ek
   500    500   			local path = {...}
   501    501   			return function()
   502    502   				while true do
   503    503   					ek = next(me.states, ek)
................................................................................
   611    611   -- objects, including ones that users have not assigned IDs
   612    612   -- to, and objects with the same name in different unlabeled
   613    613   -- sections. to handle this, we provide a "namespace" mechanism,
   614    614   -- where some lua table (really its address in memory) is used
   615    615   -- as a handle for the object and a unique ID is attached to it.
   616    616   -- if the object has an ID of its own, it is guaranteed to be
   617    617   -- unique and returned; otherwise, a generic id of the form
   618         --- `x-%u` is generated, where %u is an integer that increments
          618  +-- `x-%u` is generated, where %u is an integer that incrementsfile:///home/lexi/dev/cortav/build/cortav.html
   619    619   -- for every new object
   620    620   	local ids = {}
   621    621   	local canonicalID = {}
   622    622   	return function(obj,pfx)
   623    623   		pfx = pfx or ''
   624    624   		if canonicalID[obj] then
   625    625   			return canonicalID[obj]
................................................................................
   754    754   			code = cp;
   755    755   		}
   756    756   	end
   757    757   	ct.spanctls = {
   758    758   		{seq = '!', parse = formatter 'emph'};
   759    759   		{seq = '*', parse = formatter 'strong'};
   760    760   		{seq = '~', parse = formatter 'strike'};
          761  +		{seq = '_', parse = formatter 'underline'};
   761    762   		{seq = '+', parse = formatter 'insert'};
   762    763   		{seq = '\\', parse = function(s, c) -- raw
   763    764   			return {
   764    765   				kind = 'raw';
   765    766   				spans = {s};
   766    767   				origin = c:clone();
   767    768   			}
   768    769   		end};
   769    770   		{seq = '`', parse = formatter 'literal'};
   770    771   		{seq = '"', parse = rawcode};
   771    772   		{seq = '$', parse = formatter 'variable'};
          773  +		{seq = "'", parse = formatter 'super'};
          774  +		{seq = ',', parse = formatter 'sub'};
   772    775   		{seq = '^', parse = function(s, c)
   773    776   		-- TODO support for footnote sections
   774    777   			local fn, t = s:match '^([^%s]+)%s*(.-)$'
   775    778   			return {
   776    779   				kind = 'footnote';
   777    780   				spans = (t and t~='') and ct.parse_span(t, c) or {};
   778    781   				ref = fn;
   779    782   				origin = c:clone();
   780    783   			}
   781    784   		end};
   782    785   		{seq = '=', parse = function(s,c) --math mode
   783         -			local tx = {
   784         -				['%*'] = '×';
   785         -				['/'] = '÷';
   786         -			}
   787         -			for k,v in pairs(tx) do s = s:gsub(k,v) end
   788         -			s=s:gsub('%^([0-9]+)', function(num)
   789         -				local sup = {'⁰','¹','²','³','⁴','⁵','⁶','⁷','⁸','⁹'};
   790         -				local r = ''
   791         -				for i=1,#num do
   792         -					r = r .. sup[1 + (num:byte(i) - 0x30)]
          786  +			if c.doc.enc ~= ss.str.enc.ascii then
          787  +				for _,v in pairs(ss.compseq.math) do
          788  +					local seq, utf8, html, cp = table.unpack(v)
          789  +					seq = seq:gsub('[-+.*?[%]%%]', '%%%0') -- >_<
          790  +					s = s:gsub(seq,c.doc.enc.encodeUCS(utf8))
   793    791   				end
   794         -				return r
   795         -			end)
          792  +			end
          793  +-- 			s=s:gsub('%^([0-9]+)', function(num)
          794  +-- 				local sup = {'⁰','¹','²','³','⁴','⁵','⁶','⁷','⁸','⁹'};
          795  +-- 				local r = ''
          796  +-- 				for i=1,#num do
          797  +-- 					r = r .. sup[1 + (num:byte(i) - 0x30)]
          798  +-- 				end
          799  +-- 				return r
          800  +-- 			end)
   796    801   			local m = {s} --TODO
   797    802   			return {
   798    803   				kind = 'math';
   799    804   				original = s;
   800    805   				spans = {s};
   801    806   				origin = c:clone();
   802    807   			};

Modified ext/transmogrify.lua from [ad59e4c740] to [b92020d7d8].

    20     20   			['<->'] = '↔';
    21     21   			['-->'] = '→';
    22     22   			['<--'] = '←';
    23     23   			['==>'] = '⇒';
    24     24   			['<=>'] = '⇔';
    25     25   			['<=='] = '⇐';
    26     26   			['=/='] = '≠';
           27  +			['::='] = '⩴';
           28  +			[':='] = '≔';
    27     29   			['---'] = '⸺';
    28     30   		};
    29     31   
    30     32   		{
    31     33   			['-:-'] = '÷';
    32     34   			['--'] = '—';
    33     35   			['(C)'] = '©';
................................................................................
   138    140   ct.ext.install {
   139    141   	id = 'transmogrify';
   140    142   	version = ss.version {0,1; 'devel'};
   141    143   	contributors = {{name='lexi hale', handle='velartrill', mail='lexi@hale.su', homepage='https://hale.su'}};
   142    144   	default = true; -- on unless inhibited
   143    145   	slow = true;
   144    146   	hook = {
          147  +		doc_macro_expand_span = function(job, ir, block)
          148  +			enterspan(block.origin, ir)
          149  +		end;
   145    150   		doc_meddle_ast = function(job)
   146    151   			for n, sec in pairs(job.doc.secorder) do
   147    152   				if sec.kind=='ordinary' or sec.kind=='quote'
   148    153   				or sec.kind=='footnote' then
   149    154   					for i, block in pairs(sec.blocks) do
   150    155   			         if type(block.spans) == 'table' then
   151    156   							enterspan(block.origin, block.spans)

Modified render/groff.lua from [810c155515] to [729b875cf0].

   392    392   
   393    393   		local r = b.origin:ref(macroname)
   394    394   		if type(r) ~= 'string' then
   395    395   			b.origin:fail('%s is an object, not a reference', t.ref)
   396    396   		end
   397    397   		local mctx = b.origin:clone()
   398    398   		      mctx.invocation = m
   399         -		rs.renderSpans(rc, ct.parse_span(r, mctx))
          399  +
          400  +		local ir = ct.parse_span(r, mctx)
          401  +		local j = b.origin.doc.docjob
          402  +		for fn, ext, state in j:each('hook', 'doc_macro_expand_span') do
          403  +			local r = fn(j:delegate(ext), ir, b)
          404  +			if r then ir = r end
          405  +		end
          406  +		rs.renderSpans(rc, ir)
   400    407   	end
   401    408   
   402    409   	function rs.renderSpans(rc, sp, b, sec)
   403    410   		rc = rc or mkrc(b.origin)
   404    411   		for i, v in ipairs(sp) do
   405    412   			if type(v) == 'string' then
   406    413   				rc:span(v)

Modified render/html.lua from [f4ce452531] to [05c1f2d6b4].

   684    684   	local function getSpanRenderers(procs)
   685    685   		local tag, elt, catenate = procs.tag, procs.elt, procs.catenate
   686    686   		local span_renderers = {}
   687    687   		local plainrdr = getBaseRenderers(tagproc.toTXT, span_renderers)
   688    688   		local htmlSpan = getBaseRenderers(procs, span_renderers).htmlSpan
   689    689   
   690    690   		function span_renderers.format(sp,...)
   691         -			local tags = { strong = 'strong', emph = 'em', strike = 'del', insert = 'ins', literal = 'code', variable = 'var'}
          691  +			local tags = {
          692  +				strong = 'strong';
          693  +				emph = 'em';
          694  +				strike = 'del';
          695  +				insert = 'ins';
          696  +				literal = 'code';
          697  +				variable = 'var';
          698  +				super = 'sup';
          699  +				sub = 'sub';
          700  +				underline = 'u';
          701  +			}
   692    702   			if sp.style == 'literal' and not opts['fossil-uv'] then
   693    703   				addStyle 'code'
   694    704   			elseif sp.style == 'strike' or sp.style == 'insert' then
   695    705   				addStyle 'editors_markup'
   696    706   			elseif sp.style == 'variable' then
   697    707   				addStyle 'var'
   698    708   			end
................................................................................
   764    774   				ct.parse_span(m.macro, b.origin), b,s)
   765    775   			local r = b.origin:ref(macroname)
   766    776   			if type(r) ~= 'string' then
   767    777   				b.origin:fail('%s is an object, not a reference', r.id)
   768    778   			end
   769    779   			local mctx = b.origin:clone()
   770    780   			mctx.invocation = m
   771         -			return htmlSpan(ct.parse_span(r, mctx),b,s)
          781  +			local ir = ct.parse_span(r, mctx)
          782  +			-- even though this happens at render time, it really shouldn't;
          783  +			-- we pretend this is happening as part of the document job
          784  +			local j = b.origin.doc.docjob
          785  +			for fn, ext, state in j:each('hook', 'doc_macro_expand_span') do
          786  +				local r = fn(j:delegate(ext), ir, b)
          787  +				if r then ir = r end
          788  +			end
          789  +			return htmlSpan(ir, b, s)
   772    790   		end
   773    791   		function span_renderers.math(m,b,s)
   774    792   			addStyle 'math'
   775    793   			local spans = {}
   776    794   			local function fmt(sp, target)
   777    795   				for i,v in ipairs(sp) do
   778    796   					if type(v) == 'string' then

Modified sirsem.lua from [c72ad0a8fc] to [7e67a3ff12].

  1639   1639   				end
  1640   1640   			end
  1641   1641   			return c == pc
  1642   1642   		end;
  1643   1643   	};
  1644   1644   }
  1645   1645   ss.mime.exn = ss.exnkind 'MIME error'
         1646  +
         1647  +
         1648  +-- a composition table maps from a compose sequence to the tuple
         1649  +-- {UTF8, htmlentity, UCS codepoint}
         1650  +ss.compseq = {
         1651  +	math = {
         1652  +		{'*', '×', 'times', 0x2A2F};
         1653  +		{'/', '÷', 'divide', 0x00F7};
         1654  +		{'-', '−', 'minus', 0x2212};
         1655  +		{'+-', '±', 'plusmn', 0x00B1};
         1656  +		{'&&', '∧', 'and', 0x2227};
         1657  +		{'||', '∨', 'or', 0x2228};
         1658  +		{'&', '⋏', nil, 0x22CF};
         1659  +		{'|', '⋎', nil, 0x22CE};
         1660  +		{'~', '¬', 'not', 0x00AC};
         1661  +		{'~=', '≠', 'ne', 0x2260};
         1662  +		{'^=', '≜', 'trie', 0x225C};
         1663  +		{':=', '≔', 'coloneq', 0x2254};
         1664  +		{'::=', '⩴', nil, 0x2A74};
         1665  +		{'==', '≡', 'equiv', 0x2261};
         1666  +		{'===', '≣', nil, 0x2263};
         1667  +		{'<=', '≤', 'le', 0x2264};
         1668  +		{'>=', '≥', 'ge', 0x2265};
         1669  +		{'?=', '≟', 'questeq', 0x225F};
         1670  +		{'@<', '∝', 'prop', 0x221D};
         1671  +		{'<>', '⋄', nil, 0x22C4};
         1672  +		{'~~', '≈', 'asymp', 0x2248};
         1673  +		{'<==>', '⟺', 'Longleftrightarrow', 0x27FA};
         1674  +		{'<=>', '⇔', 'hArr', 0x21D4};
         1675  +		{'==>', '⟹', 'DoubleLongRightArrow', 0x27F9};
         1676  +		{'=>', '⇒', 'rArr', 0x21D2};
         1677  +		{'<->', '↔', 'harr', 0x2194};
         1678  +		{'->', '→', 'rarr', 0x2192};
         1679  +		{'<-', '←', 'ShortLeftArrow', 0x2190};
         1680  +		{'~|', '⊕', 'oplus', 0x2295};
         1681  +		{'@A', '∀', 'forall', 0x2200};
         1682  +		{'~@E', '∄', 'NotExists', 0x2204};
         1683  +		{'@E', '∃', 'exist', 0x2203};
         1684  +		{'.*.', '∴', 'therefore', 0x2234};
         1685  +		{'*.*', '∵', 'because', 0x2235};
         1686  +	};
         1687  +};