Escape Liquid Tags Present in Code / Code Output #66
Comments
..So I see that the "monkey patch" in Would it work to reverse the order in the build? : Run Liquid on the file with the .html extension, and then change the extension to .md afterward? EDIT: looks like from this StackOverflow post one could disable Liquid via the import glob
# escape javascript sequences from Liquid via "raw" tag
def js_escape_liquid(fname='_notebooks/*.ipynb', dest='_posts/'):
for nb_name in glob.glob(fname):
md_name = dest+os.path.basename(nb_name).replace('.ipynb','.md')
if os.path.exists(md_name):
fin = open(md_name, "rt")
data = fin.read()
if '<script ' in data:
data = data.replace('<script ', '\n{% raw %}\n<script ')
data = data.replace('/script>', '/script>\n{% endraw %}\n ')
fin.close()
fin = open(md_name, "wt")
fin.write(data)
fin.close()
js_escape_liquid() ...Sticking that code at the end of |
Yeah I knew this was going to happen at some point, going to have to escape code blocks. Will put this on the backlog |
@drscotthawley this looks like it has been fixed in the latest version of nbdev, the one line change you applied looks like it was on an old version of nbdev. Do you want to test it out and see how it goes now? I think you have two separate issues that you need to break out separately. |
Actually I know how to fix this. working on it now |
Ok the issue with external images is totally fixed in the latest nbdev. And the issue with nbdev & plot.ly is fixed. But the Liquid problems, which are the subject of this issue, those are still in play. That little 'escape' code snippet above temporarily got plotl.ly working for me, but now the updates to nbdev seem to have broken that. Or they've introduced a similar issue with an embedded draw.io object. I'm not sure, here's what I see:
See this run: https://github.com/drscotthawley/devblog2/runs/453635808?check_suite_focus=true So, I think this issue might still be unresolved. |
I found a tricky interaction between nbdev & the fastpages build. nbdev is replacing "<img src=" HTML code with Liquid "{% img src" tags. This might not be a problem ordinarily, but when running with Liquid in fastpages, it can't handle long "src" strings. So here's a question for both @sgugger and @hamelsmu: The original HTML code in question:
This is getting converted by nbdev to
|
@drscotthawley do you have a code snippet you can give me to test out your plotly graph? I can add it to the demo notebook. |
Closed this in favor of #71 |
Yes! Just created one. Check this out: EDIT: GitHub doesn't show the plot.ly graph, but when you load up the notebook in jupyter, or if you have HTML created by exporting HTML from jupyter (or from Google Colab), the graph appears. |
@drscotthawley lets take the conversation to the new issue, thanks so much for all your troubleshooting! You nudged me to figure out how to escape liquid in code blocks! Love your participation in this journey with us ❤️ |
I realize fastpages currently is only designed to work with Altair. Altair doesn't support 3D graphs, but plot.ly does. One of my notebooks uses plot.ly for interactive 3D graphs.
With a one-line change to nbdev (https://github.com/drscotthawley/nbdev/blob/master/nbdev/export2html.py), the embedded plot.ly 3D interactive graphs work fine, and the resulting html from nbdev/export2html shows these plots great. (Example HTML output of notebook from nbdev/export2html: https://hedges.belmont.edu/~shawley/2019-12-21-PCA-From-Scratch.html)
The problem is that further down in the fastpages build, the 'Rendering Liquid' step tries to treat some of the double-curly-brace javascript generated for plot.ly as if it were Liquid tags:
The javascript code it's complaining about looks like this:
I have no experience with Liquid, at all. My old Jekyll/Pages blog doesn't use it, so there was no conflict. But FastPages does use it. Is there any way to 'tell Liquid' to leave the plot.ly javascript alone and not try to interpret it as a tag? (I've googled around trying to solve this, but so far, no dice.)
Or perhaps there's a way to disable Liquid for certain files but not for the whole fastpages blog?
Run log: https://github.com/drscotthawley/devblog2/runs/451929186?
The text was updated successfully, but these errors were encountered: