Report.add_html does not obey section

I would like to have this html box be inside the “main” section, but it shows up as it’s own section.

I’m using 1.6.0 as shown in the screenshot.

import mne

report = mne.Report("foo.html", title='title')
report.add_html(
    title='html title', 
    section="main", 
    html=f"<pre><code>print('hello world')</code></pre>")
fig,ax = plt.subplots()
ax.plot([1,2,3,2,1])
report.add_figure(
    title ='figure title',
    section="main",
    fig=fig)
report.save("foo.html", overwrite=True)

I can reproduce this error. I thought it would be as simple as changing section=None to section=section here (as the section param otherwise was ignored):

but that didn’t seem to fix it. @richard do you have any insight here? I’m not super familiar with the internals of the Report module.

Definitely seems like a bug to me! Not sure how to fix it though, I would need to investigate a little…

Thank you for the responses!

I found a workaround and am able to get the desired output by adding:

report._content[0].section = 'main'
report.save("foo.html", overwrite=True)

I was going to try @drammock 's idea of changing section=section in the _add_or_replace() method and following the output but my IDE has decided it doesn’t want to “go to definition” today so I’m tabling that work for now.

1 Like

I do think it is as simple as @drammock suggested. I made the change in my local fork and the output file has the correct format. Should I submit a PR? It’d be my first!

sure if it works please do submit a PR! I didn’t manage to get it to work but I was looking very quickly, maybe I missed something (forgot to save the changed file or such).