Jupyter notebook markdown highlight options - jupyter-notebook

I would like to type highlight in jupyter notebook, such as:
How could I highlight as this?

Not sure what the question is about. I think what you're looking for is Markdown sintax, you can just use
The `numpy.array` type provides a handy method, `item`,
inside a markdown cell to get
The differences in appearance from the example you shared are relative to a different engine used for rendering. If you want to obtain a specific style, instated, markdown cells support HTML that allow you to customize the output. For instance using
The <span style='color: #e74c3c; font-family: monospace; background-color: #F7F2F4;'>numpy.array</span> type provides a handy method, <span style='color: #e74c3c; font-family: monospace; background-color: #F7F2F4;'>item</span>,
you will get
Hope this was helpful :)

Related

Different font settings for editing code and markdown cells in the Jupyter Notebook

In the Jupyter notebook, I would like to use the regular Ubuntu font when editing markdown cells and UbuntuMono for code cells. I can change the fonts of both these cell types simultaneously by editing .jupyter/custom/custom.css like so:
.CodeMirror pre {
font-family: "Ubuntu Mono", monospace;
font-size: 14pt;
}
I can also change the formatting of the headers in the markdown code cells:
.cm-header {
font-size: 110%;
font-family: "Ubuntu";
}
As well as how the text looks when rendered (after executing a markdown cell):
div.text_cell_render {
font-family: "Ubuntu";
font-size: 12pt;
}
However, I don't understand which css classes I could use to discriminate between code cells and paragragh/body text in markdown cells in edit mode. I tried the object inspector in Firefox, but the input text for both cell types show up with the same span tags and css classes. I have tried many of the combinations listed here, but it seems like I just can't find the right one, any ideas?
I received a reply from the Jupyter Notebook issue linked in the comments of my questions here. It is possible to combine CSS selector, so the following solves my problem:
.text_cell .CodeMirror pre {
font-family: "Ubuntu";
font-size: 12pt;
}

How to change the font in Markdown cells when they are in Edit Mode?

