@@ -223,10 +223,51 @@ attribute_entry = ':' negatedPrefix:'!'? name:attribute_name negatedSuffix:'!'?
223
223
return [name, negatedPrefix || negatedSuffix ? null : value || ' ' , range()]
224
224
}
225
225
226
+ attribute_entry_head = ' : ' ' ! ' ? attribute_name ' ! ' ? ' : ' (space / eol)
227
+
226
228
// TODO permit non-ASCII letters in attribute name
227
229
attribute_name = $([a-zA-Z0-9_] [a-zA-Z0-9_-]*)
228
230
229
- attribute_value = space @$(!lf .)+
231
+ //attribute_value = space lines:($(!lf .)*)|1.., &{ let idx = offset(), count = 0; while (input[--idx] === ' \\' ) count++; return !!(count % 2) } lf (&space / !(attribute_entry_head / eol / list_continuation / any_block_delimiter_line / block_attribute_line))|
232
+ //{
233
+ // const lastLineIdx = lines.length - 1
234
+ // if (!lastLineIdx) {
235
+ // const line0 = lines[0]
236
+ // if (!line0) return line0
237
+ // if (line0[line0.length - 1] !== ' \\' ) return line0[0] === ' ' ? line0.trimStart() : line0
238
+ // }
239
+ // let hardWrapNext = false
240
+ // return lines.reduce((buf, line, lineIdx) => {
241
+ // const hardWrap = hardWrapNext
242
+ // if (hardWrap) buf = buf.slice(0, -2) + ' \n'
243
+ // if (lineIdx < lastLineIdx) {
244
+ // if (!(line = line.slice(0, -1)) && !(hardWrapNext = false)) return buf
245
+ // if (line[line.length - 1] === ' \\' ) line = line.replace(/\\ +$/, (m) => m.slice(0, m.length / 2))
246
+ // } else if (line[line.length - 1] === ' \\' ) {
247
+ // line = line.replace(/\\ +$/, (m) => m.slice(0, m.length % 2 ? (m.length - 1) / 2 + 1 : m.length / 2))
248
+ // }
249
+ // hardWrapNext = line.length > 1 && line[line.length - 2] === ' ' && line[line.length - 1] === ' '
250
+ // return buf + (hardWrap || line[0] !== ' ' ? line : line.trimStart())
251
+ // }, ' ' )
252
+ //}
253
+
254
+ attribute_value = space lines:($(!(' \\' / lf) . / ' \\' !lf .)*)|1.., ' \\' lf (&space / !(attribute_entry_head / eol / list_continuation / any_block_delimiter_line / block_attribute_line))| trailer:(' \\' / ' ' )
255
+ {
256
+ if (lines.length === 1) {
257
+ const line0 = lines[0]
258
+ if (!line0) return trailer
259
+ if (line0[line0.length - 1] !== ' \\' ) return (line0[0] === ' ' ? line0.trimStart() : line0) + trailer
260
+ }
261
+ let hardWrapNext = false
262
+ return lines.reduce((buf, line) => {
263
+ const hardWrap = hardWrapNext
264
+ if (hardWrap) buf = buf.slice(0, -2) + ' \n'
265
+ if (!line && !(hardWrapNext = false)) return buf
266
+ if (line[line.length - 1] === ' \\' ) line = line.replace(/\\ +$/, (m) => m.slice(0, m.length / 2))
267
+ hardWrapNext = line.length > 1 && line[line.length - 2] === ' ' && line[line.length - 1] === ' '
268
+ return buf + (hardWrap || line[0] !== ' ' ? line : line.trimStart())
269
+ }, ' ' ) + trailer
270
+ }
230
271
231
272
body = @section_block* remainder
232
273
0 commit comments