0

If I have a python function that can take text, parse it, and generate formatted HTML, (or re-formatted text), as output, is their any way of adding that as a custom cell format to Jupyter?

I would like to create a custom markup format for register definitions and haveit displayed as pretty HTML/SVG but have the source remain text.

Thanks

EXTRA: I read a biy more and although I see input cells that can go on to generate HTML output, there seems to be nothing that allows the output to hide the input, in the same way that Markdown HTML replaces its source when not editing.

Paddy3118
  • 4,704
  • 27
  • 38

1 Answers1

1

Here is a combination of answers that I should get you what you're looking for. Using this answer as a guide, you can have IPython output HTML using display:

from IPython.core.display import display, HTML

html_custom = '<h1>%s</h1>' % 'Whatever you want'

display(HTML(html_custom))

That allows you to use python to read in whatever text you need to and format it as you need.

Next step is to hide the input. The nbextensions notebook extensions give you a lot of functionality within the notebook and was suggested here. One of the available extensions is Hide input, which as the name suggests, hides the input of a cell. The collapsed state is even maintained within the notebook metadata, so it displays collapsed as you'd expect when reopening the notebook.

enter image description here

Then within the notebook:

enter image description here

cwalvoort
  • 1,851
  • 1
  • 18
  • 19