this repo has no description

better empty textnode handling

12Me21 319d2f18 38bb2c78

+25 -24
+15 -20
parser.js
··· 107 107 complete() 108 108 } 109 109 // push the start tag (as text) 110 - push_text(o.tag) // todo: merge with surrounding text nodes? 110 + if (o.tag) 111 + push_text(o.tag) // todo: merge with surrounding text nodes? 111 112 // push the contents of the block 112 113 current.content.push(...o.content) 113 114 } 114 115 // push text 115 116 function push_text(text) { 116 - if (text) 117 + if (text!="") 117 118 current.content.push(text) 118 119 } 119 120 // push empty tag ··· 145 146 146 147 function process(type, text) { 147 148 switch (type) { 148 - default: 149 + default: // SHOULD NEVER HAPPEN 150 + console.error('unknown node', type, text) 149 151 push_text(text) 150 152 case 'newline': 151 153 while (1) ··· 213 215 let [, name, args] = /^[\\](\w+)(?:\[(.*?)\])?/.exec(tag) 214 216 current.envtype = name 215 217 current.args = parse_args(args) 218 + complete() 216 219 } 217 220 } 218 221 break;case 'escape': ··· 266 269 267 270 //tODO: kill newlines around things 268 271 269 - // what if we parse arglists as something like: 270 - // just scan for [...] everywhere, and 271 - // then later in the tree building step, we can check like 272 - // if the previous thing was something which takes arguments, then we apply those args 273 - // otherwise just insert the block literally 274 - // the one issue is like, how to handle \env[...]{ 275 - // where the { goes after... 276 - // perhaps we can parse for [...]{? and then uh 277 - // handle that later... 278 - // oh except... 279 - // this won't work, because if there's a [...] which is NOT an arg list, 280 - // now the parser is going to skip over it... yeah... 272 + // we need to remove any newline which comes directly after a block element 273 + // this INCLUDES things like, potentially 274 + 275 + // <i> 276 + // <table> 277 + // .. 278 + // </table> 279 + // </i> 280 + // <br> 281 281 282 282 // other problem: 283 283 ··· 287 287 // \tag{ ... \} >{...\} idk.. 288 288 // or match paired {}s : 289 289 // \tag{ ... {heck} ... } <- closes here 290 - 291 - // terminology 292 - // "tag" - roughly, anything which gets parsed. ex: /italic/ <- 2 tags, 293 - // "environment" - these tags: \tag{ 294 - //
+10 -4
render.js
··· 8 8 9 9 let blocks = { 10 10 ROOT: frag, 11 - newline: creator('br'), 11 + newline() { 12 + let f = frag() 13 + f.append(elem('br'), document.createTextNode("")) 14 + return f 15 + }, 12 16 line: creator('hr'), 13 17 italic: creator('i'), 14 18 bold: creator('b'), ··· 75 79 76 80 return x 77 81 }, 82 + env() { 83 + let x = elem('input') 84 + return x 85 + } 78 86 } 79 87 80 88 let no_args = [] ··· 102 110 103 111 // todo: .normalize to combine text nodes? or is it better if we do that ourselves... normalize also kills empty nodes which is.. idk 104 112 function render(tree) { 105 - let f = render_branch(tree) 106 - f.normalize() 107 - return f 113 + return render_branch(tree) 108 114 } 109 115 110 116