public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: BPJ <melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Re: removing highlights and escape values
Date: Mon, 8 May 2023 17:59:00 +0200	[thread overview]
Message-ID: <CADAJKhA_g=6gfAJONkb3AwdQ9Xqn8PvwUg-fAVEjsKE56++gFg@mail.gmail.com> (raw)
In-Reply-To: <ef709575-3717-493f-b6d8-62862c98d3d8n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 3139 bytes --]

Don't use ChatGPT to "write code"! You will get garbage which may harm your
computer and/or files if you run it!

This filter will do what you want:

``````lua
local str = pandoc.Str
local function quote (q)
  return pandoc.RawInline('markdown', q)
end
local quote_pat = re.compile(
  [[ {| ( [^"']+ -> str / ["'] -> quote )* |} ]],
  { str = str, quote = quote }
)
function Str (elem)
  return quote_pat:match(elem.text)
end
function Span (elem)
  if 1 == #elem.classes and 'mark' == elem.classes[1] then
    return elem.content
  end
  return nil
end
``````

/bpj

Den mån 8 maj 2023 00:09Mark Pinsley <mark-NHpudssogepBDgjK7y7TUQ@public.gmane.org> skrev:

> I have a bunch of docx that I want to convert to MD.
>
> The file contains highlighting and it also contains both quotes and double
> quotes
>
> For ease of someone being able to look at this MD, i want to remove the
> escape sequece for the quotes and double quotes.
>
> I also want to remove the highlighting
>
> ChatGPT wrote this LUA for me but it doesn't seem to work. Are there
> alternatives
>
> function process_inlines(inlines)
>     local result = {}
>     for _, inline in ipairs(inlines) do
>         if inline.t == "Str" then
>             inline.text = inline.text:gsub('\\"', '"'):gsub("\\'", "'")
>         elseif inline.content then
>             inline.content = process_inlines(inline.content)
>         end
>         table.insert(result, inline)
>     end
>     return result
> end
>
> function process_blocks(blocks)
>     local result = {}
>     for _, block in ipairs(blocks) do
>         if block.content then
>             block.content = process_inlines(block.content)
>         end
>         table.insert(result, block)
>     end
>     return result
> end
>
> function Pandoc(doc)
>     doc.blocks = process_blocks(doc.blocks)
>     return doc
> end
>
> the command I used was:
>  pandoc "TestHighlightQuotes.docx" --lua-filter remove_escaped_quotes.lua
> --wrap=none --reference-links -o output.md
>
> Is there another way, or did I do something wrong?
>
> --
> 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/ef709575-3717-493f-b6d8-62862c98d3d8n%40googlegroups.com
> <https://groups.google.com/d/msgid/pandoc-discuss/ef709575-3717-493f-b6d8-62862c98d3d8n%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/CADAJKhA_g%3D6gfAJONkb3AwdQ9Xqn8PvwUg-fAVEjsKE56%2B%2BgFg%40mail.gmail.com.

[-- Attachment #2: Type: text/html, Size: 4784 bytes --]

  parent reply	other threads:[~2023-05-08 15:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-07 22:08 Mark Pinsley
     [not found] ` <ef709575-3717-493f-b6d8-62862c98d3d8n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-05-08 15:59   ` BPJ [this message]
     [not found]     ` <CADAJKhA_g=6gfAJONkb3AwdQ9Xqn8PvwUg-fAVEjsKE56++gFg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-05-08 17:28       ` Mark Pinsley
     [not found]         ` <CAOtJyj5-+o3=w-dT1wYbusgTsRv=0JA5J3LE96mN53sAE9eQkg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-05-09 10:58           ` Stephan Meijer
     [not found]             ` <bc3186fd-822a-40da-99d2-9454caeabb3en-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-05-09 17:44               ` BPJ

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADAJKhA_g=6gfAJONkb3AwdQ9Xqn8PvwUg-fAVEjsKE56++gFg@mail.gmail.com' \
    --to=melroch-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).