Skip to content

Commit addbce9

Browse files
committed
add support for attribute value continuation across multiple lines
1 parent 3a982a0 commit addbce9

File tree

43 files changed

+346
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+346
-1
lines changed

grammar/asciidoc-block.pegjs

+42-1
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,51 @@ attribute_entry = ':' negatedPrefix:'!'? name:attribute_name negatedSuffix:'!'?
223223
return [name, negatedPrefix || negatedSuffix ? null : value || '', range()]
224224
}
225225
226+
attribute_entry_head = ':' '!'? attribute_name '!'? ':' (space / eol)
227+
226228
// TODO permit non-ASCII letters in attribute name
227229
attribute_name = $([a-zA-Z0-9_] [a-zA-Z0-9_-]*)
228230
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+
}
230271
231272
body = @section_block* remainder
232273
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "document",
3+
"type": "block",
4+
"header": {
5+
"attributes": {
6+
"bs": { "value": "\\", "location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 6 }] }
7+
},
8+
"location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 6 }]
9+
},
10+
"location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 6 }]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "document",
3+
"type": "block",
4+
"header": {
5+
"attributes": {
6+
"lines": { "value": "foo\nbar\nbaz", "location": [{ "line": 1, "col": 1 }, { "line": 5, "col": 3 }] }
7+
},
8+
"location": [{ "line": 1, "col": 1 }, { "line": 5, "col": 3 }]
9+
},
10+
"location": [{ "line": 1, "col": 1 }, { "line": 5, "col": 3 }]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "document",
3+
"type": "block",
4+
"header": {
5+
"attributes": {
6+
"reproducible": { "value": "", "location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 14 }] }
7+
},
8+
"location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 14 }]
9+
},
10+
"location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 14 }]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"ensureTrailingNewline": true
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "document",
3+
"type": "block",
4+
"header": {
5+
"attributes": {
6+
"reproducible": { "value": "", "location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 16 }] }
7+
},
8+
"location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 16 }]
9+
},
10+
"location": [{ "line": 1, "col": 1 }, { "line": 2, "col": 0 }]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "document",
3+
"type": "block",
4+
"header": {
5+
"attributes": {
6+
"reproducible": { "value": "", "location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 16 }] }
7+
},
8+
"location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 16 }]
9+
},
10+
"location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 16 }]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "document",
3+
"type": "block",
4+
"header": {
5+
"attributes": {
6+
"drive": { "value": "C:\\", "location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 12 }] }
7+
},
8+
"location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 12 }]
9+
},
10+
"location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 12 }]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "document",
3+
"type": "block",
4+
"header": {
5+
"attributes": {
6+
"dbs": { "value": "\\\\", "location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 10 }] }
7+
},
8+
"location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 10 }]
9+
},
10+
"location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 10 }]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "document",
3+
"type": "block",
4+
"header": {
5+
"attributes": {
6+
"bars": { "value": "Roses are red, +\nViolets are blue.", "location": [{ "line": 1, "col": 1 }, { "line": 2, "col": 17 }] }
7+
},
8+
"location": [{ "line": 1, "col": 1 }, { "line": 2, "col": 17 }]
9+
},
10+
"location": [{ "line": 1, "col": 1 }, { "line": 2, "col": 17 }]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "document",
3+
"type": "block",
4+
"header": {
5+
"attributes": {
6+
"filetree": { "value": "article.adoc\nassets/\n example.rb\n image.png", "location": [{ "line": 1, "col": 1 }, { "line": 4, "col": 11 }] }
7+
},
8+
"location": [{ "line": 1, "col": 1 }, { "line": 4, "col": 11 }]
9+
},
10+
"location": [{ "line": 1, "col": 1 }, { "line": 4, "col": 11 }]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "document",
3+
"type": "block",
4+
"header": {
5+
"attributes": {
6+
"output": { "value": "499 passing\n1 pending", "location": [{ "line": 1, "col": 1 }, { "line": 2, "col": 9 }] }
7+
},
8+
"location": [{ "line": 1, "col": 1 }, { "line": 2, "col": 9 }]
9+
},
10+
"location": [{ "line": 1, "col": 1 }, { "line": 2, "col": 9 }]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "document",
3+
"type": "block",
4+
"header": {
5+
"attributes": {
6+
"bs": { "value": "\\", "location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 6 }] },
7+
"org": { "value": "ACME", "location": [{ "line": 2, "col": 1 }, { "line": 2, "col": 10 }] }
8+
},
9+
"location": [{ "line": 1, "col": 1 }, { "line": 2, "col": 10 }]
10+
},
11+
"location": [{ "line": 1, "col": 1 }, { "line": 2, "col": 10 }]
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"options": {
3+
"parseInlines": true
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "document",
3+
"type": "block",
4+
"header": {
5+
"attributes": {
6+
"appsdir": { "value": "C:\\Program Files\\", "location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 27 }] }
7+
},
8+
"location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 27 }]
9+
},
10+
"blocks": [
11+
{
12+
"name": "paragraph",
13+
"type": "block",
14+
"inlines": [
15+
{
16+
"name": "text",
17+
"type": "string",
18+
"value": "Look for the installed application in C:\\Program Files\\.",
19+
"location": [{ "line": 3, "col": 1 }, { "line": 3, "col": 48 }]
20+
}
21+
],
22+
"location": [{ "line": 3, "col": 1 }, { "line": 3, "col": 48 }]
23+
}
24+
],
25+
"location": [{ "line": 1, "col": 1 }, { "line": 3, "col": 48 }]
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "document",
3+
"type": "block",
4+
"header": {
5+
"attributes": {
6+
"name": { "value": "value\\", "location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 13 }] }
7+
},
8+
"location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 13 }]
9+
},
10+
"blocks": [
11+
{
12+
"name": "paragraph",
13+
"type": "block",
14+
"inlines": [
15+
{
16+
"name": "text",
17+
"type": "string",
18+
"value": "+",
19+
"location": [{ "line": 2, "col": 1 }, { "line": 2, "col": 1 }]
20+
}
21+
],
22+
"location": [{ "line": 2, "col": 1 }, { "line": 2, "col": 1 }]
23+
}
24+
],
25+
"location": [{ "line": 1, "col": 1 }, { "line": 2, "col": 1 }]
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "document",
3+
"type": "block",
4+
"header": {
5+
"attributes": {
6+
"icons": { "value": "font", "location": [{ "line": 1, "col": 1 }, { "line": 1, "col": 16 }] },
7+
"toc": { "value": "preamble", "location": [{ "line": 2, "col": 1 }, { "line": 2, "col": 20 }] },
8+
"toclevels": { "value": "1", "location": [{ "line": 3, "col": 1 }, { "line": 3, "col": 13 }] }
9+
},
10+
"location": [{ "line": 1, "col": 1 }, { "line": 3, "col": 13 }]
11+
},
12+
"location": [{ "line": 1, "col": 1 }, { "line": 3, "col": 13 }]
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "document",
3+
"type": "block",
4+
"header": {
5+
"attributes": {
6+
"lml": { "value": "lightweight markup language", "location": [{ "line": 1, "col": 1 }, { "line": 3, "col": 8 }] }
7+
},
8+
"location": [{ "line": 1, "col": 1 }, { "line": 3, "col": 8 }]
9+
},
10+
"location": [{ "line": 1, "col": 1 }, { "line": 3, "col": 8 }]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "document",
3+
"type": "block",
4+
"header": {
5+
"attributes": {
6+
"description": { "value": "This is the description. It summaries the contents of this article.", "location": [{ "line": 1, "col": 1 }, { "line": 2, "col": 56 }] }
7+
},
8+
"location": [{ "line": 1, "col": 1 }, { "line": 2, "col": 56 }]
9+
},
10+
"location": [{ "line": 1, "col": 1 }, { "line": 2, "col": 56 }]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "document",
3+
"type": "block",
4+
"header": {
5+
"attributes": {
6+
"ad": { "value": "AsciiDoc", "location": [{ "line": 1, "col": 1 }, { "line": 2, "col": 3 }] }
7+
},
8+
"location": [{ "line": 1, "col": 1 }, { "line": 2, "col": 3 }]
9+
},
10+
"location": [{ "line": 1, "col": 1 }, { "line": 2, "col": 3 }]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "document",
3+
"type": "block",
4+
"header": {
5+
"attributes": {
6+
"dir": { "value": "C:\\Program Files\\Application", "location": [{ "line": 1, "col": 1 }, { "line": 3, "col": 11 }] }
7+
},
8+
"location": [{ "line": 1, "col": 1 }, { "line": 3, "col": 11 }]
9+
},
10+
"location": [{ "line": 1, "col": 1 }, { "line": 3, "col": 11 }]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "document",
3+
"type": "block",
4+
"header": {
5+
"attributes": {
6+
"source": { "value": "\npreceded by newline", "location": [{ "line": 1, "col": 1 }, { "line": 2, "col": 19 }] }
7+
},
8+
"location": [{ "line": 1, "col": 1 }, { "line": 2, "col": 19 }]
9+
},
10+
"location": [{ "line": 1, "col": 1 }, { "line": 2, "col": 19 }]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "document",
3+
"type": "block",
4+
"header": {
5+
"attributes": {
6+
"description": { "value": "Describe me.", "location": [{ "line": 1, "col": 1 }, { "line": 2, "col": 12 }] }
7+
},
8+
"location": [{ "line": 1, "col": 1 }, { "line": 2, "col": 12 }]
9+
},
10+
"location": [{ "line": 1, "col": 1 }, { "line": 2, "col": 12 }]
11+
}

0 commit comments

Comments
 (0)