Hi Albert,
We could do this by passing the full content to the strikeout constructor. We'd remove, then re-add the checkbox later:
plain.content:remove(2) -- remove space
plain.content:remove(1) -- remove checkbox
plain.content = done_marker ..
pandoc.Strikeout(plain.content)Am 24. Dezember 2022 09:37:58 MEZ schrieb "balaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <balaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:Thanks for the pointers Albert! It did help me get started. Unfortunately when I started looping through the Plain object, I realized that the individual strings were represented as separate elements so there did not seem to be an easy way to apply a strikethrough formatting for the entire sentence. The best I would be able to do was apply the strikethrough word-by-word but with that approach, the final HTML did not look very pleasing.In the end, I wound up writing a small Python script that would modify a file with the pandoc native format directly (outside of pandoc) and then feed the modified native format file back into pandoc. After a couple of false starts with the regex and then the native output becoming invalid, I've got it working fairly well for my purposes.On Thursday, 22 December 2022 at 20:21:19 UTC+8 Albert Krewinkel wrote:"balaj...@gmail.com" <balaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
> The specific scenario I'm looking at is a Markdown file such as this:
>
> ### Todo
> - [ ] Foo
> - [X] Quux Qux
This is an interesting case because it is more complex than it seems.
The reason is pandoc's `task_list` extension that causes pandoc to
handle these checkboxes specially, converting them to [Str "☐", Space]
and [Str "☒", Space]. So we'll have to match on that in our filter.
A good approach would be to write a filter for Plain, like so:
``` lua
function Plain (plain)
-- modify the object here
return plain
end
```
Pandoc will then do all necessary document traversals automatically,
the function gets applied to all `Plain` elements in the document.
To check for the prefix, we'd do something like
``` lua
local done_marker = pandoc.List{pandoc.Str '☒', pandoc.Space()}
local prefix = pandoc.List{plain.content[1], plain.content[2]}
if prefix == done_marker then
-- modify content
end
```
I hope that's enough to get you started. Happy hacking!
--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124