Skip to content

Commit 4aa8425

Browse files
committed
Fix end point of texts ending in character reference
Closes GH-38.
1 parent 1120df9 commit 4aa8425

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

dev/lib/index.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ function compiler(options) {
247247
characterReferenceMarkerHexadecimal: onexitcharacterreferencemarker,
248248
characterReferenceMarkerNumeric: onexitcharacterreferencemarker,
249249
characterReferenceValue: onexitcharacterreferencevalue,
250+
characterReference: onexitcharacterreference,
250251
codeFenced: closer(onexitcodefenced),
251252
codeFencedFence: onexitcodefencedfence,
252253
codeFencedFenceInfo: onexitcodefencedfenceinfo,
@@ -1201,11 +1202,20 @@ function compiler(options) {
12011202
value = result
12021203
}
12031204

1204-
const tail = this.stack.pop()
1205+
const tail = this.stack[this.stack.length - 1]
12051206
assert(tail, 'expected `node`')
1206-
assert(tail.position, 'expected `node.position`')
12071207
assert('value' in tail, 'expected `node.value`')
12081208
tail.value += value
1209+
}
1210+
1211+
/**
1212+
* @this {CompileContext}
1213+
* @type {Handle}
1214+
*/
1215+
function onexitcharacterreference(token) {
1216+
const tail = this.stack.pop()
1217+
assert(tail, 'expected `node`')
1218+
assert(tail.position, 'expected `node.position`')
12091219
tail.position.end = point(token.end)
12101220
}
12111221

test/fixtures/link-reference-with-phrasing.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
"offset": 7
3737
}
3838
},
39-
"identifier": "`f`",
4039
"label": "`f`",
40+
"identifier": "`f`",
4141
"referenceType": "collapsed"
4242
},
4343
{
@@ -70,8 +70,8 @@
7070
},
7171
"end": {
7272
"line": 2,
73-
"column": 7,
74-
"offset": 14
73+
"column": 8,
74+
"offset": 15
7575
}
7676
}
7777
}
@@ -88,8 +88,8 @@
8888
"offset": 18
8989
}
9090
},
91-
"identifier": ";",
9291
"label": ";",
92+
"identifier": ";",
9393
"referenceType": "collapsed"
9494
},
9595
{
@@ -140,8 +140,8 @@
140140
"offset": 25
141141
}
142142
},
143-
"identifier": "\\;",
144143
"label": ";",
144+
"identifier": "\\;",
145145
"referenceType": "collapsed"
146146
},
147147
{
@@ -192,8 +192,8 @@
192192
"offset": 31
193193
}
194194
},
195-
"identifier": ";",
196195
"label": ";",
196+
"identifier": ";",
197197
"referenceType": "collapsed"
198198
},
199199
{
@@ -242,8 +242,8 @@
242242
},
243243
"end": {
244244
"line": 5,
245-
"column": 10,
246-
"offset": 41
245+
"column": 11,
246+
"offset": 42
247247
}
248248
}
249249
}
@@ -260,8 +260,8 @@
260260
"offset": 45
261261
}
262262
},
263-
"identifier": "`f`;",
264263
"label": "`f`;",
264+
"identifier": "`f`;",
265265
"referenceType": "collapsed"
266266
},
267267
{
@@ -328,8 +328,8 @@
328328
"offset": 55
329329
}
330330
},
331-
"identifier": "`f`\\;",
332331
"label": "`f`;",
332+
"identifier": "`f`\\;",
333333
"referenceType": "collapsed"
334334
},
335335
{
@@ -396,8 +396,8 @@
396396
"offset": 64
397397
}
398398
},
399-
"identifier": "`f`;",
400399
"label": "`f`;",
400+
"identifier": "`f`;",
401401
"referenceType": "collapsed"
402402
}
403403
],

test/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import assert from 'node:assert/strict'
66
import fs from 'node:fs/promises'
7+
import process from 'node:process'
78
import test from 'node:test'
89
import {commonmark} from 'commonmark.json'
910
import {fromHtml} from 'hast-util-from-html'
@@ -1029,6 +1030,10 @@ test('fixtures', async function (t) {
10291030
let expected
10301031

10311032
try {
1033+
if ('UPDATE' in process.env) {
1034+
throw new Error('Update')
1035+
}
1036+
10321037
expected = JSON.parse(String(await fs.readFile(fp)))
10331038
} catch {
10341039
// New fixture.

0 commit comments

Comments
 (0)