|
| 1 | +/** |
| 2 | + * Right now this allows: |
| 3 | + * <section |
| 4 | + * data-markdown="content.md" |
| 5 | + * data-separator-vertical="^### " |
| 6 | + * data-separator="^## " |
| 7 | + * ></section> |
| 8 | + * |
| 9 | + * I like this because you can very quickly map h1 to title, h2 to horizontal slides, and h3 to vertical. |
| 10 | + * Which is how I think of it. |
| 11 | + * |
| 12 | + * But, what if you want an image? Or you don't want the H1 to show? |
| 13 | + * |
| 14 | + * It would be nice to have some other way to indicate a section... I wonder if you can match h2 OR |
| 15 | + * <!-- SECTION --> |
| 16 | + * for a horizontal |
| 17 | + * or some other keyword... |
| 18 | + */ |
1 | 19 | !(function (e, t) { |
2 | 20 | "object" === typeof exports && "undefined" !== typeof module |
3 | 21 | ? (module.exports = t()) |
|
2007 | 2025 | "</script>" |
2008 | 2026 | ); |
2009 | 2027 | } |
2010 | | - function i(e, t) { |
2011 | | - t = s(t); |
2012 | | - const n = new RegExp( |
2013 | | - t.separator + (t.verticalSeparator ? "|" + t.verticalSeparator : ""), |
| 2028 | + function slidify(markdown, options) { |
| 2029 | + options = s(options); |
| 2030 | + const separatorRegex = new RegExp( |
| 2031 | + options.separator + |
| 2032 | + (options.verticalSeparator ? "|" + options.verticalSeparator : ""), |
2014 | 2033 | "mg" |
2015 | 2034 | ), |
2016 | | - i = new RegExp(t.separator); |
2017 | | - let l, |
2018 | | - o, |
2019 | | - a, |
2020 | | - c = 0, |
2021 | | - h = !0, |
2022 | | - p = []; |
2023 | | - for (; (l = n.exec(e)); ) |
2024 | | - (o = i.test(l[0])), |
2025 | | - !o && h && p.push([]), |
2026 | | - (a = e.substring(c, l.index)), |
2027 | | - o && h ? p.push(a) : p[p.length - 1].push(a), |
2028 | | - (c = n.lastIndex), |
2029 | | - (h = o); |
2030 | | - (h ? p : p[p.length - 1]).push(e.substring(c)); |
2031 | | - let u = ""; |
2032 | | - for (let e = 0, n = p.length; e < n; e++) |
2033 | | - p[e] instanceof Array |
2034 | | - ? ((u += "<section " + t.attributes + ">"), |
2035 | | - p[e].forEach(function (e) { |
2036 | | - u += "<section data-markdown>" + r(e, t) + "</section>"; |
| 2035 | + horizontalSeparatorRegex = new RegExp(options.separator); |
| 2036 | + let matches, |
| 2037 | + isHorizontal, |
| 2038 | + content, |
| 2039 | + lastIndex = 0, |
| 2040 | + wasHorizontal = !0, |
| 2041 | + sectionStack = []; |
| 2042 | + for (; (matches = separatorRegex.exec(markdown)); ) { |
| 2043 | + isHorizontal = horizontalSeparatorRegex.test(matches[0]); |
| 2044 | + if (!isHorizontal && wasHorizontal) { |
| 2045 | + sectionStack.push([]); |
| 2046 | + } |
| 2047 | + content = markdown.substring(lastIndex, matches.index); |
| 2048 | + // START MY HACK ================ |
| 2049 | + // Do not add empty slides |
| 2050 | + if (content === "") { |
| 2051 | + // do nothing |
| 2052 | + } |
| 2053 | + // END MY HACK =================== |
| 2054 | + else if (isHorizontal && wasHorizontal) { |
| 2055 | + sectionStack.push(content); |
| 2056 | + } else { |
| 2057 | + sectionStack[sectionStack.length - 1].push(content); |
| 2058 | + } |
| 2059 | + // START MY HACK ================ |
| 2060 | + // This was the original line: |
| 2061 | + // lastIndex = separatorRegex.lastIndex; |
| 2062 | + // This is my line, which preserves the matched symbols (eg ##): |
| 2063 | + lastIndex = separatorRegex.lastIndex - matches[0].length; |
| 2064 | + // END MY HACK =================== |
| 2065 | + wasHorizontal = isHorizontal; |
| 2066 | + } |
| 2067 | + (wasHorizontal |
| 2068 | + ? sectionStack |
| 2069 | + : sectionStack[sectionStack.length - 1] |
| 2070 | + ).push(markdown.substring(lastIndex)); |
| 2071 | + let markdownSections = ""; |
| 2072 | + for (let e = 0, n = sectionStack.length; e < n; e++) |
| 2073 | + sectionStack[e] instanceof Array |
| 2074 | + ? ((markdownSections += "<section " + options.attributes + ">"), |
| 2075 | + sectionStack[e].forEach(function (e) { |
| 2076 | + markdownSections += |
| 2077 | + "<section data-markdown>" + r(e, options) + "</section>"; |
2037 | 2078 | }), |
2038 | | - (u += "</section>")) |
2039 | | - : (u += |
| 2079 | + (markdownSections += "</section>")) |
| 2080 | + : (markdownSections += |
2040 | 2081 | "<section " + |
2041 | | - t.attributes + |
| 2082 | + options.attributes + |
2042 | 2083 | " data-markdown>" + |
2043 | | - r(p[e], t) + |
| 2084 | + r(sectionStack[e], options) + |
2044 | 2085 | "</section>"); |
2045 | | - return u; |
| 2086 | + return markdownSections; |
2046 | 2087 | } |
2047 | 2088 | function l(e) { |
2048 | 2089 | return new Promise(function (s) { |
|
2086 | 2127 | }); |
2087 | 2128 | })(e).then( |
2088 | 2129 | function (t, s) { |
2089 | | - e.outerHTML = i(t.responseText, { |
| 2130 | + e.outerHTML = slidify(t.responseText, { |
2090 | 2131 | separator: e.getAttribute("data-separator"), |
2091 | 2132 | verticalSeparator: e.getAttribute( |
2092 | 2133 | "data-separator-vertical" |
|
2105 | 2146 | } |
2106 | 2147 | ) |
2107 | 2148 | ) |
2108 | | - : (e.outerHTML = i(t(e), { |
| 2149 | + : (e.outerHTML = slidify(t(e), { |
2109 | 2150 | separator: e.getAttribute("data-separator"), |
2110 | 2151 | verticalSeparator: e.getAttribute("data-separator-vertical"), |
2111 | 2152 | notesSeparator: e.getAttribute("data-separator-notes"), |
|
2219 | 2260 | }, |
2220 | 2261 | processSlides: l, |
2221 | 2262 | convertSlides: c, |
2222 | | - slidify: i, |
| 2263 | + slidify: slidify, |
2223 | 2264 | marked: P, |
2224 | 2265 | }; |
2225 | 2266 | }; |
|
0 commit comments