···107107 complete()
108108 }
109109 // push the start tag (as text)
110110- push_text(o.tag) // todo: merge with surrounding text nodes?
110110+ if (o.tag)
111111+ push_text(o.tag) // todo: merge with surrounding text nodes?
111112 // push the contents of the block
112113 current.content.push(...o.content)
113114 }
114115 // push text
115116 function push_text(text) {
116116- if (text)
117117+ if (text!="")
117118 current.content.push(text)
118119 }
119120 // push empty tag
···145146146147 function process(type, text) {
147148 switch (type) {
148148- default:
149149+ default: // SHOULD NEVER HAPPEN
150150+ console.error('unknown node', type, text)
149151 push_text(text)
150152 case 'newline':
151153 while (1)
···213215 let [, name, args] = /^[\\](\w+)(?:\[(.*?)\])?/.exec(tag)
214216 current.envtype = name
215217 current.args = parse_args(args)
218218+ complete()
216219 }
217220 }
218221 break;case 'escape':
···266269267270//tODO: kill newlines around things
268271269269-// what if we parse arglists as something like:
270270-// just scan for [...] everywhere, and
271271-// then later in the tree building step, we can check like
272272-// if the previous thing was something which takes arguments, then we apply those args
273273-// otherwise just insert the block literally
274274-// the one issue is like, how to handle \env[...]{
275275-// where the { goes after...
276276-// perhaps we can parse for [...]{? and then uh
277277-// handle that later...
278278-// oh except...
279279-// this won't work, because if there's a [...] which is NOT an arg list,
280280-// now the parser is going to skip over it... yeah...
272272+// we need to remove any newline which comes directly after a block element
273273+// this INCLUDES things like, potentially
274274+275275+// <i>
276276+// <table>
277277+// ..
278278+// </table>
279279+// </i>
280280+// <br>
281281282282// other problem:
283283···287287// \tag{ ... \} >{...\} idk..
288288// or match paired {}s :
289289// \tag{ ... {heck} ... } <- closes here
290290-291291-// terminology
292292-// "tag" - roughly, anything which gets parsed. ex: /italic/ <- 2 tags,
293293-// "environment" - these tags: \tag{
294294-//
+10-4
render.js
···8899let blocks = {
1010 ROOT: frag,
1111- newline: creator('br'),
1111+ newline() {
1212+ let f = frag()
1313+ f.append(elem('br'), document.createTextNode(""))
1414+ return f
1515+ },
1216 line: creator('hr'),
1317 italic: creator('i'),
1418 bold: creator('b'),
···75797680 return x
7781 },
8282+ env() {
8383+ let x = elem('input')
8484+ return x
8585+ }
7886}
79878088let no_args = []
···102110103111// todo: .normalize to combine text nodes? or is it better if we do that ourselves... normalize also kills empty nodes which is.. idk
104112function render(tree) {
105105- let f = render_branch(tree)
106106- f.normalize()
107107- return f
113113+ return render_branch(tree)
108114}
109115110116