<div dir="ltr"><div dir="ltr">On Sun, 29 Aug 2021 at 16:42, Vítek Novotný <<a href="mailto:witiko@mail.muni.cz">witiko@mail.muni.cz</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Dear Eduardo,<br>
<br>
ah, light begins to shine! I suppose you could register a<br>
process_line_buffer callback, which would `return ""` until it has<br>
matched "End of block" or until it has been called five times, at which<br>
point it would unregister itself.<br><br></blockquote><div><br></div>Hi Vitek,<br><br>I've just uploaded the second prototype to github - in this one when<br>we call Foo with a second arguments, like this,<br><br> \directlua{Foo("End of block", "skip")}<br><br>it skips the lines that are fake Markdown by making<br>"process_input_buffer" return "%". It is here,<br><br> <a href="https://github.com/edrx/markdown-dednat6/">https://github.com/edrx/markdown-dednat6/</a><br><br>and its test.tex file is just this, plus comments:<br><br>--snip--snip--<br><br>\documentclass{article}<br>\begin{document}<br><br>\catcode`\^^J=10<br>\directlua{dofile "minimalcore.lua"}<br>\directlua{texfile0(status.filename)}<br>\def\pu{\directlua{pu()}}<br><br>%L skiplinesuntil_ = 0<br>%L skiplinesuntil = function (li)<br>%L if tex.inputlineno <= skiplinesuntil_ then<br>%L return "%"<br>%L end<br>%L return li<br>%L end<br>%L luatexbase.add_to_callback("process_input_buffer",<br>%L skiplinesuntil, "skiplinesuntil")<br>%L <br>%L findlinewithre = function (firstline, re)<br>%L for i=firstline,1000000 do<br>%L if texlines[i] == nil then error("re not found") end<br>%L if texlines[i]:match(re) then return i end<br>%L end<br>%L end<br>%L printlines = function (i, j)<br>%L print("\n\n")<br>%L for k=i,j do print(k..":", '"'..texlines[k]..'"') end<br>%L print("\n\n")<br>%L end<br>%L Foo = function (re, skip)<br>%L local outerbeg = tex.inputlineno<br>%L local innerbeg = outerbeg + 1<br>%L local innerend = findlinewithre(innerbeg, re) - 1<br>%L local outerend = innerend + 1<br>%L printlines(innerbeg, innerend)<br>%L if skip then skiplinesuntil_ = outerend end<br>%L end<br>%L<br>\pu<br><br>(Test 1)<br>\directlua{Foo("End of block")}%<br>Plop<br> Plip<br> Bletch<br>End of block<br>(without skip, with \%)<br><br>(Test 2)<br>\directlua{Foo("End of block", "skip")}%<br>Plop<br> Plip<br> Bletch<br>End of block<br>(with skip, with \%)<br><br>(Test 3)<br>\directlua{Foo("End of block", "skip")}<br>Plop<br> Plip<br> Bletch<br>End of block<br>(with skip, without \%)<br><br>\end{document}<br><br>--snip--snip--<br><br><br>When we don't add a "%" after the \directlua line then a strange space<br>appears, and I don't know why. I also don't know how to handle in an<br>elegant way the cases in which we have a main .tex file that "\input"s<br>other .tex files that also have blocks of "%L" lines and blocks of<br>fake Markdown code... in Dednat6 I handle this by using this quick<br>hack in each of my sub-.tex files:<br><br> <a href="http://angg.twu.net/LATEX/dednat6/block.lua.html#tf_push_and_tf_pop">http://angg.twu.net/LATEX/dednat6/block.lua.html#tf_push_and_tf_pop</a><br><br>If you have any ideas for solving this, please let me know!<br><br> Cheers,<br> Eduardo Ochs<br> <a href="http://angg.twu.net/dednat6.html">http://angg.twu.net/dednat6.html</a><br> <a href="http://angg.twu.net/math-b.html">http://angg.twu.net/math-b.html</a><br><div> </div></div></div>