Skip to content

Commit

Permalink
Fix end point of texts ending in character reference
Browse files Browse the repository at this point in the history
Closes GH-38.
  • Loading branch information
wooorm committed May 27, 2024
1 parent 1120df9 commit 4aa8425
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
14 changes: 12 additions & 2 deletions dev/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ function compiler(options) {
characterReferenceMarkerHexadecimal: onexitcharacterreferencemarker,
characterReferenceMarkerNumeric: onexitcharacterreferencemarker,
characterReferenceValue: onexitcharacterreferencevalue,
characterReference: onexitcharacterreference,
codeFenced: closer(onexitcodefenced),
codeFencedFence: onexitcodefencedfence,
codeFencedFenceInfo: onexitcodefencedfenceinfo,
Expand Down Expand Up @@ -1201,11 +1202,20 @@ function compiler(options) {
value = result
}

const tail = this.stack.pop()
const tail = this.stack[this.stack.length - 1]
assert(tail, 'expected `node`')
assert(tail.position, 'expected `node.position`')
assert('value' in tail, 'expected `node.value`')
tail.value += value
}

/**
* @this {CompileContext}
* @type {Handle}
*/
function onexitcharacterreference(token) {
const tail = this.stack.pop()
assert(tail, 'expected `node`')
assert(tail.position, 'expected `node.position`')
tail.position.end = point(token.end)
}

Expand Down
22 changes: 11 additions & 11 deletions test/fixtures/link-reference-with-phrasing.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"offset": 7
}
},
"identifier": "`f`",
"label": "`f`",
"identifier": "`f`",
"referenceType": "collapsed"
},
{
Expand Down Expand Up @@ -70,8 +70,8 @@
},
"end": {
"line": 2,
"column": 7,
"offset": 14
"column": 8,
"offset": 15
}
}
}
Expand All @@ -88,8 +88,8 @@
"offset": 18
}
},
"identifier": ";",
"label": ";",
"identifier": ";",
"referenceType": "collapsed"
},
{
Expand Down Expand Up @@ -140,8 +140,8 @@
"offset": 25
}
},
"identifier": "\\;",
"label": ";",
"identifier": "\\;",
"referenceType": "collapsed"
},
{
Expand Down Expand Up @@ -192,8 +192,8 @@
"offset": 31
}
},
"identifier": ";",
"label": ";",
"identifier": ";",
"referenceType": "collapsed"
},
{
Expand Down Expand Up @@ -242,8 +242,8 @@
},
"end": {
"line": 5,
"column": 10,
"offset": 41
"column": 11,
"offset": 42
}
}
}
Expand All @@ -260,8 +260,8 @@
"offset": 45
}
},
"identifier": "`f`;",
"label": "`f`;",
"identifier": "`f`;",
"referenceType": "collapsed"
},
{
Expand Down Expand Up @@ -328,8 +328,8 @@
"offset": 55
}
},
"identifier": "`f`\\;",
"label": "`f`;",
"identifier": "`f`\\;",
"referenceType": "collapsed"
},
{
Expand Down Expand Up @@ -396,8 +396,8 @@
"offset": 64
}
},
"identifier": "`f`;",
"label": "`f`;",
"identifier": "`f`;",
"referenceType": "collapsed"
}
],
Expand Down
5 changes: 5 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import assert from 'node:assert/strict'
import fs from 'node:fs/promises'
import process from 'node:process'
import test from 'node:test'
import {commonmark} from 'commonmark.json'
import {fromHtml} from 'hast-util-from-html'
Expand Down Expand Up @@ -1029,6 +1030,10 @@ test('fixtures', async function (t) {
let expected

try {
if ('UPDATE' in process.env) {
throw new Error('Update')
}

expected = JSON.parse(String(await fs.readFile(fp)))
} catch {
// New fixture.
Expand Down

0 comments on commit 4aa8425

Please sign in to comment.