Nbconvert: TagRemovePreprocessor.remove_cell_tags generated empty spaces in html

Created on 22 Dec 2018  路  1Comment  路  Source: jupyter/nbconvert

I am using nbconvert to execute a notebook and turn its output into HTML. By default, I remove the cell blocks from the output. Besides, I also apply a 'Hide' tag on markdown cells (mostly headings) which I do not want in the report.

The problem is this. The tagged markdown cells are hidden, but there are considerable whitespaces in their place which together add up into a big 'hole' in the report. It does the same with simple html and html_ch (i.e. with collapsable headings) but for pdf, the whitespaces disappear.

Is there an easy way to remove the whitespace in HTML? Or I can do this only by creating a template?

Here is the code I use:

Jupiter nbconvert --execute notebook.ipynb --TemplateExporter.exclude_input=True --TagRemovePreprocessor.remove_cell_tags={\"Hide\"} --to html_ch
good first issue

Most helpful comment

Ran into this same issue: found a hack for this.

Add this cell in the notebook; it hides all "blank" cells.

from IPython.display import HTML

HTML('''<script>
$(document).ready(function() {

  all_cells = $('div.cell.border-box-sizing.code_cell.rendered')

  $.each(all_cells, function(idx, val){
      if ($(val).find('div.output_wrapper').length === 0){
        $(val).hide();
      }
    });
  });

</script>
''')

>All comments

Ran into this same issue: found a hack for this.

Add this cell in the notebook; it hides all "blank" cells.

from IPython.display import HTML

HTML('''<script>
$(document).ready(function() {

  all_cells = $('div.cell.border-box-sizing.code_cell.rendered')

  $.each(all_cells, function(idx, val){
      if ($(val).find('div.output_wrapper').length === 0){
        $(val).hide();
      }
    });
  });

</script>
''')
Was this page helpful?
0 / 5 - 0 ratings