kirbs- / hide_code

Code, prompt and output hiding for Jupyter/IPython notebooks.
MIT License
371 stars 44 forks source link

Can't export with utf-8 #74

Closed jbmg17 closed 4 years ago

jbmg17 commented 5 years ago

I try to export in html, but in markdown cells I have text that contains "ó" or "á", so when I export to html this characters don't display well. How can export to html with utf-8 ?

Greetings.

kirbs- commented 5 years ago

Not sure what's going on here, but I'll check it out. Does the output look fine if you export with the stock nbconvert utility?

jbmg17 commented 5 years ago

Not sure what's going on here, but I'll check it out. Does the output look fine if you export with the stock nbconvert utility?

yes , if I convert using: $ jupyter nbconvert --to html mynotebook.ipynb the exported file is right with words in spanish like "opción" or "brújula" but the cells with code hided apear completily

ruifpedro commented 5 years ago

Not sure what's going on here, but I'll check it out. Does the output look fine if you export with the stock nbconvert utility?

I've been facing the same problem. It seems that when you open a file for reading in python, without specifying the encoding, it assumes the encoding that it deems fit for the content. This means that, if I create a fresh notebook file and try to open it, it assumes UTF-8 encoding. However, if the notebook has any content with accents ("á", etc) it will assume a different encoding, in my case ANSI_X3.4-1968, making it unable to read the file, since the default encoding that python assumes is ascii.

As a "quick fix" I just patched hide_code.py to include encoding="utf-8" in any open file operations. Perhaps you would consider this to be configurable.

Cjkjvfnby commented 5 years ago

As a "quick fix" I just patched hide_code.py to include encoding="utf-8" in any open file operations.

file: hide_code.py

Example of the code with the fix:


class HideCodeHTMLExportHandler(IPythonHandler):
    def get(self, *args):
        self.log.info("hide_code: Starting HTML export for {}".format(args[-1]))
        with open(ipynb_file_name(args), encoding="utf-8") as f: