Skip to content

Commit

Permalink
Fix 3 or more pairs
Browse files Browse the repository at this point in the history
Closes GH-11.
Closes GH-12.

Co-authored-by: trueberryless <[email protected]>
  • Loading branch information
wooorm and trueberryless committed Jan 15, 2025
1 parent f22e3b7 commit 8248ab9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default function retextQuotes(options) {
expected = preferred === 'smart' ? '’' : "'"
} else {
const markers = preferred === 'smart' ? smart : straight
expected = markers[(stack.length + 1) % markers.length]
expected = markers[(stack.length - 1) % markers.length]

if (expected.length > 1) {
expected = expected.charAt(style.type === 'open' ? 0 : 1)
Expand Down
8 changes: 8 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ test('retextQuotes', async function (t) {
}
)

await t.test('should detect nesting correctly w/ 3 pairs', async function () {
const file = await retext()
.use(retextQuotes, {smart: ['“”', '‘’', '«»']})
.process('A sentence “with ‘multiple «nested “quotes”»’”.')

assert.deepEqual(file.messages.map(String), [])
})

await t.test('should deal with funky nesting', async function () {
const file = await retext().use(retextQuotes).process(soManyOpenings)

Expand Down

0 comments on commit 8248ab9

Please sign in to comment.