pandoc-include icon indicating copy to clipboard operation
pandoc-include copied to clipboard

newlines in src do not work

Open towi opened this issue 2 years ago • 1 comments

When my included source code contained a newline I got a backtrace:

Traceback (most recent call last):
  File "/usr/bin/pandoc-include", line 8, in <module>
    sys.exit(main())
  File "/usr/lib/python3.10/site-packages/pandoc_include/main.py", line 333, in main
    return pf.run_filter(action, doc=doc)
...
  File "/usr/lib/python3.10/site-packages/pandoc_include/main.py", line 309, in action
    codes.append(read_file(fn, config))
  File "/usr/lib/python3.10/site-packages/pandoc_include/main.py", line 160, in read_file
    content = "\n".join(dedent(content, config["dedent"]))
TypeError: sequence item 4: expected str instance, NoneType found
Error running filter pandoc-include:
Filter returned error status 1

I fixed this by adding a check in removeLeadingWhitespaces():

def removeLeadingWhitespaces(s, num):
    if not s.strip():  # <<< empty lines didn't work
        return s
    regex = re.compile(r"[^\s]")
    m = regex.search(s)
    if m == None:
        return
    pos = m.span()[0]
    if num < 0:
        return s[pos:]
    else:
        return s[min(pos, num):]

towi avatar Aug 03 '23 14:08 towi

Hi, I'm using a cpp file with only a newline in it and include it in another file simply like the following:

```cpp
!include empty.cpp
```

But I'm unable to reproduce this error. Could you provide a minimum test case?

DCsunset avatar Aug 04 '23 14:08 DCsunset