Giter Club home page Giter Club logo

smu's Introduction

smu - a Simple Markup Language
==============================

_smu_ is a very simple and minimal markup language. It is designed for use in
wiki-like environments. smu makes it very easy to write your documents on the
fly and convert them into HTML.

smu is capable of parsing very large documents. It scales just great as long
as you avoid a huge amount of indents.

Syntax
======

smu was started as a rewrite of
[markdown](http://daringfireball.net/projects/markdown/) but became something
more lightweight and consistent. It differs from [CommonMark](https://commonmark.org/) in the following ways:

* No support for _reference style links_
* Stricter indentation rules for lists
* Lists don't end paragraphs by themselves (blank line needed)
* Horizontal rules (`<hr>`) must use `- - -` as syntax
* Code fences have stricter syntax

Patches that increase the CommonMark compatibility are welcome as long as they don't increase the code complexity significantly.

This project is a fork of the [original smu](https://github.com/gottox/smu) by
[Enno Boland (gottox)](https://eboland.de). The main differences to the
original smu are:

* Support for code fences
* Improved [CommonMark](https://commonmark.org/) compatibility. E.g.
  * Code blocks need four spaces indentation instead of three
  * Skip empty lines at end of code blocks
  * Ignore single spaces around code spans
  * Keep HTML comments in output
  * Improved spec compliance for lists
  * Nesting code block in blockquotes works
  * "Empty" lines in lists behave identically, no matter how much whitespace they contain
  * No backslash escapes in code blocks
  * Use first number as start number for ordered lists
* Added a simple test suite to check for compliance and avoid regressions

Inline patterns
---------------

There are several patterns you can use to highlight your text:

* Emphasis
  * Surround your text with `*` or `_` to get *emphasised* text:
    	This *is* cool.
    	This _is_ cool, too.
  * Surround your text with `**` or `__` to get **strong** text:
    	This **is** cool.
    	This __is__ cool, too.
  * Surround your text with `***` or `___` to get ***strong and emphasised*** text:
    	This ***is*** cool.
    	This ___is___ cool, too.
  * But this example won't work as expected:
    	***Hello** you*
    This is a wontfix bug because it would make the source too complex.
    Use this instead:
    	***Hello*** *you*

* inline Code

  You can produce inline code by surrounding it with backticks.

  	Use `rm -rf /` if you're a N00b.
  	Use ``rm -rf /`` if you're a N00b.
  	Use ```rm -rf /``` if you're a N00b.

  Double and triple backticks can be used if the code itself contains backticks.


Titles
------

Creating titles in smu is very easy. There are two different syntax styles. The
first is underlining with at least three characters:

	Heading
	=======
	
	Topic
	-----

This is very intuitive and self explaining. The resulting sourcecode looks like
this:

	<h1>Heading</h1>
	<h2>Topic</h2>

Use the following prefixes if you don't like underlining:

	# h1
	## h2
	### h3
	#### h4
	##### h5
	###### h6

Links
-----

The simplest way to define a link is with simple `<>`.

	<http://s01.de>

You can do the same for E-Mail addresses:

	<[email protected]>

If you want to define a label for the url, you have to use a different syntax

	[smu - simple mark up](http://s01.de/~gottox/index.cgi/proj_smu)

The resulting HTML-Code

	<a href="http://s01.de/~gottox/index.cgi/proj_smu">smu - simple mark up</a></p>

Images
------

Images use a syntax similar to the one for links:

	![optional alt text](http://example.com/image.png)

Lists
-----

Defining lists is very straightforward:

	* Item 1
	* Item 2
	* Item 3

Result:

	<ul>
	<li>Item 1</li>
	<li>Item 2</li>
	<li>Item 3</li>
	</ul>

Defining ordered lists is also very easy:

	1. Item 1
	2. Item 2
	3. Item 3

Only the first number in a list is meaningful. All following list items are
continously counted. If you want a list starting at 2, you could write:

	2. Item 1
	2. Item 2
	2. Item 3

and get the following HTML which will render with the numbers 2, 3, 4:

	<ol start="2">
	<li>Item 1</li>
	<li>Item 2</li>
	<li>Item 3</li>
	</ol>

Code & Blockquote
-----------------

Use the `> ` as a line prefix for defining blockquotes. Blockquotes are
interpreted as well. This makes it possible to embed links, headings and even
other quotes into a quote:

	> Hello
	> This is a quote with a [link](http://s01.de/~gottox)

Result:
	<blockquote><p>
	Hello
	This is a quote with a <a href="http://s01.de/~gottox">link</a></p>
	</blockquote>


You can define a code block with a leading Tab or with __4__ leading spaces

		this.is(code)
	
	    this.is(code, too)

Result:
	<pre><code>this.is(code)</code></pre>
	<pre><code>this.is(code, too)
	</code></pre>

Please note that you can't use HTML or smu syntax in a code block.

Another way to write code blocks is to use code fences:

	```json
	{"some": "code"}
	```

This has two advantages:
* The optional language identifier will be turned into a `language-` class name
* You can keep the original indentation which helps when doing copy & paste

Tables
------

Tables can be generated with the following syntax:

	| Heading1 | Heading2 |
	| -------- | -------- |
	| Cell 1   | Cell2    |

Aligning the columns make the input nicer to read, but is not necessary to get
correct table output. You could just write

	| Heading1 | Heading2 |
	| --- | --- |
	| Cell 1 | Cell2 |

To align the content of table cells, use `|:--|` for left, `|--:|` for right
and `|:--:|` for centered alignment in the row which separates the header from
the table body.

	| Heading1 | Heading2 | Heading3 |
	| :------- | :------: | -------: |
	| Left     | Center   | Right    |

Other interesting stuff
-----------------------

* to insert a horizontal rule simple add `- - -` into an empty line:

  	Hello
  	- - -
  	Hello2

  Result:
  	<p>
  	Hello
  	<hr />
  	
  	Hello2</p>

* Any ASCII punctuation character may escaped by precedeing them with a
  backslash to avoid them being interpreted:

  	!"#$%&'()*+,-./:;<=>?@[]^_`{|}~\

* To force a linebreak simple add two spaces to the end of the line:

  	No linebreak
  	here.
  	But here is  
  	one.

embed HTML
----------

You can include arbitrary HTML code in your documents. The HTML will be
passed through to the resulting document without modification. This is a good
way to work around features that are missing in smu. If you don't want this
behaviour, use the `-n` flag when executing smu to stricly escape the HTML
tags.

smu's People

Contributors

gottox avatar hiltjo avatar karlb avatar mstevens avatar n-r-k avatar nabijaczleweli avatar ypnose avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

smu's Issues

Links containing single quote don't work

This is because of the optional "title" attribute for links.

The spec says "If both link destination and link title are present, they must be separated by spaces, tabs, and up to one line ending." (https://spec.commonmark.org/0.30/#links), so it should be possible to preserve single quotes that come before a whitespace character followed by a quote inside the link parenthesis.

A workaround is to use URL percent-encoding, but this is inconvenient when copying and pasting links.

Blank lines in code blocks within list items

For the following file:

* a
  * b
        a

        b

smu renders:

<ul>
<li><p>a
<ul>
<li>b
<pre><code>a
</code></pre>
</li>
</ul>
</p>
<pre><code>  b
</code></pre>
</li>
</ul>

and I would rather have it render something like:

<ul>
<li>a
<ul>
<li>b
<pre><code>a

b
</code></pre>
</li>
</ul>
</li>
</ul>

Can I have it so smu respect blank lines in code block within lists? Any recommended way of solving this?

Does not support tables (patch included)

Hi,

I couldn't find the very much needed table support, so I've added a Parser for it. It is using a minimalistic state-machine in the spirit of simplicity. Known issues:

  1. you have to add it before the doparagraph parser, otherwise your tables will be surrounded by <p></p>
  2. only handles 32 coloumns' alignments (more supported, just always will be left-aligned)
  3. it does not right-trim the table cells. Implementing this would require lot more complexity, and I've thought simplicity is more important here.

Supports normal coloumns, |---|, right aligned |--:| and centered |:-:|. Licensed under MIT, use it as you wish.

/* smu table parser, Copyright(C) bzt 2022 MIT */

static char intable = 0, inrow, incell;                         /* table state */
static long int calign;

int
dotable(const char *begin, const char *end, int newblock) {
    const char *p;
    int i, l = (int)sizeof(calign) * 4;

    if(*begin != '|')
        return 0;
    if(inrow && (begin + 1 >= end || begin[1] == '\n')) {       /* close cell and row and if ends, table too */
        fprintf(stdout, "</t%c></tr>", inrow == -1 ? 'h' : 'd');
        inrow = 0;
        if(begin + 2 >= end || begin[2] == '\n') {
            intable = 0;
            fputs("\n</table>", stdout);
            return 2;
        }
        return 1;
    }
    if(begin < end && (begin[1] == '-' || begin[1] == ':')) {   /* only load cell aligns from 2nd line */
        for(i = -1, p = begin; p < end && *p != '\n'; p++)
            if(*p == '|') {
                i++;
                if(i < l && p[1] == ':') {
                    calign |= 1 << (i * 2); p++;
                }
            } else
            if(i < l && *p == ':')
                calign |= 1 << (i * 2 + 1);
        return p - begin + 1;
    }
    if(!intable) {                                              /* open table */
        intable = 1; inrow = -1; incell = 0; calign = 0;
        fputs("<table>\n<tr>", stdout);
    }
    if(!inrow) {                                                /* open row */
        inrow = 1; incell = 0;
        fputs("<tr>", stdout);
    }
    if(incell)                                                  /* close cell */
        fprintf(stdout, "</t%c>", inrow == -1 ? 'h' : 'd');
    l = incell < l ? (calign >> (incell * 2)) & 3 : 0;          /* open cell */
    fprintf(stdout, "<t%c%s>", inrow == -1 ? 'h' : 'd',
        l == 2 ? " class=\"right\"" : (l == 3 ? " class=\"center\"" : ""));
    incell++;
    for(p = begin + 1; p < end && *p == ' '; p++);
    return p - begin;
}

Cheers,
bzt

UTF-8 headings not detected (patch included)

Hi,

This code does not work if there are UTF-8 characters in the headings. The reason for this is, it expects at least as many = or - characters in the next line as the heading's length in bytes. Now this is only true for English headings, encoded as ASCII. With UTF-8, you can't use the number of bytes, you have to use the number of characters instead.

For example:

abc          (l=3)
===          (j=3, so correctly detected as a heading)

ábc          (l=4)
===          (j=3, so incorrectly NOT detected as a heading)

This patch fixes this, while keeping backward compatibility.

diff --git a/smu.c b/smu.c
index fea4fbd..9272855 100644
--- a/smu.c
+++ b/smu.c
@@ -589,19 +589,20 @@ dosurround(const char *begin, const char *end, int newblock) {
 
 int
 dounderline(const char *begin, const char *end, int newblock) {
-       unsigned int i, j, l;
+       unsigned int i, j, l, k;
        const char *p;
 
        if (!newblock)
                return 0;
        p = begin;
-       for (l = 0; p + l != end && p[l] != '\n'; l++);
+       for(l = k = 0; p + l != end && p[l] != '\n'; l++)
+               if(p[l] > 0 || ((unsigned char)p[l] & 0xC0) == 0xC0) k++;
        p += l + 1;
        if (l == 0)
                return 0;
        for (i = 0; i < LENGTH(underline); i++) {
                for (j = 0; p + j < end && p[j] != '\n' && p[j] == underline[i].search[0]; j++);
-               if (j >= l) {
+               if (j >= k) {
                        fputs(underline[i].before, stdout);
                        if (underline[i].process)
                                process(begin, begin + l, 0);

This code uses l for the length (number of bytes, just as the original), but it also counts number of multi-byte characters in k, and then compares j with that latter.

Cheers,
bzt

<br> works but <br><br> doesn't

If I run the following command:

echo 'Hello<br><br>world' | smu

I expect to see:

<p>Hello<br><br>world</p>

but I get this:

<p>Hello<br><br&gt;world</p>

If I use only one <br> then smu works as expected, but two <br>s mangles the second one. Markdown.pl works in both cases. Do you have any suggestions on how to get around this?

Note: I know there are other ways to embed newlines in the rendered HTML, but I need the Markdown source to be on one line because I need to pass it through sort

Lists should interrupt paragraphs

HTML does not allow lists in paragraphs, so

foo:
- bar

should result in

<p>foo:</p>
<ul>
<li>bar</li>
</ul>

not

<p>foo:
<ul>
<li>bar</li>
</ul>
</p>

as it does now.

Embedded HTML tags get wrapped in <p> tags

The readme says: "You can include arbitrary HTML code in your documents. The HTML will be
passed through to the resulting document without modification."

But when you embed top-level HTML tags like "div", they get wrapped in "p" tags. I think the ideal behavior would as the readme suggests, which is to not add the "p" tags.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.