public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Lua filter to insert non-breable spaces
@ 2020-09-30 12:40 krulis....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
       [not found] ` <62329746-0b8e-41f1-93d9-042398687631n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 11+ messages in thread
From: krulis....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org @ 2020-09-30 12:40 UTC (permalink / raw)
  To: pandoc-discuss


[-- 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 --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-09-30 15:13 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-30 12:40 Lua filter to insert non-breable spaces krulis....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
     [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

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).