%D \module %D [ file=m-poetry, %D version=2022.08.28 %D title=\CONTEXT\ Extra Modules, %D subtitle=Whatever comes up, %D author=Hans Hagen, %D date=\currentdate, %D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] %C %C This module is part of the \CONTEXT\ macro||package and is %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. % For Denis Maier (see mails to list end of August 2022) \startluacode local poetry = moduledata.poetry or { } moduledata.poetry = poetry function poetry.sidebyside(specification) local first = string.splitlines(buffers.getcontent(specification.left)) local second = string.splitlines(buffers.getcontent(specification.right)) local template = specification.template or "|||" context.starttabulate { template } for i=1,#first do local f = first [i] or "" local s = second[i] or "" if f == "" and s == "" then context.TB { "medium" } else context.NC() context(f) context.NC() context(s) context.NC() context.NR() end end context.stoptabulate() end function poetry.sidebyside(specification) local left = specification.left local right = specification.right local first = left and string.splitlines(buffers.getcontent(left )) or { } local second = right and string.splitlines(buffers.getcontent(right)) or { } if #first > 0 and #second == 0 then for i=1,#first do local t = string.split(first[i], "|") first[i] = string.strip(t[1] or "") second[i] = string.strip(t[2] or "") end end local template = specification.template or "|||" context.starttabulate { template } for i=1,#first do local f = first [i] or "" local s = second[i] or "" if f == "" and s == "" then context.TB { "medium" } else context.NC() context(f) context.NC() context(s) context.NC() context.NR() end end context.stoptabulate() end interfaces.implement { name = "poetrysidebyside", protected = true, public = true, actions = poetry.sidebyside, arguments = "hash", } \stopluacode \continueifinputfile{m-poetry.mkxl} \starttext \startbuffer[lines-1] THIS IS A POEM WITH TWO STANZAS \stopbuffer \startbuffer[lines-2] this is a poem with two stanzas \stopbuffer \startbuffer[lines-3] this | THIS is | IS a | A poem | POEM | with | WITH two | TWO stanzas | STANZAS \stopbuffer \ctxlua { moduledata.poetry.sidebyside { left = "lines-1", right = "lines-2", template = "|l|i2r|" } } \ctxlua { moduledata.poetry.sidebyside { left = "lines-3", template = "|r|il|" } } \poetrysidebyside [left=lines-3, template={|r|il|}] \stoptext