Skip to content

Commit ab85139

Browse files
authored
Merge pull request #162 from man-group/fix-code-hiding-without-jquery
Fix input cell hiding in nbconvert>6
2 parents ae30e26 + 58f2e0e commit ab85139

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

notebooker/nbtemplates/notebooker_html_output.tpl

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,37 @@ div div.cell {
3838
var code_blocks = [
3939
'.input',
4040
'.prompt',
41-
'.output_stream'
41+
'.output_stream',
42+
'.jp-outputPrompt',
43+
'.jp-inputPrompt',
44+
'.jp-InputArea-editor',
45+
'.jp-RenderedText'
4246
];
4347
var show_code = function(){
4448
code_blocks.forEach(
45-
function(block){
46-
$(block).show()
49+
function(block){
50+
var elements = document.querySelectorAll(block);
51+
for(var i = 0; i < elements.length; i++){
52+
elements[i].style.display = '';
53+
}
4754
}
4855
)
4956
};
5057
var hide_code = function(){
5158
code_blocks.forEach(
5259
function(block){
53-
$(block).hide()
60+
var elements = document.querySelectorAll(block);
61+
for(var i = 0; i < elements.length; i++){
62+
elements[i].style.display = 'none';
63+
}
5464
}
5565
)
5666
};
5767
58-
59-
var bodyElement = $('#notebook-container')[0];
68+
var bodyElement = document.getElementsByClassName('jp-Notebook')[0];
69+
if (bodyElement === undefined) {
70+
bodyElement = document.getElementById('notebook-container');
71+
}
6072
var toggleDiv = document.createElement('div');
6173
var toggleButton = document.createElement('button');
6274
toggleButton.className = 'btn';
@@ -81,6 +93,6 @@ div div.cell {
8193

8294
{% block stream %}
8395
{%- if resources.global_content_filter.include_output_prompt -%}
84-
{{ super() }}
96+
{{ super() or "" }}
8597
{%- endif -%}
8698
{%- endblock stream %}

notebooker/utils/conversion.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def ipython_to_html(
3636
__name__, "../nbtemplates/notebooker_html_output.tpl"
3737
)
3838
c.HTMLExporter.exclude_input = hide_code
39+
c.HTMLExporter.exclude_input_prompt = hide_code
3940
c.HTMLExporter.exclude_output_prompt = hide_code
4041
html_exporter_with_figs = HTMLExporter(config=c)
4142
resources_dir = get_resources_dir(job_id)
@@ -47,6 +48,7 @@ def ipython_to_html(
4748
def ipython_to_pdf(raw_executed_ipynb: str, report_title: str, hide_code: bool = False) -> AnyStr:
4849
c = Config()
4950
c.PDFExporter.exclude_input = hide_code
51+
c.PDFExporter.exclude_input_prompt = hide_code
5052
c.PDFExporter.exclude_output_prompt = hide_code
5153
c.HTMLExporter.template_file = pkg_resources.resource_filename(
5254
__name__, "../nbtemplates/notebooker_pdf_output.tplx"

0 commit comments

Comments
 (0)