public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: "krulis....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <krulis.tomas.tk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Lua filter to insert non-breable spaces
Date: Wed, 30 Sep 2020 05:40:31 -0700 (PDT)	[thread overview]
Message-ID: <62329746-0b8e-41f1-93d9-042398687631n@googlegroups.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 2124 bytes --]

I have the same situation as person asking here on discuss: 
<https://groups.google.com/g/pandoc-discuss/c/tZ2f51iLEIk/m/CSF_AWUXBQAJ>
I am trying to insert non-breakable spaces instead of specific Space 
elements in text. I tryed to work it out from example "Removing spaces 
before citations;" but I am probably using Inlines wrong.

I am asking this, because it seems that in the original question has no 
final answer/solution.

The filter I am using is as this:

```nonbreakableSpace.lua
function myCheckString(myString)
  if myString == 'a' or
  myString == 'i' then
    return true
  else
    return false
  end
end

function Inlines (inlines)
  for i = 1, #inlines do
    if inlines[i].t == 'Space' then
      if inlines[i - 1].t == 'Str' then
        local oneLetterPrefix = myCheckString(inlines[i - 1].c)
        if oneLetterPrefix == true then
          inlines[i - 1] = inlines[i - 1].c .. "\160" .. inlines[i + 1].c
          inlines:remove(i)
          inlines:remove(i + 1)
        end
      end
    end
  end
  return inlines
end
```

and very short test file:

```test.txt
a\ i test

a i test
```

Most probably it is evident that I am lua newbie. But the idea is to take 
list of Inlines, check every element if it is type Space, then check if 
previous element is Str, and then file check this strings contents, if it 
matches `myString` (names are horrible, I know). 

So the expected native pandoc out of the test is:

[Para [Str "a\160i\160test"]
Para [Str "a\160i\160test"]]

However, currently I am getting error:

nonbreakableSpace .lua:12: attempt to index a nil value (field '?')
stack traceback:
        pandocVlna.lua:12: in function 'Inlines'

How could I fix that?

Regards, Tomas

-- 
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/62329746-0b8e-41f1-93d9-042398687631n%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 3249 bytes --]

             reply	other threads:[~2020-09-30 12:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-30 12:40 krulis....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org [this message]
     [not found] ` <62329746-0b8e-41f1-93d9-042398687631n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2020-09-30 13:32   ` Albert Krewinkel
     [not found]     ` <87k0wbjsov.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2020-09-30 14:10       ` krulis....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
     [not found]         ` <3d7b4797-4d83-44fd-a65c-d612ab07a6dfn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2020-09-30 14:29           ` Albert Krewinkel
     [not found]             ` <87imbvjq1p.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2020-09-30 14:41               ` BPJ
     [not found]                 ` <CADAJKhDgxv6fYrNrxog5ZkJdai16SpFnJiOFZ8RtLhReQDoghA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-09-30 14:44                   ` Albert Krewinkel
2020-09-30 14:42               ` krulis....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
     [not found]                 ` <2e4fe1e0-39ce-438f-b2ec-fc57fd72cad0n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2020-09-30 14:46                   ` krulis....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
     [not found]                     ` <25ebada0-19c5-4ec4-a282-274308ee6b74n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2020-09-30 14:49                       ` krulis....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
     [not found]                         ` <e83f7a58-5718-4858-b536-e7b95de540a9n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2020-09-30 15:09                           ` BPJ
     [not found]                             ` <CADAJKhDh2zaKmuRKQYXRrf7MNOHrp-LkEEx2qoeV=oYPKb_Dzg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-09-30 15:13                               ` krulis....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

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=62329746-0b8e-41f1-93d9-042398687631n@googlegroups.com \
    --to=krulis.tomas.tk-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).