* 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)
| 2015 | * @returns {string} |
| 2016 | */ |
| 2017 | function processListItems (listStr, trimTrailing) { |
| 2018 | // The $g_list_level global keeps track of when we're inside a list. |
| 2019 | // Each time we enter a list, we increment it; when we leave a list, |
| 2020 | // we decrement. If it's zero, we're not in a list anymore. |
| 2021 | // |
| 2022 | // We do this because when we're not inside a list, we want to treat |
| 2023 | // something like this: |
| 2024 | // |
| 2025 | // I recommend upgrading to version |
| 2026 | // 8. Oops, now this line is treated |
| 2027 | // as a sub-list. |
| 2028 | // |
| 2029 | // As a single paragraph, despite the fact that the second line starts |
| 2030 | // with a digit-period-space sequence. |
| 2031 | // |
| 2032 | // Whereas when we're inside a list (or sub-list), that line will be |
| 2033 | // treated as the start of a sub-list. What a kludge, huh? This is |
| 2034 | // an aspect of Markdown's syntax that's hard to parse perfectly |
| 2035 | // without resorting to mind-reading. Perhaps the solution is to |
| 2036 | // change the syntax rules such that sub-lists must start with a |
| 2037 | // starting cardinal number; e.g. "1." or "a.". |
| 2038 | globals.gListLevel++; |
| 2039 | |
| 2040 | // trim trailing blank lines: |
| 2041 | listStr = listStr.replace(/\n{2,}$/, '\n'); |
| 2042 | |
| 2043 | // attacklab: add sentinel to emulate \z |
| 2044 | listStr += '~0'; |
| 2045 | |
| 2046 | var rgx = /(\n)?(^[ \t]*)([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(~0|\2([*+-]|\d+[.])[ \t]+))/gm, |
| 2047 | isParagraphed = (/\n[ \t]*\n(?!~0)/.test(listStr)); |
| 2048 | |
| 2049 | listStr = listStr.replace(rgx, function (wholeMatch, m1, m2, m3, m4, taskbtn, checked) { |
| 2050 | checked = (checked && checked.trim() !== ''); |
| 2051 | var item = showdown.subParser('outdent')(m4, options, globals), |
| 2052 | bulletStyle = ''; |
| 2053 | |
| 2054 | // Support for github tasklists |
| 2055 | if (taskbtn && options.tasklists) { |
| 2056 | bulletStyle = ' class="task-list-item" style="list-style-type: none;"'; |
| 2057 | item = item.replace(/^[ \t]*\[(x|X| )?]/m, function () { |
| 2058 | var otp = '<input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;"'; |
| 2059 | if (checked) { |
| 2060 | otp += ' checked'; |
| 2061 | } |
| 2062 | otp += '>'; |
| 2063 | return otp; |
| 2064 | }); |
| 2065 | } |
| 2066 | // m1 - Leading line or |
| 2067 | // Has a double return (multi paragraph) or |
| 2068 | // Has sublist |
| 2069 | if (m1 || (item.search(/\n{2,}/) > -1)) { |
| 2070 | item = showdown.subParser('githubCodeBlocks')(item, options, globals); |
| 2071 | item = showdown.subParser('blockGamut')(item, options, globals); |
| 2072 | } else { |
| 2073 | // Recursion for sub-lists: |
| 2074 | item = showdown.subParser('lists')(item, options, globals); |
no outgoing calls
no test coverage detected