danielfrg / pelican-jupyter

Pelican plugin for blogging with Jupyter/IPython Notebooks
Apache License 2.0
423 stars 105 forks source link

Suppress CSS output #48

Closed mfitzp closed 7 years ago

mfitzp commented 8 years ago

Would it be possible to get a configuration variable for disabling the output of CSS (or at least for disabling the Pygments CSS)? I have a mix of notebooks and other code on my site and am using Pygments for the syntax highlighting — but it doesn't seem to be possible to override the theme applied to ipynb (without using lots of !important flags).

The ability to disable syntax highlighting completely (to support using JS-based highlighting options) would also be nice.

Casyfill commented 8 years ago

+1 on that. How can I overwrite ipython style?

danielfrg commented 8 years ago

This in is tricky guys :)

Removing all the ipython CSS will clearly result in something that is not presentable. Disabling their pygments might be possible.

It is possible to overwrite ipython/jupyter styles. I do that for my blog: https://github.com/danielfrg/danielfrg.github.io-source by just adding more CSS after the pelican converted html + css.

mfitzp commented 8 years ago

@danielfrg I was really wanting to 'disable' it so I could include it myself via a CSS file (from the theme/etc.) — the advantage being that it's easier to override things if you can add the custom styles after the notebook ones (plus smaller page size... hosting the CSS on a static domain, etc.)

I was after a variable to toggle this behaviour — definitely don't want to do this by default!

Casyfill commented 8 years ago

Exactly, that what I also end up using (a nasty hack around your hack):

def filter_css(style_text, path='plugins/ipynb/custom.css'):
        """
        HACK: IPython returns a lot of CSS including its own bootstrap.
        Get only the IPython Notebook CSS styles.
        """
        index = style_text.find('/*!\n*\n* IPython notebook\n*\n*/')
        if index > 0:
            style_text = style_text[index:]
        index = style_text.find('/*!\n*\n* IPython notebook webapp\n*\n*/')
        if index > 0:
            style_text = style_text[:index]

        style_text = re.sub(r'color\:\#0+(;)?', '', style_text)
        style_text = re.sub(r'\.rendered_html[a-z0-9,._ ]*\{[a-z0-9:;%.#\-\s\n]+\}', '', style_text)

        if path is not None and os.path.isfile(path):
            style_text += get_custom_css(path)
        else:
            print('custom.css is not found', os.getcwd())

        return '<style type=\"text/css\">{0}</style>'.format(style_text)

However, I guess I can just store "default" ipython css with my changes as an independent file, and replace all this functionalty with just link to this custom file.

danielfrg commented 8 years ago

I don't think you need a hack like that, you can just remove ipython_css from this line: content = ipython_css + content + LATEX_CUSTOM_SCRIPT @ https://github.com/danielfrg/pelican-ipynb/blob/master/core.py#L115 and no CSS will be injected.

danielfrg commented 8 years ago

Ok, I just added an IPYNB_IGNORE_CSS option that removes all CSS, hopefully that works better.

Casyfill commented 8 years ago

probably replacing this injection with just a link to my custom css should do what I want. Thanks!

KentChun33333 commented 7 years ago

@danielfrg Thanks for the modification, by setting IPYNB_IGNORE_CSS = True, everything works perfectly : )

mfitzp commented 7 years ago

Thanks for this @danielfrg works great. I've just opened a PR to document this in the README.