* Lua filters: can I traverse paragraphs in reading order?
@ 2019-10-22 10:29 jcr
[not found] ` <937d0cc8-12cf-40c4-83f8-f5c50c14e4b3-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: jcr @ 2019-10-22 10:29 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 2068 bytes --]
In a text that I am preparing in Markdown I am tagging page numbers. I use
Lua filters to transform the text for output, and one of the things I do in
the filter is warn when there are page numbers out of order. When there are
two page numbers in the same paragraph, I can get spurious warnings because
the order in which the filter is invoked on the spans does not match the
order in which the text is read. With the following text and filter, the
warning "Warning: page 123 follows page 124" is printed. this seems to
depend on the fact that the second page number is inside a quotation. If
the quotation marks are removed, no warning is printed. Is there a way to
make sure the filter visits spans in reading order?
Text:
[123]{.pnum} Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex
ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
velit esse cillum dolore eu fugiat nulla pariatur. "Excepteur sint
[124]{.pnum} occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum."
Simplified filter:
local lastPage = nil
function Span(el)
if el.classes[1] == "pnum" then
local s = pandoc.utils.stringify(el)
local page = string.match(s, "(%d+)")
if page then
page = tonumber(page)
if lastPage and page <= lastPage then
io.stderr:write(string.format("Warning: page %d follows page
%d\n", page, lastPage))
end
lastPage = page
end
end
return el
end
--
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/937d0cc8-12cf-40c4-83f8-f5c50c14e4b3%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 3159 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Lua filters: can I traverse paragraphs in reading order?
[not found] ` <937d0cc8-12cf-40c4-83f8-f5c50c14e4b3-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-10-22 16:09 ` John MacFarlane
[not found] ` <yh480kwocwkbik.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: John MacFarlane @ 2019-10-22 16:09 UTC (permalink / raw)
To: jcr, pandoc-discuss
I believe this is fixed by
https://github.com/jgm/pandoc/issues/5667
You could try with a nightly build...
jcr <ffi.appdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
> In a text that I am preparing in Markdown I am tagging page numbers. I use
> Lua filters to transform the text for output, and one of the things I do in
> the filter is warn when there are page numbers out of order. When there are
> two page numbers in the same paragraph, I can get spurious warnings because
> the order in which the filter is invoked on the spans does not match the
> order in which the text is read. With the following text and filter, the
> warning "Warning: page 123 follows page 124" is printed. this seems to
> depend on the fact that the second page number is inside a quotation. If
> the quotation marks are removed, no warning is printed. Is there a way to
> make sure the filter visits spans in reading order?
>
> Text:
>
> [123]{.pnum} Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
> do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
> minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex
> ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
> velit esse cillum dolore eu fugiat nulla pariatur. "Excepteur sint
> [124]{.pnum} occaecat cupidatat non proident, sunt in culpa qui officia
> deserunt mollit anim id est laborum."
>
> Simplified filter:
>
> local lastPage = nil
>
> function Span(el)
> if el.classes[1] == "pnum" then
> local s = pandoc.utils.stringify(el)
> local page = string.match(s, "(%d+)")
> if page then
> page = tonumber(page)
> if lastPage and page <= lastPage then
> io.stderr:write(string.format("Warning: page %d follows page
> %d\n", page, lastPage))
> end
> lastPage = page
> end
> end
> return el
> end
>
> --
> You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/937d0cc8-12cf-40c4-83f8-f5c50c14e4b3%40googlegroups.com.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Lua filters: can I traverse paragraphs in reading order?
[not found] ` <yh480kwocwkbik.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
@ 2019-10-22 16:28 ` jcr
0 siblings, 0 replies; 3+ messages in thread
From: jcr @ 2019-10-22 16:28 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 3114 bytes --]
Thank you. It works with the nightly build (pandoc-osx-b80bd174a). Since
this is only an annoyance, I'll wait for the release.
On Tuesday, October 22, 2019 at 6:09:40 PM UTC+2, John MacFarlane wrote:
>
>
> I believe this is fixed by
> https://github.com/jgm/pandoc/issues/5667
> You could try with a nightly build...
>
> jcr <ffi....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <javascript:>> writes:
>
> > In a text that I am preparing in Markdown I am tagging page numbers. I
> use
> > Lua filters to transform the text for output, and one of the things I do
> in
> > the filter is warn when there are page numbers out of order. When there
> are
> > two page numbers in the same paragraph, I can get spurious warnings
> because
> > the order in which the filter is invoked on the spans does not match the
> > order in which the text is read. With the following text and filter, the
> > warning "Warning: page 123 follows page 124" is printed. this seems to
> > depend on the fact that the second page number is inside a quotation. If
> > the quotation marks are removed, no warning is printed. Is there a way
> to
> > make sure the filter visits spans in reading order?
> >
> > Text:
> >
> > [123]{.pnum} Lorem ipsum dolor sit amet, consectetur adipiscing elit,
> sed
> > do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
> ad
> > minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
> ex
> > ea commodo consequat. Duis aute irure dolor in reprehenderit in
> voluptate
> > velit esse cillum dolore eu fugiat nulla pariatur. "Excepteur sint
> > [124]{.pnum} occaecat cupidatat non proident, sunt in culpa qui officia
> > deserunt mollit anim id est laborum."
> >
> > Simplified filter:
> >
> > local lastPage = nil
> >
> > function Span(el)
> > if el.classes[1] == "pnum" then
> > local s = pandoc.utils.stringify(el)
> > local page = string.match(s, "(%d+)")
> > if page then
> > page = tonumber(page)
> > if lastPage and page <= lastPage then
> > io.stderr:write(string.format("Warning: page %d follows page
> > %d\n", page, lastPage))
> > end
> > lastPage = page
> > end
> > end
> > return el
> > end
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "pandoc-discuss" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>.
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/937d0cc8-12cf-40c4-83f8-f5c50c14e4b3%40googlegroups.com.
>
>
--
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/5d48c77b-27e7-4108-be58-a38625eac8f2%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 5219 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-10-22 16:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-22 10:29 Lua filters: can I traverse paragraphs in reading order? jcr
[not found] ` <937d0cc8-12cf-40c4-83f8-f5c50c14e4b3-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-10-22 16:09 ` John MacFarlane
[not found] ` <yh480kwocwkbik.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2019-10-22 16:28 ` jcr
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).