Hi Jiří, thank you (again :) for this filter. I can confirm it works, with the only bug I found so far being stand-alone images converted to regular ID’d paragraphs instead of HTML figures. On Saturday, July 30, 2022 at 4:34:56 PM UTC+2 wol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > (I wrote this message accidentally as a reply not to the mailing list, > so I send it once again to the list.) > > Below, you can get the source code of a Lua filter that adds anchors to > all paragraphs, list items (list items are also paragraphs in Pandoc) > and headings. The anchors are numbered (#para-0, #para-1 etc.). > > If you really need > > To the end of every paragraph (or other block), a link to the paragraph > is added. > > Both links and anchors are given a class name. You can style them. I > recommend this CSS: > > .para-link { > font-size: .7em; > text-decoration: none; > color: inherit; > opacity: .7; > } > .para-link:hover, .para-link:focus { > text-decoration: underline; > opacity: 1; > } > > > Usage of the filter: > > pandoc inputfile.md -o outputfile.html --lua-filter=blockids.lua > > (Where the file blockids.lua is the filter file. Save it to the data dir > subdirectory ‘filters/’ or the cwd.) > > The code follows. > > > -- Adds IDs to every block of the document. > > -- MIT License > -- > -- Copyright (c) 2022 Jiří Wolker > -- > -- Permission is hereby granted, free of charge, to any person obtaining > a copy > -- of this software and associated documentation files (the "Software"), > to deal > -- in the Software without restriction, including without limitation the > rights > -- to use, copy, modify, merge, publish, distribute, sublicense, and/or > sell > -- copies of the Software, and to permit persons to whom the Software is > -- furnished to do so, subject to the following conditions: > -- > -- The above copyright notice and this permission notice shall be > included in > -- all copies or substantial portions of the Software. > -- > -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, > EXPRESS OR > -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, > -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT > SHALL THE > -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER > -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, > ARISING FROM, > -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER > DEALINGS IN THE > -- SOFTWARE. > > paragraph_number = 0 > > function Block(elem) > local blocks_to_modify = { > ["Para"] = true, > ["Div"] = true, > ["Header"] = true, > } > if blocks_to_modify[elem.t] then > id = "para-"..paragraph_number > paragraph_number = paragraph_number + 1 > > anchor = pandoc.Link({ }, "#"..id) > anchor.classes:insert("para-anchor") > anchor.identifier = id > > link = pandoc.Link("link", "#"..id) > link.classes:insert("para-link") > > -- At the start of the block: > elem.content:insert(1, anchor) > > -- At the end of the block: > elem.content:insert(pandoc.Space()) > elem.content:insert(link) > > -- Return the modified block. > return elem > 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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/22f277e9-5f3f-4673-a898-cf8be9e6492fn%40googlegroups.com.