package kkmarkdown

  1. Overview
  2. Docs

kkmarkdown syntax

It supports a subset of the original markdown syntax, in order to avoid XSS attack.

The following rules are listed in alphabetical order. To see the actual application order, read the definitions:

BlockRuleCode

Code block with backquote

```
abc
```

BlockRuleCode

Code block with tilde

~~~
abc
~~~

BlockRuleCode

UNSAFE Code block with backquote

``` {.abc}
abc
```

is tranlsated to

<pre><code class="abc">abc</code></pre>

BlockRuleCode

UNSAFE Code block with tilde

~~~ {.abc}
abc
~~~

BlockRuleCode

Code block with indent

____abc

where _ is a space

BlockRuleHeader

Headers: e.g. # abc is for <h1> and ## abc is for <h2>. Similar rules are applied for <h3> to <h6>.

BlockRuleHeader

Header <h1> by underline

Title
===

BlockRuleHeader

Header <h2> by underline

Sub-title
---

BlockRuleHr

Hr: e.g. ***

BlockRuleImg

UNSAFE Image

![text](link) {.a .b}

is translated to

<img alt="text" src="link" class="a b">

Note that the class part is optional.

BlockRuleInlineHTML

UNSAFE Div inline HTML

<div>
  ...
</div>

Note that <div> and </div> should be their own lines.

BlockRuleInlineHTML

UNSAFE Script inline HTML

<script>
  ...
</script>

BlockRuleList

Unordered list

* a
* b
* c

A list element can have block-level elements by adding line spaces.

* line1

  * line2
  * line3

* line4

is translated to

<ul>
  <li>
    <p>line1</p>
    <ul>
      <li>line2</li>
      <li>line3</li>
    </ul>
  </li>
  <li>
    <p>line4</p>
  </li>
</ul>

However, without a line space, a list element CANNOT include another list.

* line1
  * line2
  * line3

is translated to

<ul>
  <li>
    <p>line1 <em> line2 </em> line3</p>
  </li>
</ul>

rather than something like

<ul>
  <li>
    line1
    <ul>
      <li>line2</li>
      <li>line3</li>
    </ul>
  </li>
</ul>

This is beacause, I am too lazy to think about such ambiguous corner cases. /o\

BlockRuleList

Ordered list

1. a
2. b
3. c

BlockRuleP

Paragraph

abc

def

BlockRuleQuote

Quote

> abc

RuleBr

Br: e.g. abc__<end-of-line>, where '_' is a space

SpanRuleA

Link: e.g. <https://kkeun.net>

For simplicity, the https:// prefix is omitted in the translated result, i.e. the example above is translated to

<a href="https://kkeun.net">kkeun.net</a>

Note that the link address must start with https:// or http://.

SpanRuleA

UNSAFE Link: e.g. [kkeundotnet](https://kkeun.net)

SpanRuleEscape

Escaped character: HTML special characters, e.g. &, <, etc., are translated to &amp;, &lt;, etc. The following characters should be escaped by backslash in markdown.

[ ] \ ` * # _ { } ( ) + - . !

SpanRuleStack

Emphasis: e.g. *abc*

SpanRuleStack

Strong: e.g. **abc**

SpanRuleStack

Emphasis+strong: e.g. ***abc***

Note that nested forms of emphasis and strong are NOT supported. For example,

***word*word**

will NOT be translated as you expect.

SpanRuleStack

Strike: e.g. ~~abc~~

SpanRuleStack

Code: e.g. `abc`

SpanRuleUnicode

Hex unicode: e.g. &#xhhhhh;

SpanRuleUnicode

Dec unicode: e.g. &#nnnnnn;

That's it. Enjoy kkmarkdown!

OCaml

Innovation. Community. Security.