如何使用wiky.js将有序的wikitext列表解析为HTML? [英] How to parse ordered list of wikitext to HTML using wiky.js?

查看:116
本文介绍了如何使用wiky.js将有序的wikitext列表解析为HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 wiky.js将有序的wikitext列表解析为html 。这个JavaScript主要是使用正则表达式来做到这一点。

I need to parse ordered list of wikitext to html using wiky.js. This javascript is mainly using regex to do that.



E.g.

# Item1
# Item2
# Item3
# Item4
## Sub-item 1
### Sub-sub-item

显示为



is displayed as

1.Item1
2.Item2
3.Item3
4.Item4
    1.Sub-item 1
       1. Sub-sub-item

我需要获得代码的HTML版本。目前wiky.js使用旧版本的解析有序列表,而现在维基编辑器不支持该列表。

I need to get the HTML version of the code. Currently wiky.js uses the old version of parsing ordered list which is not supported by Wiki Editor now.

推荐答案

添加以下内容:

Add the following:

{
    rex: /^((#*)[^#].*(\n))(?=#\2)/gm,
    tmplt: "$1<ol>$3"
},
{
    rex: /^((#+).*(\n))(?!\2|<ol)/gm,
    tmplt: "$1</ol>$2.$2$3"
},
{
    rex: /#(?=(#+)\.#+\n(?!\1))/gm,
    tmplt: "</ol>"
},
{
    rex: /(<\/ol>)[#.]+/gm,
    tmplt: "$1"
},
{
    rex: /^((#+).*(\n))(?=\2[^#]|<\/ol)/gm,
    tmplt: "$1</li>$3"
},
{
    rex: /^(<\/ol>(\n)*)#+/gm,
    tmplt: "$1</li>$2<li>"
},
{
    rex: /^#+/gm,
    tmplt: "<li>"
}

希望它们按此顺序执行。这将涵盖< ol>< li>< / li>< / ol>< / code>标记的潜在无限递归级别。

Hoping they are executed in this order. This will cover a potentially infinite recursion level of <ol><li></li></ol> tags.

我没有向你解释代码,因为我使用了一些肮脏的权宜之计,其逻辑很难展开。

I don't explain you the code 'cause I've used some dirty expedients whose logic it's hard to unfold.

这篇关于如何使用wiky.js将有序的wikitext列表解析为HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