[fastpages] remove `# collapse-hide` in html file

I would like to remove the line

# collapse-hide

and other similar lines when a Jupyter notebook is converted to html.

I have in mind something like MathJax’s inlineMath: [ ['$','$'], ["\\(","\\)"] ] to replace characters. I would imagine this is a simple javascript with a suitable string.replace and regex, but I don’t have any familiarity with the language.

Any tip?

You would have to maybe add a post processing step to clean the HTML which will be located in a _site folder after you website is built (this doesn’t appear in your master branch because it is never committed when your site is built so you would have to edit the Actions), or in your gh-pages branch.

I’ve been thinking about this for a while; for me, it would make sense to remove all nbdev flags from generated HTML and md - but it probably makes most sense to introduce a flag to nbdev_build_docs etc so you have the option of stripping out flags or keeping current behavior.
I’d be happy to create a PR - but would like to get an idea of how many people would benefit from this change - the fastai team are super busy and I’m pushing quite a few changes to nbdev already.

If you’re interested in implementation details, I’m thinking we could;

  • add pre-processing callback to the convert functions
    • which would make it possible for anyone to write their own callbacks to modify a notebook before converting
  • write a callback to remove nbdev flags before converting
1 Like

I’ve just realised that all special flags will be removed from HTML if you start using magic flags https://pete88b.github.io/fastpages/nbdev/fastai/jupyter/2020/06/02/nbdev-magic.html

Details: We use https://nbdev.fast.ai/export/#split_flags_and_code for both nbdev_build_lib and nbdev_build_docs. The reason for this different behaviour is that we can’t write magic flags to .py library files.