#!/usr/bin/env python # coding: utf-8 # In[1]: import os from IPython.display import HTML import ezmarkdown as md # In[2]: text_md = r""" ##This notebook shows how to use `ezmarkdown` to create standalone HTML documents + Based on a series of examples. + To install, run the following command in your terminal. ```pip install ezmarkdown``` """ text_html = md.md_to_html(text_md) HTML(text_html) # ###MarkDown input # + WARNING: text string must be raw e.g. r'example string' # In[3]: # path_img1 = 'data/svgclock.svg' # path_img2 = 'data/example2.jpg' # path_img3 = 'data/example4.png' path_img1 = 'http://upload.wikimedia.org/wikipedia/commons/f/fd/Ghostscript_Tiger.svg' path_img2 = 'http://upload.wikimedia.org/wikipedia/commons/thumb/3/3e/Einstein_1921_by_F_Schmutzer_-_restoration.jpg/220px-Einstein_1921_by_F_Schmutzer_-_restoration.jpg' path_img3 = 'http://upload.wikimedia.org/wikipedia/en/thumb/f/f9/Singing_in_the_rain_poster.jpg/220px-Singing_in_the_rain_poster.jpg' text_md = r""" #Header One ##Header Two ###Header Three ####Header Four

Native HTML sample

##Caractères avec accents + Un poème de Paul Verlaine Les sanglots longs Des violons De l'automne Blessent mon cœur D'une langueur Monotone. Tout suffocant Et blême, quand Sonne l'heure, Je me souviens Des jours anciens Et je pleure Et je m'en vais Au vent mauvais Qui m'emporte Deçà, delà, Pareil à la Feuille morte. + Autre example: çà avec accent, symbole de l'Euro € + Et aussi équations Latex inline $\mu$ ou encore $e^{i\pi}=-1$ ##Multi line Latex examples A mathjax expression, by default left-aligned. $$ \frac{n!}{k!(n-k)!} = \binom{n}{k} $$ A mathjax expression, centered.
$$ \begin{equation} x = a_0 + \cfrac{1}{a_1 + \cfrac{1}{a_2 + \cfrac{1}{a_3 + \cfrac{1}{a_4} } } } \end{equation} $$
A mathjax expression, right-aligned.
$$ A_{m,n} = \begin{pmatrix} a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\ a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m,1} & a_{m,2} & \cdots & a_{m,n} \end{pmatrix} $$
##List Example Here is a list of items : - Item no 1 - Item no 2 - etc - Very long item that I need to write on 2 lines azerty azerty azerty azerty azerty azerty azerty azerty azerty azerty ##A block quote > Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. ##Tables **[links](http://example.com)** 4. Apples 5. Oranges 6. Pears A centered table
| Header 1 | *Header* 2 | | -------- | -------- | | `Cell 1` | [Cell 2](http://example.com) link | | Cell 3 | **Cell 4** |
Another table, left-aligned by default. See how the mathjax expression can be left-aligned or centered in a table cell. |title1|title2| |-|-| |![alt text](%s)|$$\frac{n!}{k!(n-k)!} = \binom{n}{k}$$| |![alt text](%s)|
$$\frac{n!}{k!(n-k)!} = \binom{n}{k}$$
| |![alt text](%s)|![alt text](%s)| ###Finally some variables + %s + %s + %s """ % (path_img1, path_img1, path_img2, path_img3, 'variableA', 'variableB', 'variableC') text_html = md.md_to_html(text_md) HTML(text_html) # ###Create HTML document # + Save notebook before creating doc # + Make sure to update the notebook name if necessary # + `selected_cells` is the list of cells that will be written in the html doc # + Count cells (i.e. including code **and** markdown cells) starting from 0 # + A code cell has 2 parts: In[ ] and Out[ ] # + Several templates are available, accessible by autocomplete. # + TEMPLATE_INPUT_AND_OUTPUT_CELLS: # + TEMPLATE_INPUT_CELLS_ONLY # + TEMPLATE_OUTPUT_CELLS_ONLY # + TEMPLATE_INPUT_CELLS_TOGGLE_OUTPUT_CELLS # + TEMPLATE_OUTPUT_CELLS_TOGGLE_INPUT_CELLS # + The selected template controls how code cells will be rendered in the HTML doc. Try them out. # + The resulting HTML doc is created where variable `output` indicates. # + A subdirectory 'saved' is created is necessary. # In[4]: fname = 'demo_ezmarkdown.ipynb' output = 'saved/output.html' tpl = md.template.TEMPLATE_OUTPUT_CELLS_ONLY selected_cells = [1, 3] md.write_html_doc(fname, output, selected_cells, template=tpl) # In[ ]: