{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import os\n", "from IPython.display import HTML\n", "\n", "import ezmarkdown as md" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", "

This notebook shows how to use ezmarkdown to create standalone HTML documents

\n", "" ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "text_md = r\"\"\"\n", "##This notebook shows how to use `ezmarkdown` to create standalone HTML documents\n", "+ Based on a series of examples.\n", "+ To install, run the following command in your terminal. \n", "```pip install ezmarkdown```\n", "\"\"\"\n", "text_html = md.md_to_html(text_md)\n", "HTML(text_html)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###MarkDown input\n", "+ WARNING: text string must be raw e.g. r'example string'" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false, "scrolled": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", "

Header One

\n", "

Header Two

\n", "

Header Three

\n", "

Header Four

\n", "

Native HTML sample

\n", "\n", "

Caractères avec accents

\n", "\n", "

Les sanglots longs
\n", "Des violons
\n", "De l'automne
\n", "Blessent mon cœur
\n", "D'une langueur
\n", "Monotone.

\n", "

Tout suffocant
\n", "Et blême, quand
\n", "Sonne l'heure,
\n", "Je me souviens
\n", "Des jours anciens
\n", "Et je pleure

\n", "

Et je m'en vais
\n", "Au vent mauvais
\n", "Qui m'emporte
\n", "Deçà, delà,
\n", "Pareil à la
\n", "Feuille morte.

\n", "\n", "

Multi line Latex examples

\n", "

A mathjax expression, by default left-aligned.\n", "$$\n", "\\frac{n!}{k!(n-k)!} = \\binom{n}{k}\n", "$$

\n", "

A mathjax expression, centered.\n", "

\n", "$$\n", "\\begin{equation} x = a_0 + \\cfrac{1}{a_1 + \\cfrac{1}{a_2 + \\cfrac{1}{a_3 + \\cfrac{1}{a_4} } } } \\end{equation}\n", "$$\n", "

\n", "

A mathjax expression, right-aligned.\n", "

\n", "$$\n", "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} \\\\\n", "\\vdots & \\vdots & \\ddots & \\vdots \\\\ a_{m,1} & a_{m,2} & \\cdots & a_{m,n} \\end{pmatrix}\n", "$$\n", "

\n", "

List Example

\n", "

Here is a list of items :

\n", "\n", "

A block quote

\n", "
\n", "

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.

\n", "
\n", "

Tables

\n", "

links

\n", "
    \n", "
  1. Apples
  2. \n", "
  3. Oranges
  4. \n", "
  5. Pears
  6. \n", "
\n", "

A centered table\n", "

\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
Header 1Header 2
Cell 1Cell 2 link
Cell 3Cell 4
\n", "
\n", "\n", "

Another table, left-aligned by default.\n", "See how the mathjax expression can be left-aligned or centered in a table cell.

\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
title1title2
\"alt$$\\frac{n!}{k!(n-k)!} = \\binom{n}{k}$$
\"alt
$$\\frac{n!}{k!(n-k)!} = \\binom{n}{k}$$
\"alt\"alt
\n", "

Finally some variables

\n", "" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# path_img1 = 'data/svgclock.svg'\n", "# path_img2 = 'data/example2.jpg'\n", "# path_img3 = 'data/example4.png'\n", "\n", "path_img1 = 'http://upload.wikimedia.org/wikipedia/commons/f/fd/Ghostscript_Tiger.svg'\n", "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'\n", "path_img3 = 'http://upload.wikimedia.org/wikipedia/en/thumb/f/f9/Singing_in_the_rain_poster.jpg/220px-Singing_in_the_rain_poster.jpg'\n", "\n", "\n", "text_md = r\"\"\"\n", "#Header One\n", "##Header Two\n", "###Header Three\n", "####Header Four\n", "\n", "

Native HTML sample

\n", "\n", "##Caractères avec accents \n", "+ Un poème de Paul Verlaine \n", "\n", "Les sanglots longs \n", "Des violons \n", "De l'automne \n", "Blessent mon cœur \n", "D'une langueur \n", "Monotone. \n", "\n", "Tout suffocant \n", "Et blême, quand \n", "Sonne l'heure, \n", "Je me souviens \n", "Des jours anciens \n", "Et je pleure \n", "\n", "Et je m'en vais \n", "Au vent mauvais \n", "Qui m'emporte \n", "Deçà, delà, \n", "Pareil à la \n", "Feuille morte. \n", "\n", "+ Autre example: çà avec accent, symbole de l'Euro €\n", "+ Et aussi équations Latex inline $\\mu$ ou encore $e^{i\\pi}=-1$\n", "\n", "##Multi line Latex examples\n", "\n", "A mathjax expression, by default left-aligned.\n", "$$\n", "\\frac{n!}{k!(n-k)!} = \\binom{n}{k}\n", "$$\n", "\n", "A mathjax expression, centered.\n", "
\n", "$$\n", "\\begin{equation} x = a_0 + \\cfrac{1}{a_1 + \\cfrac{1}{a_2 + \\cfrac{1}{a_3 + \\cfrac{1}{a_4} } } } \\end{equation}\n", "$$\n", "
\n", "\n", "\n", "A mathjax expression, right-aligned.\n", "
\n", "$$\n", "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} \\\\\n", "\\vdots & \\vdots & \\ddots & \\vdots \\\\ a_{m,1} & a_{m,2} & \\cdots & a_{m,n} \\end{pmatrix}\n", "$$\n", "
\n", "\n", "##List Example\n", "\n", "Here is a list of items :\n", "\n", "- Item no 1\n", "- Item no 2\n", "- etc\n", "- Very long item that I need to write on 2 lines\n", "azerty azerty azerty azerty azerty azerty azerty azerty azerty azerty \n", "\n", "\n", "##A block quote\n", "\n", "> 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.\n", "\n", "##Tables\n", "\n", "**[links](http://example.com)**\n", "\n", "4. Apples\n", "5. Oranges\n", "6. Pears\n", "\n", "A centered table\n", "
\n", "\n", "| Header 1 | *Header* 2 |\n", "| -------- | -------- |\n", "| `Cell 1` | [Cell 2](http://example.com) link |\n", "| Cell 3 | **Cell 4** |\n", "\n", "
\n", "\n", "\n", "Another table, left-aligned by default.\n", "See how the mathjax expression can be left-aligned or centered in a table cell.\n", "\n", "|title1|title2|\n", "|-|-|\n", "|![alt text](%s)|$$\\frac{n!}{k!(n-k)!} = \\binom{n}{k}$$|\n", "|![alt text](%s)|
$$\\frac{n!}{k!(n-k)!} = \\binom{n}{k}$$
|\n", "|![alt text](%s)|![alt text](%s)|\n", "\n", "\n", "###Finally some variables \n", "+ %s\n", "+ %s\n", "+ %s\n", "\n", "\"\"\" % (path_img1,\n", " path_img1,\n", " path_img2,\n", " path_img3,\n", " 'variableA',\n", " 'variableB',\n", " 'variableC')\n", "\n", "text_html = md.md_to_html(text_md)\n", "HTML(text_html)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###Create HTML document\n", "+ Save notebook before creating doc\n", "+ Make sure to update the notebook name if necessary\n", "+ `selected_cells` is the list of cells that will be written in the html doc\n", " + Count cells (i.e. including code **and** markdown cells) starting from 0\n", " + A code cell has 2 parts: In[ ] and Out[ ]\n", "+ Several templates are available, accessible by autocomplete.\n", " + TEMPLATE_INPUT_AND_OUTPUT_CELLS:\n", " + TEMPLATE_INPUT_CELLS_ONLY\n", " + TEMPLATE_OUTPUT_CELLS_ONLY\n", " + TEMPLATE_INPUT_CELLS_TOGGLE_OUTPUT_CELLS\n", " + TEMPLATE_OUTPUT_CELLS_TOGGLE_INPUT_CELLS\n", " + The selected template controls how code cells will be rendered in the HTML doc. Try them out.\n", "+ The resulting HTML doc is created where variable `output` indicates.\n", " + A subdirectory 'saved' is created is necessary." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [], "source": [ "fname = 'demo_ezmarkdown.ipynb'\n", "output = 'saved/output.html'\n", "tpl = md.template.TEMPLATE_OUTPUT_CELLS_ONLY\n", "selected_cells = [1, 3]\n", "\n", "md.write_html_doc(fname, output, selected_cells, template=tpl)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.10" } }, "nbformat": 4, "nbformat_minor": 0 }