-2

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

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.

1 Answers1

0

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>"
}

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.

logi-kal
  • 7,107
  • 6
  • 31
  • 43
  • The code works fine if I don't add it to wiky.js. If I add it to wiky.js, it conflicts with the

    tag. How can I remove the conflict, any help?

    – Srijan Agarwal Jul 22 '16 at 05:25
  • So this is what happening. `# First # second ## Second-First #### z #### y #### x *** Third Point ## Second-Second [ftp://www.facebook.com FacebookFTP] ## Second-Third [http://www.google.com Google Here] # third` If I'm using this to parse to html, `

    # First # secon ## Second-First

    ?(p_uuu)
  • Third Point ## Second-Second FacebookFTP ## Second-Third Google Here # third
  • ` This is what is getting displayed. – Srijan Agarwal Jul 22 '16 at 06:58
  • First, the code is not expected to be used togheter with pointed lists. Second, you have added the code in the inverse function part, that is the part where it's HTML to be parsed and converted to wiki (and with `` you have done the contrary). Are you sure of what you are doing? – logi-kal Jul 22 '16 at 08:57
  • I did add this code to wikiinlines as well, the place where I added `` tag. When I added there, this goes the result : `
  • Item1 # Item2 # Item3 # Item4 ## Sub-item 1 ### Sub-sub-item`
  • – Srijan Agarwal Jul 22 '16 at 12:50