* Process the contents of a single ordered or unordered list, splitting it * into individual list items. * @param {string} listStr * @param {boolean} trimTrailing * @returns {string}
(listStr, trimTrailing)
| 12 | * @returns {string} |
| 13 | */ |
| 14 | function processListItems (listStr, trimTrailing) { |
| 15 | // The $g_list_level global keeps track of when we're inside a list. |
| 16 | // Each time we enter a list, we increment it; when we leave a list, |
| 17 | // we decrement. If it's zero, we're not in a list anymore. |
| 18 | // |
| 19 | // We do this because when we're not inside a list, we want to treat |
| 20 | // something like this: |
| 21 | // |
| 22 | // I recommend upgrading to version |
| 23 | // 8. Oops, now this line is treated |
| 24 | // as a sub-list. |
| 25 | // |
| 26 | // As a single paragraph, despite the fact that the second line starts |
| 27 | // with a digit-period-space sequence. |
| 28 | // |
| 29 | // Whereas when we're inside a list (or sub-list), that line will be |
| 30 | // treated as the start of a sub-list. What a kludge, huh? This is |
| 31 | // an aspect of Markdown's syntax that's hard to parse perfectly |
| 32 | // without resorting to mind-reading. Perhaps the solution is to |
| 33 | // change the syntax rules such that sub-lists must start with a |
| 34 | // starting cardinal number; e.g. "1." or "a.". |
| 35 | globals.gListLevel++; |
| 36 | |
| 37 | // trim trailing blank lines: |
| 38 | listStr = listStr.replace(/\n{2,}$/, '\n'); |
| 39 | |
| 40 | // attacklab: add sentinel to emulate \z |
| 41 | listStr += '¨0'; |
| 42 | |
| 43 | var rgx = /(\n)?(^ {0,3})([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(¨0| {0,3}([*+-]|\d+[.])[ \t]+))/gm, |
| 44 | isParagraphed = (/\n[ \t]*\n(?!¨0)/.test(listStr)); |
| 45 | |
| 46 | // Since version 1.5, nesting sublists requires 4 spaces (or 1 tab) indentation, |
| 47 | // which is a syntax breaking change |
| 48 | // activating this option reverts to old behavior |
| 49 | if (options.disableForced4SpacesIndentedSublists) { |
| 50 | rgx = /(\n)?(^ {0,3})([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(¨0|\2([*+-]|\d+[.])[ \t]+))/gm; |
| 51 | } |
| 52 | |
| 53 | listStr = listStr.replace(rgx, function (wholeMatch, m1, m2, m3, m4, taskbtn, checked) { |
| 54 | checked = (checked && checked.trim() !== ''); |
| 55 | |
| 56 | var item = showdown.subParser('outdent')(m4, options, globals), |
| 57 | bulletStyle = ''; |
| 58 | |
| 59 | // Support for github tasklists |
| 60 | if (taskbtn && options.tasklists) { |
| 61 | bulletStyle = ' class="task-list-item" style="list-style-type: none;"'; |
| 62 | item = item.replace(/^[ \t]*\[(x|X| )?]/m, function () { |
| 63 | var otp = '<input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;"'; |
| 64 | if (checked) { |
| 65 | otp += ' checked'; |
| 66 | } |
| 67 | otp += '>'; |
| 68 | return otp; |
| 69 | }); |
| 70 | } |
| 71 |
no outgoing calls
no test coverage detected
searching dependent graphs…