Code Monkey home page Code Monkey logo

Comments (13)

sgugger avatar sgugger commented on August 19, 2024 1

No we won't go back to '<img src' since it doesn't display properly normal images with good resolution (examples: screenshots in the index of nbdev.fast.ai). We can add a hack for embedded images instead.

from nbdev.

drscotthawley avatar drscotthawley commented on August 19, 2024

One way to remove the errors is to add a return right before the os.makedirs() line, (line 142):

        if (src.startswith('http://') or src.startswith('https://')): return

Doing this solved my errors with external image URLs. (EDIT: see below, all this did was strip out the images though.)

Now...embedded objects (e.g. plots from plot.ly) are also being treated as they were files too. These extremely long strings then produce "filename too long" errors. Ideally, I'd imagine one would want to simply leave these things alone and 'pass them through', since they are already HTML.

from nbdev.

drscotthawley avatar drscotthawley commented on August 19, 2024

Ok, fixed the embedded object problem too:

        if (src.startswith('http://') or src.startswith('https://') or src.startswith('data:image/')): return

...So now the build will complete without errors, and the plot.ly interactive plots work in the generated .html file, BUT...

but actually the external images links aren't present in the final html file!

So, my 'fix' return statement only seems to strip out the external images entirely.

from nbdev.

sgugger avatar sgugger commented on August 19, 2024

I think there were a few more things to add, but I added tests and all seems to pass now.

from nbdev.

drscotthawley avatar drscotthawley commented on August 19, 2024

Oh great! That fixes the external image problem. Thanks!

Now, could you also add a

        if src.startswith('data:image/'): return

...to the line immediately before the os.makedirs() line in copy_images()?

Doing this will allow imbedded object-images such as interactive plots from plot.ly to work perfectly. :-)

from nbdev.

sgugger avatar sgugger commented on August 19, 2024

I added that. Can you make one last test on your side before we make a release?

from nbdev.

drscotthawley avatar drscotthawley commented on August 19, 2024

Thanks. Gladly. Um...I will need to read up on your methodologies for contributing tests the way you like. My naive method would be to add an entire new .ipynb file in the repo to test against, but I'm guessing that would be too 'bulky' for fastai style.

from nbdev.

sgugger avatar sgugger commented on August 19, 2024

Oh no, I was just saying: test is on fastpage with your own notebooks to make sure all works okay, not add some tests to nbdev. :)

from nbdev.

drscotthawley avatar drscotthawley commented on August 19, 2024

Oh, ok! Great.
I see that your version has "return cell" for that new line, whereas my version just has "return".

In running these on my test notebook file,Your version produces errors that halt the code (see below), whereas mine runs to completion but ...on closer inspection...produces output HTML which is slightly mangled -- the data:image parts load, but in the resulting HTML it has "paragraph symbols" (ΒΆ) at the right side of each markdown heading.

Output from export2html.notebook2html with the nbdev currently in the official repo:

sequence item 1: expected str instance, NotebookNode found
Traceback (most recent call last):
  File "_action_files/nb2post.py", line 37, in <module>
    export2html.notebook2html(fname='_notebooks/*.ipynb', dest='_posts/', template_file='_action_files/fastpages.tpl')
  File "/home/shawley/nbdev/nbdev/export2html.py", line 432, in notebook2html
    raise Exception(msg + '\n'.join([f.name for p,f in zip(passed,files) if not p]))
Exception: Conversion failed on the following:
2019-12-21-PCA-From-Scratch.ipynb

from nbdev.

sgugger avatar sgugger commented on August 19, 2024

I thought your line was weird but mine was worse ;). Tried something else to unify the approaches, let me know if it works better.

from nbdev.

drscotthawley avatar drscotthawley commented on August 19, 2024

I think it's fine now, thanks. But to be sure, would you mind taking a look the HTML output for the nbdev/nbs/tutorial.ipynb page that I just created using your newest export2html code, to make sure it looks like you want it to?
Posting it here: https://hedges.belmont.edu/~shawley/2020-02-18-nbdev-tutorial.html

It also has the "paragraph symbols", and I'm not sure if they're supposed to be there.

from nbdev.

drscotthawley avatar drscotthawley commented on August 19, 2024

...wait, none of the inline math is rendering now, such as $x$ or $f(x)$.
Full-line math (with $$) is rendering ok in one of my notebooks, but not in another.

from nbdev.

drscotthawley avatar drscotthawley commented on August 19, 2024

As per fastai/fastpages#71, HTML "<img src" is getting translated into Liquid "{% img" by nbdev. This breaks embedded image objects because Liquid can't handle the long strings.
Might prefer for nbdev to leave "<img src" as is, and not translate it to Liquid.

from nbdev.

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.