I want to change the font type in Markdown cells when I am editing them.
How Can I do that?
I can edit the file .jupyter/custom/custom.css and change the font when they are "run":
div.text_cell_render {
font-family: 'Linux Libertine O';
font-size: 12pt;
}
As shown in the figure, the upper half is a Markdown cell in edit mode, and that is the place where I want to change the font.
A simple possibility is
from IPython.display import HTML, display
display(HTML('<style>.CodeMirror{font-family:whatever}</style>')
but beware that the code above changes also the fonts used for
editing cells of code
rendered code cells
Also note, that my simple proposal works on a notebook by notebook base, you have to add the lines to every notebook you want to modify. On the contrary, if you have a custom.css file where it can be accessed by jupiter during startup you can add the font-family:whatever to it, to make the customization hold for every notebook that you are using.
For an example of permanent customization please have a look at this question from Joel Ostblom — in a nutshell, edit ~/.jupyter/custom/custom.css and put in it
.CodeMirror pre {
font-family: "Ubuntu Mono", monospace;
font-size: 14pt;
...
}

Julia notebook custom css

Is it possible to customize the cell colours and notebook output such as dataframes in IJulia notebook (using julia). For example, in python, we could do
Python notebook
from IPython.core.display import HTML
css = open('style.css').read()
HTML('<style>{}</style>'.format(css))
style.css
table.dataframe th:not(:empty) {
background-color: #FFCCFF;
text-align:left;
font-weight: bold;
font-family: monospace;
}
table.dataframe tr:nth-child(2) th:empty {
border-left: none;
border-right: 1px dashed #888;
}
table.dataframe td {
border: 2px solid #ccf;
background-color: #f4f4ff;
}
From looking at the IJulia source, it doesn't seem like there's a method for updating the styles from within the package directly.
The simplest way to customize the IJulia CSS – assuming you're using jupyter 0.4 – would be to add your customizations to ~/.jupyter/custom/custom.css. If the directory does not exist, just create it, and your custom styles should load automagically.
Sourced from: How do I set custom CSS for my IPython/IHaskell/Jupyter Notebook?
This seem to work
file = open("styletableJul.css")
styl = readall(file)
HTML("$styl")
Jupyter permits rendering output with Javascript code in it. Using Javascript you can really play with the DOM (browser page representation) and achieve a different look. My mini-test example was:
In[356]: HTML("<script>tt = \$(\".output_prompt\"); tt[tt.length-1].style.color=\"green\"</script><em>hello</em>")
The result was:
Out[356]: hello
but with a green Out[356] (it has the output_prompt class). Getting the JavaScript code to change the styles might be annoying. It might also be possible to really include CSS style sheet programmatically using Javascript. You already have some default libraries loaded to help you (JQuery) - but I'm afraid I'm no Jupyter expert.

Adding custom styled paragraphs in markdown cells

I want to add more formatting elements than provided by the Markdown synthax in an IPython Notebook.
For example, I want to add a "Warning Box" or a "Memo Box" that are basically paragraph with different styles (for example different background color, border, an icon, etc...).
I guess I can add HTML code in the cell, for example a <div> with an inline style. But what is the "proper" way to do that, I mean the one that ipython developer promote?
Examples appreciated.
NB: I'm using the current 1.0dev version from git master.
Answering to my own question...
Other solutions
Jim proposed to add some custom CSS style in a markdown cell of each notebook. This solution works, but is not convenient since you need to embed the style on each notebook. In my case I want a global style and I don't want to modify all the notebooks after every the style modification.
A natural solution would be using a custom file (custom.css) containing the style. However after trying these instructions
the style is not applied to the notebook (it can be downloaded from the server though).
Best solution (so far)
I found a solution looking at this impressive book written as a collection of IPython notebooks. The author adds at the end of each notebook the following code cell:
from IPython.core.display import HTML
def css_styling():
styles = open("./styles/custom.css", "r").read()
return HTML(styles)
css_styling()
Putting a file custom.css in your notebook folder (in the styles subfolder), the style will be loaded after the first cell execution. Moreover the style will be magically loaded every time the notebook is opened, without the need to execute the cell again!
This magic trick works because the style is saved in the ouput cell the first time we execute it, and although being invisible, will be saved like any other output. So when we load the notebook, and conseguentely the output cells, the style will be applied.
Sample CSS
To complete the answer I post a CSS style I used to create a "Warning box":
<style>
div.warn {
background-color: #fcf2f2;
border-color: #dFb5b4;
border-left: 5px solid #dfb5b4;
padding: 0.5em;
}
</style>
Save this style and load it using the code cell shown before. Now, to insert a warning box in your notebook use this syntax:
<div class=warn>
**Warning:** remember to do bookeping
</div>
That will be rendered like this:
For more general notebook styling you can take inspiration from the custom.css
of the book mentioned above.
A simple way to add warning, note, success (etc...) boxes (also called admonition or alert boxes) is simply using the bootstrap classes already included with the notebook. The only caveat is that links and other styles (e.g. bold) must be specified in HTML inside the box.
Example
A markdown cell containing this code:
# Upload data files
<p class="lead">This Jupyter notebook
shows how to upload data files to be converted
to [Photon-HDF5](http://photon-hdf5.org) format. </p>
<i>Please send feedback and report any problems to the
[Photon-HDF5 google group](https://groups.google.com/forum/#!forum/photon-hdf5).</i>
<br>
<div class="alert alert-warning">
<b>NOTE</b> Uploading data files is only necessary when running the notebook online.
</div>
will result in this output:
You can change alert-warning with alert-success, alert-info or alert-danger to get different colors for the box.
Update: This technique no longer works in IPython 4.0 / Jupyter since the way the notebook is rendered has changed.
I believe the best way to do such styling is to create a markdown entry at the top of your document and to collect your styles there. Since a markdown cell can contain any valid HTML code, it could contain (for instance)
<style>
.warning { color: red; }
</style>
See Matt Davis' PyCon 2013 talk, about 22 minutes in during the Q&A for an example of this in use.
These custom css styles are already added in ipython version 2 and higher.
<div class="alert">
As of IPython 2.0, the user interface has changed significantly
</div>
<div class="alert alert-success">
Enter edit mode by pressing `Enter`
</div>
<div class="alert alert-error">
Don't try to type into a cell in command mode
</div>
Just paste this in the cell and change it to markdown type.
Check this for the examples and ipython in depth for the cutting edge features of ipython.
Another mean consists to simply create a style chain and open it with iPython HTML object in a code cell:
from IPython.display import HTML
style = "<style>div.warn { background-color: #fcf2f2;border-color: #dFb5b4; border-left: 5px solid #dfb5b4; padding: 0.5em;}</style>"
HTML(style)
Then use it in a markdown cell:
<div class="warn">Warning!</div>

How can i format aspx-markup as html to show it on webpage

i've been using C. Coller's excellent CopyAsHtml-Visual Studio addin for copying C# code as html to a webpage.
Now, i started to wonder if there exists a similar tool for converting the aspx-markup to valid html to show on page? Functionality that i'm looking for can be seen on G. Houston's blog.
F.ex. if i feed this
<asp:Button id="btnSthing" runat="server"></button>
into the tool in link above, it generates the following for me:
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color:
#000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height:
14px;padding: 5px; overflow: auto; width: 100%"><code><asp:Button id="
btnSthing" runat="server"></button></code></pre>
and i can simply copy and paste this into a website to show the aspx-markup used.
If there's a tool for this sort of functionality, that would integrate into VS, i'd like to hear about it! Other methods for achieving this effect would be greatly appreciated too!
greets,
J.Arola
I'm not aware of such a tool for VS, but the following website allows you to have source code from several languages (C#, Java, PHP, XML, HTML, ASPX) formatted for HTML:
http://codeconverter.sharpdevelop.net/FormatCode.aspx

Resources