Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

newlines in src do not work #37

Open
towi opened this issue Aug 3, 2023 · 1 comment
Open

newlines in src do not work #37

towi opened this issue Aug 3, 2023 · 1 comment

Comments

@towi
Copy link

towi commented Aug 3, 2023

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):]
@DCsunset
Copy link
Owner

DCsunset commented Aug 4, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants