93 lines
16 KiB
HTML
93 lines
16 KiB
HTML
<!doctype html>
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
<head>
|
|
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
|
<style>
|
|
blockquote { background-color: #FFFAAE; padding: 7px; }
|
|
table { border-collapse: collapse; }
|
|
thead td { border-bottom: 1px solid; }
|
|
tfoot td { border-top: 1px solid; }
|
|
.tableclass1 { background-color: lime; }
|
|
.tableclass1 thead { color: yellow; background-color: green; }
|
|
.tableclass1 tfoot { color: yellow; background-color: green; }
|
|
.tableclass1 .even td { background-color: #80FF7F; }
|
|
.tableclass1 .first td {border-top: 1px solid; }
|
|
|
|
td.num { text-align: right; }
|
|
pre { background-color: #E0E0E0; padding: 5px; }
|
|
</style>
|
|
<title>Markmin markup language</title>
|
|
</head>
|
|
<body>
|
|
<h1>Markmin markup language</h1><h2>About</h2><p>This is a new markup language that we call markmin designed to produce high quality scientific papers and books and also put them online. We provide serializers for html, latex and pdf. It is implemented in the <code>markmin2html</code> function in the <code>markmin2html.py</code>.</p><p>Example of usage:</p><pre><code>m = "Hello **world** [[link http://web2py.com]]"
|
|
from markmin2html import markmin2html
|
|
print markmin2html(m)
|
|
from markmin2latex import markmin2latex
|
|
print markmin2latex(m)
|
|
from markmin2pdf import markmin2pdf # requires pdflatex
|
|
print markmin2pdf(m)</code></pre> ====================<h1>This is a test block with new features:</h1><p>This is a blockquote with a list with tables in it:</p><blockquote class="blockquoteclass" id="markmin_blockquoteid">This is a paragraph before list. You can continue paragraph on the next lines.<br />This is an ordered list with tables:<ol><li>Item 1</li><li>Item 2</li><li><table class="tableclass1" id="markmin_tableid1"><tbody><tr class="first"><td>aa</td><td>bb</td><td>cc</td></tr><tr class="even"><td class="num">11</td><td class="num">22</td><td class="num">33</td></tr></tbody></table></li><li>Item 4 <table class="tableclass1"><thead><tr class="first"><td>T1</td><td>T2</td><td>t3</td></tr></thead><tbody><tr class="first"><td>aaa</td><td>bbb</td><td>ccc</td></tr><tr class="even"><td>ddd</td><td>fff</td><td>ggg</td></tr><tr><td class="num">123</td><td class="num">0</td><td class="num">5.0</td></tr></tbody></table></li></ol></blockquote><p>This this a new paragraph with a table. Table has header, footer, sections, odd and even rows:</p><table class="tableclass1" id="markmin_tableid2"><thead><tr class="first"><td><strong>Title 1</strong></td><td><strong>Title 2</strong></td><td><strong>Title 3</strong></td></tr></thead><tbody><tr class="first"><td>data 1</td><td>data 2</td><td class="num">2.00</td></tr><tr class="even"><td>data 3</td><td>data4(long)</td><td class="num">23.00</td></tr><tr><td></td><td>data 5</td><td class="num">33.50</td></tr><tr class="first"><td>New section</td><td>New data</td><td class="num">5.00</td></tr><tr class="even"><td>data 1</td><td>data2(long)</td><td class="num">100.45</td></tr><tr><td></td><td>data 3</td><td class="num">12.50</td></tr><tr class="even"><td>data 4</td><td>data 5</td><td class="num">.33</td></tr><tr><td>data 6</td><td>data7(long)</td><td class="num">8.01</td></tr><tr class="even"><td></td><td>data 8</td><td class="num">514</td></tr></tbody><tfoot><tr class="first"><td>Total:</td><td>9 items</td><td>698,79</td></tr></tfoot></table><h2>Multilevel lists</h2><p>Now lists can be multilevel:</p><ol><li>Ordered item 1 on level 1. You can continue item text on next strings<ol><li><p>Ordered item 1 of sublevel 2 with a paragraph (paragraph can start with point after plus or minus characters, e.g. <strong>++.</strong> or <strong>--.</strong>)</p><li><p>This is another item. But with 3 paragraphs, blockquote and sublists:</p><p>This is the second paragraph in the item. You can add paragraphs to an item, using point notation, where first characters in the string are sequence of points with space between them and another string. For example, this paragraph (in sublevel 2) starts with two points:</p><code>.. This is the second paragraph...</code><blockquote><h3>this is a blockquote in a list</h3>You can use blockquote with headers, paragraphs, tables and lists in it:<br />Tables can have or have not header and footer. This table is defined without any header and footer in it:<table><tbody><tr class="first"><td>red</td><td>fox</td><td class="num">0</td></tr><tr class="even"><td>blue</td><td>dolphin</td><td class="num">1000</td></tr><tr><td>green</td><td>leaf</td><td class="num">10000</td></tr></tbody></table></blockquote><p>This is yet another paragraph in the item.</p><ul><li>This is an item of unordered list <strong>(sublevel 3)</strong></li><li>This is the second item of the unordered list <em>(sublevel 3)</em><ol><ol><ol><li>This is a single item of ordered list in sublevel 6</li></ol></ol><p>and this is a paragraph in sublevel 4</p></ol></li><li><p>This is a new item with paragraph in sublevel 3.</p><ol><li>Start ordered list in sublevel 4 with code block: <pre><code>line 1
|
|
line 2
|
|
line 3</code></pre></li><li><p>Yet another item with code block:</p><pre><code> line 1
|
|
line 2
|
|
line 3</code></pre> This item finishes with this paragraph.</li></ol><p>Item in sublevel 3 can be continued with paragraphs.</p><pre><code> this is another
|
|
code block
|
|
in the
|
|
sublevel 3 item</code></pre></li></ul><ol><li>The last item in sublevel 3</li></ol><p>This is a continuous paragraph for item 2 in sublevel 2. You can use such structure to create difficult structured documents.</p><li>item 3 in sublevel 2</li></li></li></ol><ul><li>item 1 in sublevel 2 (new unordered list)</li><li>item 2 in sublevel 2</li><li>item 3 in sublevel 2</li></ul><ol><li>item 1 in sublevel 2 (new ordered list)</li><li>item 2 in sublevel 2</li><li>item 3 in sublevle 2</li></ol></li><li>item 2 in level 1</li><li>item 3 in level 1</li></ol><ul><li>new unordered list (item 1 in level 1)</li><li>level 2 in level 1</li><li>level 3 in level 1</li><li>level 4 in level 1</li></ul><h2>This is the last section of the test</h2><p>Single paragraph with '----' in it will be turned into separator:</p><hr /><p>And this is the last paragraph in the test. Be happy!</p><p>====================</p><h2>Why?</h2><p>We wanted a markup language with the following requirements:</p><ul><li>less than 300 lines of functional code</li><li>easy to read</li><li>secure</li><li>support table, ul, ol, code</li><li>support html5 video and audio elements (html serialization only)</li><li>can align images and resize them</li><li>can specify class for tables and code elements</li><li>can add anchors</li><li>does not use _ for markup (since it creates odd behavior)</li><li>automatically links urls</li><li>fast</li><li>easy to extend</li><li>supports latex and pdf including references</li><li>allows to describe the markup in the markup (this document is generated from markmin syntax)</li></ul><p>(results depend on text but in average for text ~100K markmin is 30% faster than markdown, for text ~10K it is 10x faster)</p><p>The <a href="http://www.lulu.com/product/paperback/web2py-%283rd-edition%29/12822827">web2py book</a> published by lulu, for example, was entirely generated with markmin2pdf from the online <a href="http://www.web2py.com/book">web2py wiki</a></p><h2>Download</h2><ul><li><a href="http://web2py.googlecode.com/hg/gluon/contrib/markmin/markmin2html.py">http://web2py.googlecode.com/hg/gluon/contrib/markmin/markmin2html.py</a></li><li><a href="http://web2py.googlecode.com/hg/gluon/contrib/markmin/markmin2latex.py">http://web2py.googlecode.com/hg/gluon/contrib/markmin/markmin2latex.py</a></li><li><a href="http://web2py.googlecode.com/hg/gluon/contrib/markmin/markmin2pdf.py">http://web2py.googlecode.com/hg/gluon/contrib/markmin/markmin2pdf.py</a></li></ul><p>markmin2html.py and markmin2latex.py are single files and have no web2py dependence. Their license is BSD.</p><h2>Examples</h2><h3>Bold, italic, code and links</h3><table><thead><tr class="first"><td><strong>SOURCE</strong></td><td><strong>OUTPUT</strong></td></tr></thead><tbody><tr class="first"><td><code># title</code></td><td><strong>title</strong></td></tr><tr class="even"><td><code>## section</code></td><td><strong>section</strong></td></tr><tr><td><code>### subsection</code></td><td><strong>subsection</strong></td></tr><tr class="even"><td><code>**bold**</code></td><td><strong>bold</strong></td></tr><tr><td><code>''italic''</code></td><td><em>italic</em></td></tr><tr class="even"><td><code>~~strikeout~~</code></td><td><del>strikeout</del></td></tr><tr><td><code>``verbatim``</code></td><td><code>verbatim</code></td></tr><tr class="even"><td><code>``color with **bold**``:red</code></td><td><span style="color: red">color with <strong>bold</strong></span></td></tr><tr><td><code>``many colors``:color[blue:#ffff00]</code></td><td><span style="color: blue;background-color: #ffff00;">many colors</span></td></tr><tr class="even"><td><code>http://google.com</code></td><td><a href="http://google.com">http://google.com</a></td></tr><tr><td><code>[[**click** me #myanchor]]</code></td><td><a href="#markmin_myanchor"><strong>click</strong> me</a></td></tr><tr class="even"><td><code>[[click me [extra info] #myanchor popup]]</code></td><td><a href="#markmin_myanchor" title="extra info" target="_blank">click me</a></td></tr></tbody></table><h3>More on links</h3><p>The format is always <code>[[title link]]</code> or <code>[[title [extra] link]]</code>. Notice you can nest bold, italic, strikeout and code inside the link <code>title</code>.</p><h3>Anchors <a name="markmin_myanchor"></a></h3><p>You can place an anchor anywhere in the text using the syntax <code>[[name]]</code> where <em>name</em> is the name of the anchor. You can then link the anchor with <a href="#markmin_myanchor">link</a>, i.e. <code>[[link #myanchor]]</code> or <a href="#markmin_myanchor" title="extra info">link with an extra info</a>, i.e. <code>[[link with an extra info [extra info] #myanchor]]</code>.</p><h3>Images</h3><p><img src="http://www.web2py.com/examples/static/web2py_logo.png" alt="alt-string for the image" title="the image title" style="float:right" width="200px" /> This paragraph has an image aligned to the right with a width of 200px. Its is placed using the code</p><p><code>[[alt-string for the image [the image title] http://www.web2py.com/examples/static/web2py_logo.png right 200px]]</code>.</p><h3>Unordered Lists</h3><pre><code>- Dog
|
|
- Cat
|
|
- Mouse</code></pre><p>is rendered as</p><ul><li>Dog</li><li>Cat</li><li>Mouse</li></ul><p>Two new lines between items break the list in two lists.</p><h3>Ordered Lists</h3><pre><code>+ Dog
|
|
+ Cat
|
|
+ Mouse</code></pre><p>is rendered as</p><ol><li>Dog</li><li>Cat</li><li>Mouse</li></ol><h3>Multilevel Lists</h3><pre><code>+ Dogs
|
|
-- red
|
|
-- brown
|
|
-- black
|
|
+ Cats
|
|
-- fluffy
|
|
-- smooth
|
|
-- bald
|
|
+ Mice
|
|
-- small
|
|
-- big
|
|
-- huge</code></pre><p>is rendered as</p><ol><li>Dogs<ul><li>red</li><li>brown</li><li>black</li></ul></li><li>Cats<ul><li>fluffy</li><li>smooth</li><li>bald</li></ul></li><li>Mice<ul><li>small</li><li>big</li><li>huge</li></ul></li></ol><h3>Tables (with optional header and/or footer)</h3><p>Something like this</p><pre><code>-----------------
|
|
**A**|**B**|**C**
|
|
=================
|
|
0 | 0 | X
|
|
0 | X | 0
|
|
X | 0 | 0
|
|
=================
|
|
**D**|**F**|**G**
|
|
-----------------:abc[id]</code></pre> is a table and is rendered as<table class="abc" id="markmin_id"><thead><tr class="first"><td><strong>A</strong></td><td><strong>B</strong></td><td><strong>C</strong></td></tr></thead><tbody><tr class="first"><td class="num">0</td><td class="num">0</td><td>X</td></tr><tr class="even"><td class="num">0</td><td>X</td><td class="num">0</td></tr><tr><td>X</td><td class="num">0</td><td class="num">0</td></tr></tbody><tfoot><tr class="first"><td><strong>D</strong></td><td><strong>F</strong></td><td><strong>G</strong></td></tr></tfoot></table> Four or more dashes delimit the table and | separates the columns. The <code>:abc</code>, <code>:id[abc_1]</code> or <code>:abc[abc_1]</code> at the end sets the class and/or id for the table and it is optional.<h3>Blockquote</h3><p>A table with a single cell is rendered as a blockquote:</p><blockquote>Hello world</blockquote><p>Blockquote can contain headers, paragraphs, lists and tables:</p><pre><code>-----
|
|
This is a paragraph in a blockquote
|
|
|
|
+ item 1
|
|
+ item 2
|
|
-- item 2.1
|
|
-- item 2.2
|
|
+ item 3
|
|
|
|
---------
|
|
0 | 0 | X
|
|
0 | X | 0
|
|
X | 0 | 0
|
|
---------:tableclass1
|
|
-----</code></pre><p>is rendered as:</p><blockquote>This is a paragraph in a blockquote<ol><li>item 1</li><li>item 2<ul><li>item 2.1</li><li>item 2.2</li></ul></li><li>item 3</li></ol><table class="tableclass1"><tbody><tr class="first"><td class="num">0</td><td class="num">0</td><td>X</td></tr><tr class="even"><td class="num">0</td><td>X</td><td class="num">0</td></tr><tr><td>X</td><td class="num">0</td><td class="num">0</td></tr></tbody></table></blockquote><h3>Code, <code><code></code>, escaping and extra stuff</h3><pre><code class="python">def test():
|
|
return "this is Python code"</code></pre><p>Optionally a ` inside a <code>``...``</code> block can be inserted escaped with !`!.</p><p><strong>NOTE:</strong> You can escape markmin constructions ('',``,**,~~,[,{,]},$,@) with '\' character: so \`\` can replace !`!`! escape string</p><p>The <code>:python</code> after the markup is also optional. If present, by default, it is used to set the class of the <code> block. The behavior can be overridden by passing an argument <code>extra</code> to the <code>render</code> function. For example:</p><pre><code class="python">markmin2html("``aaa``:custom",
|
|
extra=dict(custom=lambda text: 'x'+text+'x'))</code></pre><p>generates</p><code class="python">'xaaax'</code><p>(the <code>``...``:custom</code> block is rendered by the <code>custom=lambda</code> function passed to <code>render</code>).</p><h3>Html5 support</h3><p>Markmin also supports the <video> and <audio> html5 tags using the notation:</p><pre><code>[[message link video]]
|
|
[[message link audio]]
|
|
|
|
[[message [title] link video]]
|
|
[[message [title] link audio]]</code></pre> where <code>message</code> will be shown in brousers without HTML5 video/audio tags support.<h3>Latex and other extensions</h3><p>Formulas can be embedded into HTML with <em>$$<code>formula</code>$$</em>. You can use Google charts to render the formula:</p><pre><code>LATEX = '<img src="http://chart.apis.google.com/chart?cht=tx&chl=%s" />'
|
|
markmin2html(text,{'latex':lambda code: LATEX % code.replace('"','\"')})</code></pre><h3>Code with syntax highlighting</h3><p>This requires a syntax highlighting tool, such as the web2py CODE helper.</p><pre><code>extra={'code_cpp':lambda text: CODE(text,language='cpp').xml(),
|
|
'code_java':lambda text: CODE(text,language='java').xml(),
|
|
'code_python':lambda text: CODE(text,language='python').xml(),
|
|
'code_html':lambda text: CODE(text,language='html').xml()}</code></pre> or simple:<pre><code>extra={'code':lambda text,lang='python': CODE(text,language=lang).xml()}</code></pre><pre><code>markmin2html(text,extra=extra)</code></pre><p>Code can now be marked up as in this example:</p><pre><code>``
|
|
<html><body>example</body></html>
|
|
``:code_html</code></pre> OR<pre><code>``
|
|
<html><body>example</body></html>
|
|
``:code[html]</code></pre><h3>Citations and References</h3><p>Citations are treated as internal links in html and proper citations in latex if there is a final section called "References". Items like</p><pre><code>- [[key]] value</code></pre><p>in the References will be translated into Latex</p><pre><code>\bibitem{key} value</code></pre><p>Here is an example of usage:</p><pre><code>As shown in Ref.``mdipierro``:cite
|
|
|
|
## References
|
|
|
|
- [[mdipierro]] web2py Manual, 3rd Edition, lulu.com</code></pre><h3>Caveats</h3><p><code><ul/></code>, <code><ol/></code>, <code><code/></code>, <code><table/></code>, <code><blockquote/></code>, <code><h1/></code>, ..., <code><h6/></code> do not have <code><p>...</p></code> around them.</p>
|
|
</body>
|
|
</html>
|