this repo has no description

notes

12Me21 84ed8d85 78e4fca9

+14 -12
+14 -12
parse.js
··· 20 20 // all state is stored in these vars (and REGEX.lastIndex) 21 21 let current, brackets 22 22 23 + // About __proto__ in object literals: 24 + // https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-runtime-semantics-propertydefinitionevaluation 25 + 23 26 // elements which can survive an eol (without a body) 24 27 const IS_BLOCK = {__proto__:null, code:1, divider:1, ROOT:1, heading:1, quote:1, table:1, table_cell:1, image:1, video:1, audio:1, spoiler:1, align:1, list:1, list_item:1, youtube:1} 25 28 ··· 71 74 const ARGS_CODE = // ... ``` 72 75 /(?: *([-\w.+#$ ]+?) *(?:\n|$))?([^]*?)(?:```|$)/y 73 76 74 - // problem with improving style parsing: 75 - // sometimes a style tag might be valid as both a start and end tag? 76 - // and we don't know until we also check the previous char 77 77 PAT`[\n]?[}]${{ BLOCK_END: 0}}` 78 78 PAT`[\n]${{ NEWLINE: 0}}` 79 79 PAT`{BOL}[#]{1,4}${{ HEADING: ARGS_HEADING}}` ··· 150 150 } 151 151 TEXT(token) 152 152 } break; case 'BLOCK_END': { 153 - if (brackets<=0) { 153 + if (brackets>0) { 154 + while (!current.body) 155 + CANCEL() 156 + if ('invalid'===current.type) { 157 + if ("\n}"==token) 158 + NEWLINE(false) // false since we already closed everything 159 + TEXT("}") 160 + } 161 + CLOSE() 162 + } else { 154 163 // hack: 155 164 if ("\n}"==token) 156 165 NEWLINE(true) 157 166 TEXT("}") 158 - return 159 167 } 160 - // only runs if at least 1 element has a body, so this won't fail: 161 - while (!current.body) 162 - CANCEL() 163 - if ('invalid'===current.type) 164 - TEXT("}") 165 - CLOSE() 166 168 } break; case 'NULL_ENV': { 167 169 OPEN('null_env', token, null, true) 168 170 current.prev = current.parent.prev ··· 469 471 } 470 472 471 473 function parse(text) { 472 - let tree = {type: 'ROOT', token: "", content: [], prev: 'all_newline'} 474 + let tree = {type: 'ROOT', content: [], prev: 'all_newline'} 473 475 current = tree 474 476 brackets = 0 475 477