* Help with Lua filter for markdown to LaTeX with Pandoc @ 2023-03-25 12:42 Pa Sc [not found] ` <79ac7814-9558-4d49-a682-cf31f970d27dn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 0 siblings, 1 reply; 10+ messages in thread From: Pa Sc @ 2023-03-25 12:42 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 4844 bytes --] In markdown (written in Obsidian.md) I use a plugin/theme so that `*==text==*` is rendered as red instead of italic and highlighted. I use this lua-filter to convert regular `==highlighting==` to LaTeX `\hl{highlighting}` which works perfectly: (I somehow require these two files, I can't remember why) **highlight.lua**: ``` --[[ Add support for a custom inline syntax. This pandoc Lua filter allows to add a custom markup syntax extension. It is designed to be adjustable; it should not be necessary to modify the code below the separator line. The example here allows to add highlighted text by enclosing the text with `==` on each side. Pandoc supports this for HTML output out of the box. Other outputs will need additional filters. Copyright: © 2022 Albert Krewinkel License: MIT ]] -- Lua pattern matching the opening markup string. local opening = [[==]] -- Lua pattern matching the closing markup string. local closing = [[==]] -- Toggle whether the opening markup may be followed by whitespace. local nospace = true -- Function converting the enclosed inlines to their internal pandoc -- representation. local function markup_inlines (inlines) return pandoc.Span(inlines, {class="mark"}) end ------------------------------------------------------------------------ local function is_space (inline) return inline and (inline.t == 'Space' or inline.t == 'LineBreak' or inline.t == 'SoftBreak') end function Inlines (inlines) local result = pandoc.Inlines{} local markup = nil local start = nil for i, inline in ipairs(inlines) do if inline.tag == 'Str' then if not markup then local first = inline.text:match('^' .. opening .. '(.*)') if first then start = inline -- keep element around in case the -- markup is not closed. Check if the -- closing pattern is already in this -- string. local selfclosing = first:match('(.*)' .. closing .. '$') if selfclosing then result:insert(markup_inlines{pandoc.Str(selfclosing)}) elseif nospace and first == '' and is_space(inlines[i+1]) then -- the opening pattern is followed by a space, but the -- config disallows this. result:insert(inline) else markup = pandoc.Inlines{pandoc.Str(first)} end else result:insert(inline) end else local last = inline.text:match('(.*)' .. closing .. '$') if last then markup:insert(pandoc.Str(last)) result:insert(markup_inlines(markup)) markup = nil else markup:insert(inline) end end else local acc = markup or result acc:insert(inline) end end -- keep unterminated markup if markup then markup:remove(1) -- the stripped-down first element result:insert(start) result:extend(markup) end return result end local function markup_inlines (inlines) return {pandoc.RawInline('tex', '\\hl{')} .. inlines .. {pandoc.RawInline('tex', '}')} end ``` **Span.lua**: ``` function Span (span) if span.classes:includes 'mark' then return {pandoc.RawInline('latex', '\\hl{')} .. span.content .. {pandoc.RawInline('latex', '}')} end end ``` This works great, I got this here: [https://gist.github.com/tarleb/a0646da1834318d4f71a780edaf9f870](https://gist.github.com/tarleb/a0646da1834318d4f71a780edaf9f870) However, for my other usecase I'd like it to be able to render `*==this kind of highlighting==*` as `\colorbox{lightred}{this new kind of highlighting}` I've tried replacing the `\\hl{` with `\colorbox{declared-color}{` but that didn't work. I was wondering if it had something to do with the class? But renaming that class from `mark` to `mark-red` didn't work either. Any advice or ideas? Thanks! -- 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/79ac7814-9558-4d49-a682-cf31f970d27dn%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 6005 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <79ac7814-9558-4d49-a682-cf31f970d27dn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: Help with Lua filter for markdown to LaTeX with Pandoc [not found] ` <79ac7814-9558-4d49-a682-cf31f970d27dn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2023-03-25 14:38 ` Bastien DUMONT 2023-03-25 22:01 ` Pa Sc 0 siblings, 1 reply; 10+ messages in thread From: Bastien DUMONT @ 2023-03-25 14:38 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw First, you need to replace `\\hl{` with `\\colorbox{declared-color}{` (mind the double backslash). Then Span.lua can be replaced with the following filter acting on emphasized (italicized) pieces of text: in-red.lua: ``` function Emph (emph) local content = emph.content if #content == 1 and content[1].t == 'Span' and content[1].classes:includes 'mark-red' then return { pandoc.RawInline('latex', '\\colorbox{lightred}{'), content[1], pandoc.RawInline('latex', '}') } end end ``` Here, I replaced "mark" with "mark-red" as you suggested because I don't remove the Span element, in case it contains other classes or attributes that should be processed by other filters or by Pandoc itself. If the Span was kept with the "mark" class, Pandoc would wrap it in the \hl macro afterwards. Le Saturday 25 March 2023 à 05:42:45AM, Pa Sc a écrit : > In markdown (written in Obsidian.md) I use a plugin/theme so that `*==text==*` > is rendered as red instead of italic and highlighted. > > I use this lua-filter to convert regular `==highlighting==` to LaTeX `\hl > {highlighting}` which works perfectly: (I somehow require these two files, I > can't remember why) > > **highlight.lua**: > ``` > --[[ > Add support for a custom inline syntax. > This pandoc Lua filter allows to add a custom markup syntax > extension. It is designed to be adjustable; it should not be > necessary to modify the code below the separator line. > The example here allows to add highlighted text by enclosing the > text with `==` on each side. Pandoc supports this for HTML output > out of the box. Other outputs will need additional filters. > Copyright: © 2022 Albert Krewinkel > License: MIT > ]] > > -- Lua pattern matching the opening markup string. > local opening = [[==]] > > -- Lua pattern matching the closing markup string. > local closing = [[==]] > > -- Toggle whether the opening markup may be followed by whitespace. > local nospace = true > > -- Function converting the enclosed inlines to their internal pandoc > -- representation. > local function markup_inlines (inlines) > return pandoc.Span(inlines, {class="mark"}) > end > > ------------------------------------------------------------------------ > > local function is_space (inline) > return inline and > (inline.t == 'Space' or > inline.t == 'LineBreak' or > inline.t == 'SoftBreak') > end > > function Inlines (inlines) > local result = pandoc.Inlines{} > local markup = nil > local start = nil > for i, inline in ipairs(inlines) do > if inline.tag == 'Str' then > if not markup then > local first = inline.text:match('^' .. opening .. '(.*)') > if first then > start = inline -- keep element around in case the > -- markup is not closed. Check if the > -- closing pattern is already in this > -- string. > local selfclosing = first:match('(.*)' .. closing .. '$') > if selfclosing then > result:insert(markup_inlines{pandoc.Str(selfclosing)}) > elseif nospace and first == '' and is_space(inlines[i+1]) then > -- the opening pattern is followed by a space, but the > -- config disallows this. > result:insert(inline) > else > markup = pandoc.Inlines{pandoc.Str(first)} > end > else > result:insert(inline) > end > else > local last = inline.text:match('(.*)' .. closing .. '$') > if last then > markup:insert(pandoc.Str(last)) > result:insert(markup_inlines(markup)) > markup = nil > else > markup:insert(inline) > end > end > else > local acc = markup or result > acc:insert(inline) > end > end > > -- keep unterminated markup > if markup then > markup:remove(1) -- the stripped-down first element > result:insert(start) > result:extend(markup) > end > return result > end > > local function markup_inlines (inlines) return {pandoc.RawInline('tex', ' > \\hl{')} .. inlines .. {pandoc.RawInline('tex', '}')} end > ``` > > **Span.lua**: > ``` > function Span (span) > if span.classes:includes 'mark' then > return {pandoc.RawInline('latex', '\\hl{')} .. > span.content .. > {pandoc.RawInline('latex', '}')} > end > end > ``` > This works great, I got this here: [https://gist.github.com/tarleb/ > a0646da1834318d4f71a780edaf9f870](https://gist.github.com/tarleb/ > a0646da1834318d4f71a780edaf9f870) > > However, for my other usecase I'd like it to be able to render `*==this kind of > highlighting==*` as `\colorbox{lightred}{this new kind of highlighting}` > > I've tried replacing the `\\hl{` with `\colorbox{declared-color}{` but that > didn't work. > > I was wondering if it had something to do with the class? But renaming that > class from `mark` to `mark-red` didn't work either. > > Any advice or ideas? Thanks! > > -- > 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 [1]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit [2]https://groups.google.com/d/msgid/ > pandoc-discuss/79ac7814-9558-4d49-a682-cf31f970d27dn%40googlegroups.com. > > References: > > [1] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > [2] https://groups.google.com/d/msgid/pandoc-discuss/79ac7814-9558-4d49-a682-cf31f970d27dn%40googlegroups.com?utm_medium=email&utm_source=footer -- 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/ZB8HbxE9qj%2B%2BaouD%40localhost. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Help with Lua filter for markdown to LaTeX with Pandoc 2023-03-25 14:38 ` Bastien DUMONT @ 2023-03-25 22:01 ` Pa Sc [not found] ` <bb3c6fab-dee9-48c4-81e4-7db67bc6931an-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 0 siblings, 1 reply; 10+ messages in thread From: Pa Sc @ 2023-03-25 22:01 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 7174 bytes --] I followed that, thanks! But I'm still getting `\emph{\hl{abc}` as the output, any other ideas? Bastien DUMONT schrieb am Samstag, 25. März 2023 um 15:38:47 UTC+1: > First, you need to replace `\\hl{` with `\\colorbox{declared-color}{` > (mind the double backslash). Then Span.lua can be replaced with the > following filter acting on emphasized (italicized) pieces of text: > > in-red.lua: > ``` > function Emph (emph) > local content = emph.content > if #content == 1 > and content[1].t == 'Span' > and content[1].classes:includes 'mark-red' then > return { > pandoc.RawInline('latex', '\\colorbox{lightred}{'), > content[1], > pandoc.RawInline('latex', '}') > } > end > end > ``` > > Here, I replaced "mark" with "mark-red" as you suggested because I don't > remove the Span element, in case it contains other classes or attributes > that should be processed by other filters or by Pandoc itself. If the Span > was kept with the "mark" class, Pandoc would wrap it in the \hl macro > afterwards. > > Le Saturday 25 March 2023 à 05:42:45AM, Pa Sc a écrit : > > In markdown (written in Obsidian.md) I use a plugin/theme so that > `*==text==*` > > is rendered as red instead of italic and highlighted. > > > > I use this lua-filter to convert regular `==highlighting==` to LaTeX `\hl > > {highlighting}` which works perfectly: (I somehow require these two > files, I > > can't remember why) > > > > **highlight.lua**: > > ``` > > --[[ > > Add support for a custom inline syntax. > > This pandoc Lua filter allows to add a custom markup syntax > > extension. It is designed to be adjustable; it should not be > > necessary to modify the code below the separator line. > > The example here allows to add highlighted text by enclosing the > > text with `==` on each side. Pandoc supports this for HTML output > > out of the box. Other outputs will need additional filters. > > Copyright: © 2022 Albert Krewinkel > > License: MIT > > ]] > > > > -- Lua pattern matching the opening markup string. > > local opening = [[==]] > > > > -- Lua pattern matching the closing markup string. > > local closing = [[==]] > > > > -- Toggle whether the opening markup may be followed by whitespace. > > local nospace = true > > > > -- Function converting the enclosed inlines to their internal pandoc > > -- representation. > > local function markup_inlines (inlines) > > return pandoc.Span(inlines, {class="mark"}) > > end > > > > > ------------------------------------------------------------------------ > > > > local function is_space (inline) > > return inline and > > (inline.t == 'Space' or > > inline.t == 'LineBreak' or > > inline.t == 'SoftBreak') > > end > > > > function Inlines (inlines) > > local result = pandoc.Inlines{} > > local markup = nil > > local start = nil > > for i, inline in ipairs(inlines) do > > if inline.tag == 'Str' then > > if not markup then > > local first = inline.text:match('^' .. opening .. '(.*)') > > if first then > > start = inline -- keep element around in case the > > -- markup is not closed. Check if the > > -- closing pattern is already in this > > -- string. > > local selfclosing = first:match('(.*)' .. closing .. '$') > > if selfclosing then > > result:insert(markup_inlines{pandoc.Str(selfclosing)}) > > elseif nospace and first == '' and is_space(inlines[i+1]) > then > > -- the opening pattern is followed by a space, but the > > -- config disallows this. > > result:insert(inline) > > else > > markup = pandoc.Inlines{pandoc.Str(first)} > > end > > else > > result:insert(inline) > > end > > else > > local last = inline.text:match('(.*)' .. closing .. '$') > > if last then > > markup:insert(pandoc.Str(last)) > > result:insert(markup_inlines(markup)) > > markup = nil > > else > > markup:insert(inline) > > end > > end > > else > > local acc = markup or result > > acc:insert(inline) > > end > > end > > > > -- keep unterminated markup > > if markup then > > markup:remove(1) -- the stripped-down first element > > result:insert(start) > > result:extend(markup) > > end > > return result > > end > > > > local function markup_inlines (inlines) return > {pandoc.RawInline('tex', ' > > \\hl{')} .. inlines .. {pandoc.RawInline('tex', '}')} end > > ``` > > > > **Span.lua**: > > ``` > > function Span (span) > > if span.classes:includes 'mark' then > > return {pandoc.RawInline('latex', '\\hl{')} .. > > span.content .. > > {pandoc.RawInline('latex', '}')} > > end > > end > > ``` > > This works great, I got this here: [https://gist.github.com/tarleb/ > > a0646da1834318d4f71a780edaf9f870](https://gist.github.com/tarleb/ > > a0646da1834318d4f71a780edaf9f870) > > > > However, for my other usecase I'd like it to be able to render `*==this > kind of > > highlighting==*` as `\colorbox{lightred}{this new kind of highlighting}` > > > > I've tried replacing the `\\hl{` with `\colorbox{declared-color}{` but > that > > didn't work. > > > > I was wondering if it had something to do with the class? But renaming > that > > class from `mark` to `mark-red` didn't work either. > > > > Any advice or ideas? Thanks! > > > > -- > > 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 [1]pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To view this discussion on the web visit [2] > https://groups.google.com/d/msgid/ > > pandoc-discuss/79ac7814-9558-4d49-a682-cf31f970d27dn%40googlegroups.com. > > > > References: > > > > [1] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > [2] > https://groups.google.com/d/msgid/pandoc-discuss/79ac7814-9558-4d49-a682-cf31f970d27dn%40googlegroups.com?utm_medium=email&utm_source=footer > > -- 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/bb3c6fab-dee9-48c4-81e4-7db67bc6931an%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 10593 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <bb3c6fab-dee9-48c4-81e4-7db67bc6931an-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: Help with Lua filter for markdown to LaTeX with Pandoc [not found] ` <bb3c6fab-dee9-48c4-81e4-7db67bc6931an-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2023-03-25 22:40 ` Bastien DUMONT 2023-03-25 22:44 ` Pa Sc 0 siblings, 1 reply; 10+ messages in thread From: Bastien DUMONT @ 2023-03-25 22:40 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw It works for me. Could you provide a minimal test case, your filters and the command? Le Saturday 25 March 2023 à 03:01:10PM, Pa Sc a écrit : > I followed that, thanks! But I'm still getting `\emph{\hl{abc}` as the output, > any other ideas? > > Bastien DUMONT schrieb am Samstag, 25. März 2023 um 15:38:47 UTC+1: > > First, you need to replace `\\hl{` with `\\colorbox{declared-color}{` (mind > the double backslash). Then Span.lua can be replaced with the following > filter acting on emphasized (italicized) pieces of text: > > in-red.lua: > ``` > function Emph (emph) > local content = emph.content > if #content == 1 > and content[1].t == 'Span' > and content[1].classes:includes 'mark-red' then > return { > pandoc.RawInline('latex', '\\colorbox{lightred}{'), > content[1], > pandoc.RawInline('latex', '}') > } > end > end > ``` > > Here, I replaced "mark" with "mark-red" as you suggested because I don't > remove the Span element, in case it contains other classes or attributes > that should be processed by other filters or by Pandoc itself. If the Span > was kept with the "mark" class, Pandoc would wrap it in the \hl macro > afterwards. > > Le Saturday 25 March 2023 à 05:42:45AM, Pa Sc a écrit : > > In markdown (written in Obsidian.md) I use a plugin/theme so that `*== > text==*` > > is rendered as red instead of italic and highlighted. > > > > I use this lua-filter to convert regular `==highlighting==` to LaTeX `\hl > > {highlighting}` which works perfectly: (I somehow require these two > files, I > > can't remember why) > > > > **highlight.lua**: > > ``` > > --[[ > > Add support for a custom inline syntax. > > This pandoc Lua filter allows to add a custom markup syntax > > extension. It is designed to be adjustable; it should not be > > necessary to modify the code below the separator line. > > The example here allows to add highlighted text by enclosing the > > text with `==` on each side. Pandoc supports this for HTML output > > out of the box. Other outputs will need additional filters. > > Copyright: © 2022 Albert Krewinkel > > License: MIT > > ]] > > > > -- Lua pattern matching the opening markup string. > > local opening = [[==]] > > > > -- Lua pattern matching the closing markup string. > > local closing = [[==]] > > > > -- Toggle whether the opening markup may be followed by whitespace. > > local nospace = true > > > > -- Function converting the enclosed inlines to their internal pandoc > > -- representation. > > local function markup_inlines (inlines) > > return pandoc.Span(inlines, {class="mark"}) > > end > > > > > ------------------------------------------------------------------------ > > > > local function is_space (inline) > > return inline and > > (inline.t == 'Space' or > > inline.t == 'LineBreak' or > > inline.t == 'SoftBreak') > > end > > > > function Inlines (inlines) > > local result = pandoc.Inlines{} > > local markup = nil > > local start = nil > > for i, inline in ipairs(inlines) do > > if inline.tag == 'Str' then > > if not markup then > > local first = inline.text:match('^' .. opening .. '(.*)') > > if first then > > start = inline -- keep element around in case the > > -- markup is not closed. Check if the > > -- closing pattern is already in this > > -- string. > > local selfclosing = first:match('(.*)' .. closing .. '$') > > if selfclosing then > > result:insert(markup_inlines{pandoc.Str(selfclosing)}) > > elseif nospace and first == '' and is_space(inlines[i+1]) > then > > -- the opening pattern is followed by a space, but the > > -- config disallows this. > > result:insert(inline) > > else > > markup = pandoc.Inlines{pandoc.Str(first)} > > end > > else > > result:insert(inline) > > end > > else > > local last = inline.text:match('(.*)' .. closing .. '$') > > if last then > > markup:insert(pandoc.Str(last)) > > result:insert(markup_inlines(markup)) > > markup = nil > > else > > markup:insert(inline) > > end > > end > > else > > local acc = markup or result > > acc:insert(inline) > > end > > end > > > > -- keep unterminated markup > > if markup then > > markup:remove(1) -- the stripped-down first element > > result:insert(start) > > result:extend(markup) > > end > > return result > > end > > > > local function markup_inlines (inlines) return {pandoc.RawInline > ('tex', ' > > \\hl{')} .. inlines .. {pandoc.RawInline('tex', '}')} end > > ``` > > > > **Span.lua**: > > ``` > > function Span (span) > > if span.classes:includes 'mark' then > > return {pandoc.RawInline('latex', '\\hl{')} .. > > span.content .. > > {pandoc.RawInline('latex', '}')} > > end > > end > > ``` > > This works great, I got this here: [[1]https://gist.github.com/tarleb/ > > a0646da1834318d4f71a780edaf9f870]([2]https://gist.github.com/tarleb/ > > a0646da1834318d4f71a780edaf9f870) > > > > However, for my other usecase I'd like it to be able to render `*==this > kind of > > highlighting==*` as `\colorbox{lightred}{this new kind of highlighting}` > > > > I've tried replacing the `\\hl{` with `\colorbox{declared-color}{` but > that > > didn't work. > > > > I was wondering if it had something to do with the class? But renaming > that > > class from `mark` to `mark-red` didn't work either. > > > > Any advice or ideas? Thanks! > > > > -- > > 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 [1]pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To view this discussion on the web visit [2][3]https://groups.google.com/ > d/msgid/ > > pandoc-discuss/79ac7814-9558-4d49-a682-cf31f970d27dn%[4] > 40googlegroups.com. > > > > References: > > > > [1] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > [2] [5]https://groups.google.com/d/msgid/pandoc-discuss/ > 79ac7814-9558-4d49-a682-cf31f970d27dn%40googlegroups.com?utm_medium=email& > utm_source=footer > > > -- > 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 [6]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit [7]https://groups.google.com/d/msgid/ > pandoc-discuss/bb3c6fab-dee9-48c4-81e4-7db67bc6931an%40googlegroups.com. > > References: > > [1] https://gist.github.com/tarleb/ > [2] https://gist.github.com/tarleb/ > [3] https://groups.google.com/d/msgid/ > [4] http://40googlegroups.com/ > [5] https://groups.google.com/d/msgid/pandoc-discuss/79ac7814-9558-4d49-a682-cf31f970d27dn%40googlegroups.com?utm_medium=email&utm_source=footer > [6] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > [7] https://groups.google.com/d/msgid/pandoc-discuss/bb3c6fab-dee9-48c4-81e4-7db67bc6931an%40googlegroups.com?utm_medium=email&utm_source=footer -- 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/ZB94bf//ef6J/nsc%40localhost. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Help with Lua filter for markdown to LaTeX with Pandoc 2023-03-25 22:40 ` Bastien DUMONT @ 2023-03-25 22:44 ` Pa Sc [not found] ` <6a7dabf5-1fda-4825-9d21-193b63363937n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 0 siblings, 1 reply; 10+ messages in thread From: Pa Sc @ 2023-03-25 22:44 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 1148 bytes --] Yeah, I have a MWE here: https://tex.stackexchange.com/questions/680766/help-with-lua-filter-for-markdown-to-latex-with-pandoc As for the command: ``` mkdir -p /home/ME/Documents/Obsidian/Output/{{title}} pandoc -r markdown-auto_identifiers -w latex {{file_path:absolute}} -o /home/ME/Documents/Obsidian/Output/{{title}}/{{title}}.tex --template="/home/ME/Documents/LaTeX/My Templates/Proposal/default-proposal.tex" --lua-filter=/home/ME/Documents/LaTeX/Filters/highlight.lua --lua-filter=/home/ME/Documents/LaTeX/Filters/highlight-period.lua --lua-filter=/home/ME/Documents/LaTeX/Filters/Span.lua --lua-filter=/home/ME/Documents/LaTeX/Filters/highlight-red.lua --lua-filter=/home/ME/Documents/LaTeX/Filters/Span-red.lua ``` -- 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/6a7dabf5-1fda-4825-9d21-193b63363937n%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 1508 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <6a7dabf5-1fda-4825-9d21-193b63363937n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: Help with Lua filter for markdown to LaTeX with Pandoc [not found] ` <6a7dabf5-1fda-4825-9d21-193b63363937n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2023-03-25 23:08 ` Bastien DUMONT 2023-03-26 9:42 ` Pa Sc 0 siblings, 1 reply; 10+ messages in thread From: Bastien DUMONT @ 2023-03-25 23:08 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw Please share the two lua filters you use to parse `==` as a syntax for highlighting and to print in red an emphasized span produced by this filter. We can't figure out what is wrong without them. Le Saturday 25 March 2023 à 03:44:24PM, Pa Sc a écrit : > Yeah, I have a MWE here: https://tex.stackexchange.com/questions/680766/ > help-with-lua-filter-for-markdown-to-latex-with-pandoc > > As for the command: > ``` > mkdir -p /home/ME/Documents/Obsidian/Output/{{title}} > pandoc -r markdown-auto_identifiers -w latex {{file_path:absolute}} -o /home/ME > /Documents/Obsidian/Output/{{title}}/{{title}}.tex --template="/home/ME/ > Documents/LaTeX/My Templates/Proposal/default-proposal.tex" --lua-filter=/home/ > ME/Documents/LaTeX/Filters/highlight.lua --lua-filter=/home/ME/Documents/LaTeX/ > Filters/highlight-period.lua --lua-filter=/home/ME/Documents/LaTeX/Filters/ > Span.lua --lua-filter=/home/ME/Documents/LaTeX/Filters/highlight-red.lua > --lua-filter=/home/ME/Documents/LaTeX/Filters/Span-red.lua > ``` > > -- > 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 [1]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit [2]https://groups.google.com/d/msgid/ > pandoc-discuss/6a7dabf5-1fda-4825-9d21-193b63363937n%40googlegroups.com. > > References: > > [1] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > [2] https://groups.google.com/d/msgid/pandoc-discuss/6a7dabf5-1fda-4825-9d21-193b63363937n%40googlegroups.com?utm_medium=email&utm_source=footer -- 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/ZB9%2B/QK6XhVucw9i%40localhost. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Help with Lua filter for markdown to LaTeX with Pandoc 2023-03-25 23:08 ` Bastien DUMONT @ 2023-03-26 9:42 ` Pa Sc [not found] ` <aded6fcf-0720-4fea-a873-af2cacfb8281n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 0 siblings, 1 reply; 10+ messages in thread From: Pa Sc @ 2023-03-26 9:42 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 2386 bytes --] Do you mean the two filters that are in the original post? Or what filter do you mean? Bastien DUMONT schrieb am Sonntag, 26. März 2023 um 00:08:53 UTC+1: > Please share the two lua filters you use to parse `==` as a syntax for > highlighting and to print in red an emphasized span produced by this > filter. We can't figure out what is wrong without them. > > Le Saturday 25 March 2023 à 03:44:24PM, Pa Sc a écrit : > > Yeah, I have a MWE here: https://tex.stackexchange.com/questions/680766/ > > help-with-lua-filter-for-markdown-to-latex-with-pandoc > > > > As for the command: > > ``` > > mkdir -p /home/ME/Documents/Obsidian/Output/{{title}} > > pandoc -r markdown-auto_identifiers -w latex {{file_path:absolute}} -o > /home/ME > > /Documents/Obsidian/Output/{{title}}/{{title}}.tex --template="/home/ME/ > > Documents/LaTeX/My Templates/Proposal/default-proposal.tex" > --lua-filter=/home/ > > ME/Documents/LaTeX/Filters/highlight.lua > --lua-filter=/home/ME/Documents/LaTeX/ > > Filters/highlight-period.lua > --lua-filter=/home/ME/Documents/LaTeX/Filters/ > > Span.lua --lua-filter=/home/ME/Documents/LaTeX/Filters/highlight-red.lua > > --lua-filter=/home/ME/Documents/LaTeX/Filters/Span-red.lua > > ``` > > > > -- > > 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 [1]pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To view this discussion on the web visit [2] > https://groups.google.com/d/msgid/ > > pandoc-discuss/6a7dabf5-1fda-4825-9d21-193b63363937n%40googlegroups.com. > > > > References: > > > > [1] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > [2] > https://groups.google.com/d/msgid/pandoc-discuss/6a7dabf5-1fda-4825-9d21-193b63363937n%40googlegroups.com?utm_medium=email&utm_source=footer > > -- 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/aded6fcf-0720-4fea-a873-af2cacfb8281n%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 4330 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <aded6fcf-0720-4fea-a873-af2cacfb8281n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: Help with Lua filter for markdown to LaTeX with Pandoc [not found] ` <aded6fcf-0720-4fea-a873-af2cacfb8281n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2023-03-26 9:53 ` Bastien DUMONT 2023-03-26 10:33 ` Pa Sc 0 siblings, 1 reply; 10+ messages in thread From: Bastien DUMONT @ 2023-03-26 9:53 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw [-- Attachment #1: Type: text/plain, Size: 3755 bytes --] I attached two filters. If you run: pandoc -t latex -L highlight-red.lua -L in-red.lua <<< 'Some *==text in red==*!' You get: Some \colorbox{lightred}{{text in red}}! Le Sunday 26 March 2023 à 02:42:54AM, Pa Sc a écrit : > Do you mean the two filters that are in the original post? Or what filter do > you mean? > > Bastien DUMONT schrieb am Sonntag, 26. März 2023 um 00:08:53 UTC+1: > > Please share the two lua filters you use to parse `==` as a syntax for > highlighting and to print in red an emphasized span produced by this > filter. We can't figure out what is wrong without them. > > Le Saturday 25 March 2023 à 03:44:24PM, Pa Sc a écrit : > > Yeah, I have a MWE here: [1]https://tex.stackexchange.com/questions/ > 680766/ > > help-with-lua-filter-for-markdown-to-latex-with-pandoc > > > > As for the command: > > ``` > > mkdir -p /home/ME/Documents/Obsidian/Output/{{title}} > > pandoc -r markdown-auto_identifiers -w latex {{file_path:absolute}} -o / > home/ME > > /Documents/Obsidian/Output/{{title}}/{{title}}.tex --template="/home/ME/ > > Documents/LaTeX/My Templates/Proposal/default-proposal.tex" --lua-filter= > /home/ > > ME/Documents/LaTeX/Filters/highlight.lua --lua-filter=/home/ME/Documents/ > LaTeX/ > > Filters/highlight-period.lua --lua-filter=/home/ME/Documents/LaTeX/ > Filters/ > > Span.lua --lua-filter=/home/ME/Documents/LaTeX/Filters/highlight-red.lua > > --lua-filter=/home/ME/Documents/LaTeX/Filters/Span-red.lua > > ``` > > > > -- > > 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 [1]pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To view this discussion on the web visit [2][2]https://groups.google.com/ > d/msgid/ > > pandoc-discuss/6a7dabf5-1fda-4825-9d21-193b63363937n%[3] > 40googlegroups.com. > > > > References: > > > > [1] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > [2] [4]https://groups.google.com/d/msgid/pandoc-discuss/ > 6a7dabf5-1fda-4825-9d21-193b63363937n%40googlegroups.com?utm_medium=email& > utm_source=footer > > > -- > 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 [5]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit [6]https://groups.google.com/d/msgid/ > pandoc-discuss/aded6fcf-0720-4fea-a873-af2cacfb8281n%40googlegroups.com. > > References: > > [1] https://tex.stackexchange.com/questions/680766/ > [2] https://groups.google.com/d/msgid/ > [3] http://40googlegroups.com/ > [4] https://groups.google.com/d/msgid/pandoc-discuss/6a7dabf5-1fda-4825-9d21-193b63363937n%40googlegroups.com?utm_medium=email&utm_source=footer > [5] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > [6] https://groups.google.com/d/msgid/pandoc-discuss/aded6fcf-0720-4fea-a873-af2cacfb8281n%40googlegroups.com?utm_medium=email&utm_source=footer -- 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/ZCAWF2ex/yTJBEuH%40localhost. [-- Attachment #2: highlight-red.lua --] [-- Type: text/plain, Size: 2679 bytes --] --[[ Add support for a custom inline syntax. This pandoc Lua filter allows to add a custom markup syntax extension. It is designed to be adjustable; it should not be necessary to modify the code below the separator line. The example here allows to add highlighted text by enclosing the text with `==` on each side. Pandoc supports this for HTML output out of the box. Other outputs will need additional filters. Copyright: © 2022 Albert Krewinkel License: MIT ]] -- Lua pattern matching the opening markup string. local opening = [[==]] -- Lua pattern matching the closing markup string. local closing = [[==]] -- Toggle whether the opening markup may be followed by whitespace. local nospace = true -- Function converting the enclosed inlines to their internal pandoc -- representation. local function markup_inlines (inlines) return pandoc.Span(inlines, {class="mark-red"}) end ------------------------------------------------------------------------ local function is_space (inline) return inline and (inline.t == 'Space' or inline.t == 'LineBreak' or inline.t == 'SoftBreak') end function Inlines (inlines) local result = pandoc.Inlines{} local markup = nil local start = nil for i, inline in ipairs(inlines) do if inline.tag == 'Str' then if not markup then local first = inline.text:match('^' .. opening .. '(.*)') if first then start = inline -- keep element around in case the -- markup is not closed. Check if the -- closing pattern is already in this -- string. local selfclosing = first:match('(.*)' .. closing .. '$') if selfclosing then result:insert(markup_inlines{pandoc.Str(selfclosing)}) elseif nospace and first == '' and is_space(inlines[i+1]) then -- the opening pattern is followed by a space, but the -- config disallows this. result:insert(inline) else markup = pandoc.Inlines{pandoc.Str(first)} end else result:insert(inline) end else local last = inline.text:match('(.*)' .. closing .. '$') if last then markup:insert(pandoc.Str(last)) result:insert(markup_inlines(markup)) markup = nil else markup:insert(inline) end end else local acc = markup or result acc:insert(inline) end end -- keep unterminated markup if markup then markup:remove(1) -- the stripped-down first element result:insert(start) result:extend(markup) end return result end [-- Attachment #3: in-red.lua --] [-- Type: text/plain, Size: 296 bytes --] function Emph (emph) local content = emph.content if #content == 1 and content[1].t == 'Span' and content[1].classes:includes 'mark-red' then return { pandoc.RawInline('latex', '\\colorbox{lightred}{'), content[1], pandoc.RawInline('latex', '}') } end end ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Help with Lua filter for markdown to LaTeX with Pandoc 2023-03-26 9:53 ` Bastien DUMONT @ 2023-03-26 10:33 ` Pa Sc [not found] ` <39893365-8248-4286-ae04-560895d69212n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 0 siblings, 1 reply; 10+ messages in thread From: Pa Sc @ 2023-03-26 10:33 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 143 bytes --] Yay, that works! However, now I'm getting the problem that the red text is going off screen? Any ideas on that? Anyways, thank you so much :) ^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <39893365-8248-4286-ae04-560895d69212n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: Help with Lua filter for markdown to LaTeX with Pandoc [not found] ` <39893365-8248-4286-ae04-560895d69212n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2023-03-26 18:51 ` Bastien DUMONT 0 siblings, 0 replies; 10+ messages in thread From: Bastien DUMONT @ 2023-03-26 18:51 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw I guess that a \colorbox is a \hbox, so that it cannot be split. But this is a LaTeX problem that should be solved by searching how to use colors in LaTeX. Le Sunday 26 March 2023 à 03:33:18AM, Pa Sc a écrit : > Yay, that works! However, now I'm getting the problem that the red text is > going off screen? Any ideas on that? Anyways, thank you so much :) > > -- > 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 [1]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit [2]https://groups.google.com/d/msgid/ > pandoc-discuss/39893365-8248-4286-ae04-560895d69212n%40googlegroups.com. > > References: > > [1] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > [2] https://groups.google.com/d/msgid/pandoc-discuss/39893365-8248-4286-ae04-560895d69212n%40googlegroups.com?utm_medium=email&utm_source=footer -- 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/ZCCUG7AkXsn5FZla%40localhost. ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-03-26 18:51 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-03-25 12:42 Help with Lua filter for markdown to LaTeX with Pandoc Pa Sc [not found] ` <79ac7814-9558-4d49-a682-cf31f970d27dn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2023-03-25 14:38 ` Bastien DUMONT 2023-03-25 22:01 ` Pa Sc [not found] ` <bb3c6fab-dee9-48c4-81e4-7db67bc6931an-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2023-03-25 22:40 ` Bastien DUMONT 2023-03-25 22:44 ` Pa Sc [not found] ` <6a7dabf5-1fda-4825-9d21-193b63363937n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2023-03-25 23:08 ` Bastien DUMONT 2023-03-26 9:42 ` Pa Sc [not found] ` <aded6fcf-0720-4fea-a873-af2cacfb8281n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2023-03-26 9:53 ` Bastien DUMONT 2023-03-26 10:33 ` Pa Sc [not found] ` <39893365-8248-4286-ae04-560895d69212n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2023-03-26 18:51 ` Bastien DUMONT
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).