Skip to content

[BUG] IndexError: list index out of range #6

Closed
@ooker777

Description

@ooker777

Say my mkdocs.yaml is:

site_name: test
site_url: https://example.com
plugins:
  - embed_file:
      callouts: true

and in the docs folder I have 2 files: a.md and b.md. The content of a.md is:

![z](b)

And the content of b.md is:

[](index)

Running mkdocs build returns this error:

INFO    -  Cleaning site directory
INFO    -  Building documentation to directory: D:\QC
           supplements\Code\Websites\CW-obsidian-quan-ly-du-an-va-cong-cu-nghi\site
WARNING -  Doc file 'b.md' contains a relative link
           'index.md', but the target is not found     
           among documentation files.
ERROR   -  Error building page 'a.md': list index out
           of range
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\ganuo\AppData\Local\Programs\Python\Python311\Scripts\mkdocs.exe\__main__.py", line 7, in <module>
  File "C:\Users\ganuo\AppData\Local\Programs\Python\Python311\Lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ganuo\AppData\Local\Programs\Python\Python311\Lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "C:\Users\ganuo\AppData\Local\Programs\Python\Python311\Lib\site-packages\click\core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ganuo\AppData\Local\Programs\Python\Python311\Lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)     
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^     
  File "C:\Users\ganuo\AppData\Local\Programs\Python\Python311\Lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ganuo\AppData\Local\Programs\Python\Python311\Lib\site-packages\mkdocs\__main__.py", line 286, in build_command
    build.build(cfg, dirty=not clean)
  File "C:\Users\ganuo\AppData\Local\Programs\Python\Python311\Lib\site-packages\mkdocs\commands\build.py", line 349, in build
    _build_page(
  File "C:\Users\ganuo\AppData\Local\Programs\Python\Python311\Lib\site-packages\mkdocs\commands\build.py", line 235, in _build_page
    output = config.plugins.on_post_page(output, page=page, config=config)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ganuo\AppData\Local\Programs\Python\Python311\Lib\site-packages\mkdocs\plugins.py", line 586, in on_post_page
    return self.run_event('post_page', output, page=page, config=config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ganuo\AppData\Local\Programs\Python\Python311\Lib\site-packages\mkdocs\plugins.py", line 507, in run_event
    result = method(item, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ganuo\AppData\Local\Programs\Python\Python311\Lib\site-packages\mkdocs_embed_file_plugins\plugin.py", line 201, in on_post_page
    soup = cite(
           ^^^^^
  File "C:\Users\ganuo\AppData\Local\Programs\Python\Python311\Lib\site-packages\mkdocs_embed_file_plugins\plugin.py", line 77, in cite
    quote = convert_links_if_markdown(quote, (docs, url, md_link_path))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ganuo\AppData\Local\Programs\Python\Python311\Lib\site-packages\mkdocs_embed_file_plugins\src\links_correction.py", line 28, in convert_links_if_markdown
    url = create_url(internal_link, link[1], base, url_blog_path, False)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ganuo\AppData\Local\Programs\Python\Python311\Lib\site-packages\mkdocs_embed_file_plugins\src\links_correction.py", line 47, in create_url
    search_file_in_documentation(link, md_link_path.parent, base)
  File "C:\Users\ganuo\AppData\Local\Programs\Python\Python311\Lib\site-packages\mkdocs_embed_file_plugins\src\search_quote.py", line 62, in search_file_in_documentation
    linksBaseEquals = [i for i in linksParent if i in baseParent][0]
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

The link in a must point to b and be in the embed syntax, and the link in b must contain index in order to get this bug.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions