Comments (15)
That's a good point. I think a way to solve this is to make the default behaviour emit a warning. Meanwhile, we can provide an environment variable to force an error if it's set.
from pandoc-include.
@studerluk Actually, I found a better way to solve this. The extra tags are added because it uses extended Markdown syntax. For file include, we don't want them so it's better to use markdown_strict
, which prevents adding such tags.
from pandoc-include.
@studerluk Thanks for looking into it. I think probably we can adopt your second approach to ignore all contents in the curly braces after the quote (still able to capture other input errors).
I don't fully yet understand the regex to make the change by myself. Do you know what
\9
means in the regex? You can also submit a PR to fix it if you are willing to.
\9
references the 9th capture group of the regex. In this case ([\`\'\"])
from pandoc-include.
The latest commit should address this issue. You could install the latest version from git if you want to test it immediately
from pandoc-include.
Hi @DCsunset,
With the latest commit, I get this error:
Traceback (most recent call last):
File "/usr/local/bin/pandoc-include", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.10/dist-packages/pandoc_include/main.py", line 408, in main
return pf.run_filter(action, doc=doc)
File "/usr/local/lib/python3.10/dist-packages/panflute/io.py", line 227, in run_filter
return run_filters([action], *args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/panflute/io.py", line 208, in run_filters
doc = doc.walk(action, doc=doc, stop_if=stop_if)
File "/usr/local/lib/python3.10/dist-packages/panflute/base.py", line 264, in walk
child = child.walk(action, doc, stop_if)
File "/usr/local/lib/python3.10/dist-packages/panflute/base.py", line 264, in walk
child = child.walk(action, doc, stop_if)
File "/usr/local/lib/python3.10/dist-packages/panflute/containers.py", line 152, in walk
ans = [(k, v) for k, v in ans if v != []]
File "/usr/local/lib/python3.10/dist-packages/panflute/containers.py", line 152, in <listcomp>
ans = [(k, v) for k, v in ans if v != []]
File "/usr/local/lib/python3.10/dist-packages/panflute/containers.py", line 151, in <genexpr>
ans = ((k, v.walk(action, doc, stop_if)) for k, v in self.items())
File "/usr/local/lib/python3.10/dist-packages/panflute/base.py", line 264, in walk
child = child.walk(action, doc, stop_if)
File "/usr/local/lib/python3.10/dist-packages/panflute/containers.py", line 86, in walk
ans = list(chain.from_iterable(ans))
File "/usr/local/lib/python3.10/dist-packages/panflute/containers.py", line 84, in <genexpr>
ans = ((item,) if type(item) is not list else item for item in ans)
File "/usr/local/lib/python3.10/dist-packages/panflute/containers.py", line 82, in <genexpr>
ans = (item.walk(action, doc, stop_if) for item in self)
File "/usr/local/lib/python3.10/dist-packages/panflute/base.py", line 272, in walk
altered = action(self, doc)
File "/usr/local/lib/python3.10/dist-packages/pandoc_include/main.py", line 238, in action
options = parseOptions(doc)
File "/usr/local/lib/python3.10/dist-packages/pandoc_include/config.py", line 110, in parseOptions
if options["process-path"] is None:
KeyError: 'process-path'
Error running filter pandoc-include:
Filter returned error status 1
Note that I am running it all in docker, and this is how I installed your latest fix (might have done it wrong?):
RUN pip3 install --force-reinstall git+https://github.com/DCsunset/pandoc-include.git#egg=pandoc-include
from pandoc-include.
Let's ignore the problem with process-path
, maybe that's something with my environment... I've moved to the local machine (no docker), and still I have these failures:
(local_pandoc) dperets@dperets-mac wptest % cat test-include.md
!include filters.md
(local_pandoc) dperets@dperets-mac wptest % cat filters.md
### pandoc-include
!include <file-doesnt-exist>
$include <file-doesnt-exist>
```
!include <file>
$include <file>
```
Result:
(local_pandoc) dperets@dperets-mac wptest % pandoc test-include.md --filter pandoc-include -o test-include.html
[INFO] including file 'filters.md'... ok
Traceback (most recent call last):
File "/Users/dperets/git/wptest/local_pandoc/bin/pandoc-include", line 8, in <module>
sys.exit(main())
^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/pandoc_include/main.py", line 408, in main
return pf.run_filter(action, doc=doc)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/panflute/io.py", line 227, in run_filter
return run_filters([action], *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/panflute/io.py", line 208, in run_filters
doc = doc.walk(action, doc=doc, stop_if=stop_if)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/panflute/base.py", line 264, in walk
child = child.walk(action, doc, stop_if)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/panflute/containers.py", line 86, in walk
ans = list(chain.from_iterable(ans))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/panflute/containers.py", line 84, in <genexpr>
ans = ((item,) if type(item) is not list else item for item in ans)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/panflute/containers.py", line 82, in <genexpr>
ans = (item.walk(action, doc, stop_if) for item in self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/panflute/base.py", line 272, in walk
altered = action(self, doc)
^^^^^^^^^^^^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/pandoc_include/main.py", line 248, in action
includeType, name, config = is_include_line(elem)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/pandoc_include/main.py", line 87, in is_include_line
includeType, name, config = extract_info(rawString)
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/pandoc_include/main.py", line 60, in extract_info
raise ValueError(f"Unable to extract info from include line {rawString}")
ValueError: Unable to extract info from include line !include `<file-doesnt-exist>`{=html}
Error running filter pandoc-include:
Filter returned error status 1
Traceback (most recent call last):
File "/Users/dperets/git/wptest/local_pandoc/bin/pandoc-include", line 8, in <module>
sys.exit(main())
^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/pandoc_include/main.py", line 408, in main
return pf.run_filter(action, doc=doc)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/panflute/io.py", line 227, in run_filter
return run_filters([action], *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/panflute/io.py", line 208, in run_filters
doc = doc.walk(action, doc=doc, stop_if=stop_if)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/panflute/base.py", line 264, in walk
child = child.walk(action, doc, stop_if)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/panflute/containers.py", line 86, in walk
ans = list(chain.from_iterable(ans))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/panflute/containers.py", line 84, in <genexpr>
ans = ((item,) if type(item) is not list else item for item in ans)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/panflute/containers.py", line 82, in <genexpr>
ans = (item.walk(action, doc, stop_if) for item in self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/panflute/base.py", line 272, in walk
altered = action(self, doc)
^^^^^^^^^^^^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/pandoc_include/main.py", line 329, in action
new_doc = pf.convert_text(
^^^^^^^^^^^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/panflute/tools.py", line 487, in convert_text
out = inner_convert_text(text, in_fmt, out_fmt, extra_args, pandoc_path=pandoc_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/panflute/tools.py", line 510, in inner_convert_text
out = run_pandoc(text, args, pandoc_path=pandoc_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/panflute/tools.py", line 408, in run_pandoc
raise IOError('')
OSError
Error running filter pandoc-include:
Filter returned error status 1
from pandoc-include.
Since you can run it locally, could you try running the test in this repo? You just need to clone it and run make
in the test directory? I'm not sure why it still shows an exception but maybe it is the issue of the version you installed.
from pandoc-include.
Also, I've fixed the previous KeyError in case the application state is corrupted due to some reason.
from pandoc-include.
@DCsunset I managed to run it, but I found two remaining issues with non-existing files:
First - it doesn't like the "< >". So this crashes:
!include <file-doesnt-exist>
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/pandoc_include/main.py", line 60, in extract_info
raise ValueError(f"Unable to extract info from include line {rawString}")
ValueError: Unable to extract info from include line !include `<file-doesnt-exist>`{=html}
... but this works fine:
!include file-doesnt-exist
Second - include inside fenced code blocks still has the original issue, that is, it raises IOError exception instead of the warning:
```
!include file-doesnt-exist
```
File "/Users/dperets/git/wptest/local_pandoc/lib/python3.11/site-packages/pandoc_include/main.py", line 379, in action
raise IOError(f"File not found: {name}")
OSError: File not found: file-doesnt-exist
Note: pandoc-include 1.2.0 handles both these issues successfully.
from pandoc-include.
The first case is caused by a failed regex match. Do you have any idea why it fails? @studerluk
I have fixed the second case in the latest commit.
from pandoc-include.
Looking at the error message I assume this happens because pandoc is treating the filename placeholder as HTML (note the added {=html}
):
Raw include line from error message: !include `<file-doesnt-exist>`{=html}
The regex pattern expects the include line to be finished after the filename which wouldn't be the case with the addition of {=html}
Of the top of my head I see two possible solutions that might resolve the issue:
- Remove the line ending condition from the regex pattern.
- Add handling of such added tags, like
{=html}
, to the regex pattern for them to be ignored.
In the mean time @dmitryperets you can maybe try putting the place holder in code ticks to try to force pandoc to not treat it as HTML tag: !include `<file-doesnt-exist>`
from pandoc-include.
@studerluk Thanks for looking into it. I think probably we can adopt your second approach to ignore all contents in the curly braces after the quote (still able to capture other input errors).
I don't fully yet understand the regex to make the change by myself. Do you know what \9
means in the regex? You can also submit a PR to fix it if you are willing to.
from pandoc-include.
@dmitryperets The latest commit should fix all the above issues. Feel free to try it again.
from pandoc-include.
@DCsunset I confirm that the latest version successfully passes all my tests. Thanks!
from pandoc-include.
The fix is included in v1.3.0. Closing it now.
from pandoc-include.
Related Issues (20)
- Bug with code blocks (containing tab?) HOT 2
- Another issue with code blocks and horizontal lines HOT 3
- Included figures with relative paths are not found HOT 3
- Comments in code blocks returns error HOT 1
- Hard line breaks are not preserved HOT 1
- Invalid API Version HOT 1
- Error: invalid api version HOT 3
- Parameterized include HOT 2
- files with _ (underscore) in their name HOT 1
- No longer automatically inserting pagebreaks HOT 2
- Adjust section level in included markdown files HOT 12
- support mdbook include syntax HOT 1
- add id-prefix option
- Could not find executable pandoc-include HOT 3
- newlines in src do not work HOT 1
- invalid api version? HOT 3
- Filename's underscore gets escaped? HOT 2
- Support for `sourcepos` extension recursively, to provide sync-preview. HOT 3
- Release 1.3.1 not available in Pypi HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pandoc-include.