领券减价怎么说
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.
Markdown使用起来很自然,即使在不受支持的地方,我也发现自己正在使用它。 我仍然不喜欢它的某些方面,例如内联HTML,规则不一致以及它不容易扩展的事实。
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
.
我将在这里尝试向您介绍一个替代方法,该方法在这三点上有所改进,同时仍易于使用,也许有一天,我还将写一篇关于如何在rust
实现解析器的文章。
I introduce to you Backslash Markup Language (BS Lang).
我向您介绍了反斜杠标记语言(BS Lang)。
Skip directly to the CHEATSHEAT part to avoid reading unnecessary rules.
直接跳至CHEATSHEAT部分,以避免阅读不必要的规则。
标签: (Tags:)
Since a lot of people are familiar with HTML, I’ll use the notion tag for the language items.
由于很多人都熟悉HTML,因此我将在语言项目中使用标记。
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\.
.
所有标签均以反斜杠开头,后跟元素标识符和空格。 元素以反斜杠后跟一个点关闭。 例如,以下行是标题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.
但是Markdown的好处是不必关闭某些标签。 在这种情况下,您可以使用自动关闭标签,该标签将在行尾(或父标签)关闭。 为此的开始标记以反斜杠开头,后跟标识符,其后是另一个反斜杠,然后是空格。 例如,以下行等效于上一个示例。
\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:
也有需要多个参数的标签。 一个示例是链接元素。 可以使用\+
序列来完成。 例如,如果要添加URL,则可以添加:
\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>
.
这将具有使用c样式语言的build_a(" https://medium.com /", "Link title", "The text of the link")
和<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.反斜杠后跟空格可以用作结束标记,后跟空格。 例如
\h1 Title\ text
转换为<h1>Title</h1> text
,避免添加.
最后一个反斜杠之后。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.默认情况下,不以任何方式操纵换行符(例如,将每个换行符翻译为HTML都将转换为
<br>
)。 要转义新行,可以使用\<
作为该行的最后一个字符。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.使用以下样式可忽略反斜杠,并认为它们与其他字符
\#custom-text#h2 This h2 can contain a \ which is not parsed. This is how it is actually closed\#custom-text#.
\#custom-text#h2 This h2 can contain a \ which is not parsed. This is how it is actually closed\#custom-text#.
。 您也可以将其与自动关闭标签一起使用。
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
.
您还可以指定在其他标签中可以使用哪些标签。 例如,您不想在h5
内使用h3
或使用其他任何东西,除了img
的alt-text中的文本。
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.
好吧,如果您想在markdown中添加一些其他元素类型,则必须更改一些现有规则。
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”).
例如,我们要添加数学公式作为功能。 在互联网上搜索之后,我们可以注意到大多数实现方式(我不会透露任何名称,但是如果您搜索“ 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 \.
.
BSLang提供的功能是添加新元素的能力,因此,如果要使用名为BSMath的库,则可以将所有内容写入bsmath
标记中。 例如\bsmath S = 2 * $PI * r \.
。
作弊(反斜杠-> HTML) (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.
以下是HTML的反斜杠实现,可以用作降价的替代方法。 我以此为参考。
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
翻译自: https://medium.com/@codenoob/an-extensible-alternative-to-markdown-b29c015cfc66
领券减价怎么说