* ignore section & content in output
@ 2019-02-09 18:55 Colin McLear
[not found] ` <bbe3cee2-f65b-41c2-a1e0-04eceedd463f-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: Colin McLear @ 2019-02-09 18:55 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 971 bytes --]
I would like to be able to put an id like {#ignore} next to any section
title of arbitrary depth (i.e. h1, h2, etc) and have a lua filter that just
removes that section for any output. I have a filter that accomplishes this
for particular headings but for some reason (well, probably because I know
very little lua) I can't make this work for heading and content. Any ideas
are appreciated!
--
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/bbe3cee2-f65b-41c2-a1e0-04eceedd463f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[-- Attachment #1.2: Type: text/html, Size: 1407 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: ignore section & content in output
[not found] ` <bbe3cee2-f65b-41c2-a1e0-04eceedd463f-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-02-09 21:40 ` Albert Krewinkel
[not found] ` <87a7j4iqtc.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2019-02-11 17:48 ` Colin McLear
1 sibling, 1 reply; 8+ messages in thread
From: Albert Krewinkel @ 2019-02-09 21:40 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
Colin McLear writes:
> I would like to be able to put an id like {#ignore} next to any section
> title of arbitrary depth (i.e. h1, h2, etc) and have a lua filter that just
> removes that section for any output. I have a filter that accomplishes this
> for particular headings but for some reason (well, probably because I know
> very little lua) I can't make this work for heading and content. Any ideas
> are appreciated!
Maybe take a look at the abstract-to-meta filter in
<https://github.com/pandoc/lua-filters>. It does something quite
similar, in that it looks for a specific header and removes it
together with all its content from the document body. Only few
changes should be necessary to make it suitable for your
use-case.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: ignore section & content in output
[not found] ` <87a7j4iqtc.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
@ 2019-02-11 5:17 ` Colin McLear
0 siblings, 0 replies; 8+ messages in thread
From: Colin McLear @ 2019-02-11 5:17 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 1474 bytes --]
That worked perfectly -- thanks!
On Saturday, February 9, 2019 at 4:40:19 PM UTC-5, Albert Krewinkel wrote:
>
> Colin McLear writes:
>
> > I would like to be able to put an id like {#ignore} next to any section
> > title of arbitrary depth (i.e. h1, h2, etc) and have a lua filter that
> just
> > removes that section for any output. I have a filter that accomplishes
> this
> > for particular headings but for some reason (well, probably because I
> know
> > very little lua) I can't make this work for heading and content. Any
> ideas
> > are appreciated!
>
> Maybe take a look at the abstract-to-meta filter in
> <https://github.com/pandoc/lua-filters>. It does something quite
> similar, in that it looks for a specific header and removes it
> together with all its content from the document body. Only few
> changes should be necessary to make it suitable for your
> use-case.
>
--
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/1003e3ab-3a06-4249-b02c-93295a2886ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[-- Attachment #1.2: Type: text/html, Size: 2543 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: ignore section & content in output
[not found] ` <bbe3cee2-f65b-41c2-a1e0-04eceedd463f-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-02-09 21:40 ` Albert Krewinkel
@ 2019-02-11 17:48 ` Colin McLear
[not found] ` <717bc9dc-b99a-4472-9965-1c84a737fc01-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
1 sibling, 1 reply; 8+ messages in thread
From: Colin McLear @ 2019-02-11 17:48 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 1579 bytes --]
In case anyone is interested in such a filter:
-- cutsection.lua - remove tagged sections in Pandoc output
-- heavily adapted from
https://github.com/pandoc/lua-filters/tree/master/abstract-to-meta
local looking_at_section = false
local remove = {}
function Block (elem)
if looking_at_section then
remove[#remove + 1] = elem
return {}
end
end
function Header (elem)
if elem.identifier == 'remove' then
looking_at_section = true
return {}
else
looking_at_section = false
end
end
On Saturday, February 9, 2019 at 1:55:15 PM UTC-5, Colin McLear wrote:
>
> I would like to be able to put an id like {#ignore} next to any section
> title of arbitrary depth (i.e. h1, h2, etc) and have a lua filter that just
> removes that section for any output. I have a filter that accomplishes this
> for particular headings but for some reason (well, probably because I know
> very little lua) I can't make this work for heading and content. Any ideas
> are appreciated!
>
>
>
--
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/717bc9dc-b99a-4472-9965-1c84a737fc01%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[-- Attachment #1.2: Type: text/html, Size: 2472 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: ignore section & content in output
[not found] ` <717bc9dc-b99a-4472-9965-1c84a737fc01-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-02-11 23:27 ` EBkysko
[not found] ` <b4c57563-7c47-4b1d-accd-2bdaf2e39e75-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: EBkysko @ 2019-02-11 23:27 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 1717 bytes --]
Your filter looks good, except that any subsection of the "marked" section
will remain present... but perhaps that's what you want.
If not, or if anyone else would like to remove all subsections of that
section, the following seems to work:
local looking_at_section = false
local remove = {}
local lvl = 0
function Block (elem)
if looking_at_section then
remove[#remove + 1] = elem
return {}
end
end
function Header (elem)
if elem.identifier == 'remove' then
looking_at_section = true
lvl = elem.level
return {}
else
looking_at_section = looking_at_section and elem.level > lvl
if looking_at_section then
remove[#remove + 1] = elem
return {}
end
end
end
The original filter has the same problem... but an abstract usually doesn't
have subsections/sublevels (I think).
Note also that usually an identifier should identify only one element, and
pandoc will (rightly) be annoyed when there's more than one header with the
same ID.
A class would be ideal for this situation, and one might then use `if
elem.classes:includes('remove',1)` rather than `if elem.identifier ==
'remove'`
--
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/b4c57563-7c47-4b1d-accd-2bdaf2e39e75%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[-- Attachment #1.2: Type: text/html, Size: 9558 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: ignore section & content in output
[not found] ` <b4c57563-7c47-4b1d-accd-2bdaf2e39e75-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-02-12 22:47 ` Colin McLear
[not found] ` <5a59f103-d049-453e-b677-d85a2a2d3a76-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: Colin McLear @ 2019-02-12 22:47 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 1895 bytes --]
Even better - thanks very much!
On Monday, February 11, 2019 at 6:27:25 PM UTC-5, EBkysko wrote:
>
> Your filter looks good, except that any subsection of the "marked" section
> will remain present... but perhaps that's what you want.
>
> If not, or if anyone else would like to remove all subsections of that
> section, the following seems to work:
>
> local looking_at_section = false
> local remove = {}
> local lvl = 0
>
> function Block (elem)
> if looking_at_section then
> remove[#remove + 1] = elem
> return {}
> end
> end
>
> function Header (elem)
> if elem.identifier == 'remove' then
> looking_at_section = true
> lvl = elem.level
> return {}
> else
> looking_at_section = looking_at_section and elem.level > lvl
> if looking_at_section then
> remove[#remove + 1] = elem
> return {}
> end
> end
> end
>
> The original filter has the same problem... but an abstract usually
> doesn't have subsections/sublevels (I think).
>
> Note also that usually an identifier should identify only one element, and
> pandoc will (rightly) be annoyed when there's more than one header with the
> same ID.
> A class would be ideal for this situation, and one might then use `if
> elem.classes:includes('remove',1)` rather than `if elem.identifier ==
> 'remove'`
>
>
--
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/5a59f103-d049-453e-b677-d85a2a2d3a76%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[-- Attachment #1.2: Type: text/html, Size: 6395 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: ignore section & content in output
[not found] ` <5a59f103-d049-453e-b677-d85a2a2d3a76-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-02-13 0:00 ` EBkysko
[not found] ` <50ee8006-c909-4b7f-a81b-98d83c2a4aa9-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: EBkysko @ 2019-02-13 0:00 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 1595 bytes --]
One can simplify further I think[^1], removing a redundancy:
local looking_at_section = false
local lvl = 0
local remove = {} -- delete line if 'remove' array not needed
function Block (elem)
if elem.t == "Header" then
-- if elem.classes:includes('remove',1) then
if elem.identifier == 'remove' then
looking_at_section = true
lvl = elem.level
else
looking_at_section = looking_at_section and elem.level > lvl
end
end
if looking_at_section then
remove[#remove + 1] = elem -- delete line if 'remove' array not needed
return {}
end
end
Note that in the original "abstract" script example, the removed portion
was recreated as a meta section. If you don't intend to use the removed
elements, you can simplify further (as noted) by removing the two lines
related to the remove{} array.
[^1]: As long as the filter acts from top to bottom of document among the
Blocks, i.e. if there's no unknown precedence rules among all the Block
types... which I'm not 100% sure.
--
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/50ee8006-c909-4b7f-a81b-98d83c2a4aa9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[-- Attachment #1.2: Type: text/html, Size: 9121 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: ignore section & content in output
[not found] ` <50ee8006-c909-4b7f-a81b-98d83c2a4aa9-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-02-13 1:13 ` EBkysko
0 siblings, 0 replies; 8+ messages in thread
From: EBkysko @ 2019-02-13 1:13 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 1316 bytes --]
*Sigh* I don't know why formatting error appear (blank lines, new lines at
wrong places) when I use google groups "code syntax" from the UI... and of
course can't edit my dang post... So here's in raw form :
```
local looking_at_section = false
local lvl = 0
local remove = {} -- delete line if 'remove' array not needed
function Block (elem)
if elem.t == "Header" then
-- if elem.classes:includes('remove',1) then
if elem.identifier == 'remove' then
looking_at_section = true
lvl = elem.level
else
looking_at_section = looking_at_section and elem.level > lvl
end
end
if looking_at_section then
remove[#remove + 1] = elem -- delete line if 'remove' array not needed
return {}
end
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/e3c5e5cf-8f2b-481f-afcd-de08d1a653b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[-- Attachment #1.2: Type: text/html, Size: 1960 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2019-02-13 1:13 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-09 18:55 ignore section & content in output Colin McLear
[not found] ` <bbe3cee2-f65b-41c2-a1e0-04eceedd463f-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-02-09 21:40 ` Albert Krewinkel
[not found] ` <87a7j4iqtc.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2019-02-11 5:17 ` Colin McLear
2019-02-11 17:48 ` Colin McLear
[not found] ` <717bc9dc-b99a-4472-9965-1c84a737fc01-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-02-11 23:27 ` EBkysko
[not found] ` <b4c57563-7c47-4b1d-accd-2bdaf2e39e75-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-02-12 22:47 ` Colin McLear
[not found] ` <5a59f103-d049-453e-b677-d85a2a2d3a76-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-02-13 0:00 ` EBkysko
[not found] ` <50ee8006-c909-4b7f-a81b-98d83c2a4aa9-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-02-13 1:13 ` EBkysko
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).