Code Monkey home page Code Monkey logo

Comments (4)

jcolson avatar jcolson commented on May 24, 2024

changing the code to print a bit:

        for l in re.findall(r'^(\<inclusion href="[^"]*" />)', self.page, re.MULTILINE):
            link = l.replace('<inclusion href="', '').replace('" />', '')
            link_lookup = GetObsidianFilePath(link, self.file_tree)
            print(link)
            print(link_lookup[0])
            print(link_lookup[1])
            file_record = link_lookup[1]
            if len(link_lookup) >= 3:
                print(link_lookup[2])
                header = link_lookup[2]

results in:

Hymey.jpg|300
Hymey.jpg.md
False
Traceback (most recent call last):
  File "/opt/homebrew/bin/obsidianhtml", line 8, in <module>
    sys.exit(main())
  File "/opt/homebrew/lib/python3.9/site-packages/obsidianhtml/__init__.py", line 365, in main
    recurseObisidianToMarkdown(str(paths['obsidian_entrypoint']), pb)
  File "/opt/homebrew/lib/python3.9/site-packages/obsidianhtml/__init__.py", line 75, in recurseObisidianToMarkdown
    recurseObisidianToMarkdown(files[link_path]['fullpath'], pb)
  File "/opt/homebrew/lib/python3.9/site-packages/obsidianhtml/__init__.py", line 75, in recurseObisidianToMarkdown
    recurseObisidianToMarkdown(files[link_path]['fullpath'], pb)
  File "/opt/homebrew/lib/python3.9/site-packages/obsidianhtml/__init__.py", line 49, in recurseObisidianToMarkdown
    md.ConvertObsidianPageToMarkdownPage(paths['md_folder'], paths['obsidian_entrypoint'])
  File "/opt/homebrew/lib/python3.9/site-packages/obsidianhtml/MarkdownPage.py", line 288, in ConvertObsidianPageToMarkdownPage
    self.links.append(file_record['fullpath'])
TypeError: 'bool' object is not subscriptable

from obsidian-html.

dwrolvink avatar dwrolvink commented on May 24, 2024

Hi @jcolson thanks for your bug report.

This bug/issue has to do with the fact that code inclusions and images both use the same tags.
For example, you can create an inclusion of a page by doing ![[Note name]], and you can include an image by doing ![[Hymey.jpg]].

Now to discern between the two is done naively by looking at the suffix of the link:

if len(link.split('.')) == 1 or link.split('.')[-1] not in image_suffixes:

Now, the problem is that you've used ![[Hymey.jpg|300]]. This is a feature that I wasn't aware of. It's for setting the width it looks like? My code is too dumb to account for this. I could replicate your issue by adding |300 behind a local image.

A simple fix should be to change the code above to:

if len(link.split('.')) == 1 or link.split('.')[-1].split('|')[0] not in image_suffixes:

Notice the .split('|')[0]

The next issue would be the following block, which needs a similar cleanup step:

if urllib.parse.unquote(link).split('/')[-1] not in self.file_tree.keys():
continue
# Build relative paths
src_file_path_str = self.file_tree[urllib.parse.unquote(link).split('/')[-1]]['fullpath']

I've added these changes to c11e004 and tested it, this works for me.

Note that now the size annotation gets stripped. If you need this to carry over into the html output please make another issue for that (feature request), because that will take some more time to get done right.

I'll keep this issue open to remind me to fix the fact that this part of the code gives a very cryptic error at moment when an image gets parsed wrong.

Let me know if this fix works for you too!
(n.b. the pypi package isn't updated yet so use the git code directly)

from obsidian-html.

dwrolvink avatar dwrolvink commented on May 24, 2024

Looked into it, and for now there isn't really a good solution to the error except for just making sure that the function always returns the same type of struct. There is a whole flow to parsing and there isn't one point or one check that can make sure we get better errors in the future. If anything the fact that it bugged out here made it easy to find the problem.

Setting this as solved, if anyone bumps their head on this in the future maybe we can revisit it.

from obsidian-html.

jcolson avatar jcolson commented on May 24, 2024

adding 'pdf' to image_suffixes = ['jpg', 'jpeg', 'gif', 'png', 'bmp'] seems to resolve.

from obsidian-html.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.