An extensible alternative to markdown

Codigo Noob
5 min readSep 27, 2020

Markdown is so natural to use that I find myself using it even where it is not supported. I still don’t like some aspects of it like inline HTML, inconsistent rules and the fact that it’s not easily extensible.

I will try to present to you here an alternative that improves on those three points while still being simple to use, and maybe someday I’ll also write about how to implement a parser for it in rust.

I introduce to you Backslash Markup Language (BS Lang).

Skip directly to the CHEATSHEAT part to avoid reading unnecessary rules.

Tags:

Since a lot of people are familiar with HTML, I’ll use the notion tag for the language items.

All tags start with a backslash, followed by identifier of the element and a space. An element is closed with backslash followed by a dot. E.g. the following line is a heading 1: \h1 The title\. .

But.. Markdown has the benefit of not having to close some of the tags. For that case you can use the self-closing tags, which will close by the end of the line (or the parent tag). The opening tag for this begins with a backslash followed by identifier, another backslash after it and then a space. E.g. the following line is equivalent to the previous example.

\h1\ The title

There are also tags which need multiple parameters. An example would be a link element. That can be done using the \+ -sequence. If you wanted to add a URL for example you would add:

\a https://medium.com/\+ Link title\+ The text of the link\.

This would have a similar semantic to build_a("https://medium.com/", "Link title", "The text of the link") in a c-style language and to <a href="https://medium.com/" title="Link title">The text of the link</a>.

You could also use a self-closing tag for the last parameter on the tag like this:

\a https://medium.com/\+ Link title\+\ The text of the link

Some other syntactic helpers about the tags would be:

  • Use double backslash \\ if you want to just use backslash as a character
  • Backslash followed by a space can be used as closing tag followed by a space. e.g. \h1 Title\ text translates to <h1>Title</h1> text which avoids adding a . after the last backslash.
  • Newlines are not manipulated in any way by default (e.g. translating to HTML every newline will be translated to <br> ). To escape a new line you can use \< as the last character in the line.
  • Use the following style to ignore backslashes and consider them the same as other characters \#custom-text#h2 This h2 can contain a \ which is not parsed. This is how it is actually closed\#custom-text#. . You can use this with the self-closing tag as well.

You can also specify which tags can be used inside of which other tags. For e.g. You wouldn’t want to use a h3 inside of an h5 or use anything except from text in an alt-text of img.

And that should be it. There should be no more rules to it.

How is this extensible

Well, if you wanted to add some additional element types in markdown, you would have to change some existing rules.

Say for example we want to add math formulas as a feature. After searching the internet we can notice that most of the implementation (I won’t name any, but there are plenty if you search for “math in markdown”).

Some of them will add additional syntax rules. You have to get used to these and make sure that you aren’t breaking any if you’re adding math to an old document.

Some others will use the ``` code block but specifying the plugin name. This is better, but you’re still using an existing feature for a different purpose. And you’d still need to break some rules for displaying formulas inline.

What BSLang offers is the ability to add new elements, so that if you want to use a library named BSMath, you would write everything inside the bsmath tag. E.g. \bsmath S = 2 * $PI * r \..

Cheatsheat (Backslash -> HTML)

The following is an implementation of Backslash to HTML which could be used as an alternative to markdown. I used this as reference.

Normal text:

This is normal text.
This is a normal backslash \\
All this text is \<
in the same line

Headers:

\h1 This is a <h1>\.
\h2 This is a <h2>\.
\h6 You get the point\.
\h3\ This is a self closing <h3>

Emphasis:

\b This is bold\.
\i This is italic\.
\b \i \u This is bold, italic and underscored\.\.\.
\~ This is scratched\.
You can use \b bold\ in between the sentence without having to add a dot after closing backslash if it already has a space. Same goes for \i italic\., \u underscored\ and \~ scratched\ as well.

Lists:

\ol
\-\ This is an ordered list item
\-\ This is another ordered list item
\-\ You get the point
\.
\ul
\-\ This is an unordered list item
\-\ This is another unordered list item
\- This is another item
\ul
\- This is a sub-item\.
\.
\.
\.
\ol\ \-\ This is a single item ordered list, useful in sub-items

Links:

\a http://url-here.com\.
\a http://url-here.com\+ This is the link text\+ This is the title\.
Alternatively:
\a\ http://url-here.com
\a http://url-here.com\+\ This is the link text
\a http://url-here.com\+ This is the link text\+\ This is the title

Images:

\img http://url-to.com/img.png\
\img http://url-to.com/img.png\+ With alt text\
Alternatively:
\img\ http://url-to.com/img.png
\img http://url-to.com/img.png\+\ With alt text

Code:

We can use \` inline code\\code Or we can use code blocks\These might be the weirdest part of this markup language:\code rust\+ 
fn main() {
println!("We can also specify the language of the code block");
}
\
\##code rust\##+
fn main() {
print!("We don't have to escape the newline backslash\n")
}
\##

Tables:

\table
\head Column 1 \+ Column 2 \.
\trow Some \+ text \.
\trow Some other \+ text \.
\trow \b Bold\ text \+ \i italic\ text \.
\.

Blockquotes:

\quote This is a blockquote\
\quote\ This blockquote ends at the end of the line

--

--