zhaoterryy / mkdocs-pdf-export-plugin

An MkDocs plugin to export content pages as PDF files
MIT License
313 stars 44 forks source link

List index out of range error when using 'combined' option #48

Open ghost opened 5 years ago

ghost commented 5 years ago

Using version 0.5.5 of the plugin I get the following error when using the combined option:

Traceback (most recent call last):
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/bin/mkdocs", line 10, in <module>
    sys.exit(cli())
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/mkdocs/__main__.py", line 163, in build_command
    ), dirty=not clean)
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/mkdocs/commands/build.py", line 298, in build
    config['plugins'].run_event('post_build', config)
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/mkdocs/plugins.py", line 94, in run_event
    result = method(item, **kwargs)
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/mkdocs_pdf_export_plugin/plugin.py", line 119, in on_post_build
    self.renderer.write_combined_pdf(abs_pdf_path)
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/mkdocs_pdf_export_plugin/renderer.py", line 55, in write_combined_pdf
    render = self.render_doc(p[0], p[1], p[2])
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/mkdocs_pdf_export_plugin/renderer.py", line 37, in render_doc
    soup = prep_combined(soup, base_url, rel_url)
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/mkdocs_pdf_export_plugin/preprocessor/prep.py", line 16, in get_combined
    a['href'] = transform_href(a['href'], rel_url)
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/mkdocs_pdf_export_plugin/preprocessor/links/transform.py", line 17, in transform_href
    id = str.split(ext, '#')[1]
IndexError: list index out of range
lukasgeiter commented 5 years ago

I've had this issue as well. In my case it was due to a link with anchor but no file extension:

[click me](../foo#bar)

instead of

[click me](../foo.md#bar)
fschrempf commented 4 years ago

I can confirm this issue and in my case it was also caused by an anchor link without file extension.

dl1com commented 4 years ago

Same issue here. If I add the file extension, PDF generation works, but the link on the generated site does not work any longer (http://localhost:8000/foo/bar#baz -> OK, http://localhost:8000/foo/bar.md#baz -> 404 not found)