Skip to content

Commit

Permalink
Fix join order
Browse files Browse the repository at this point in the history
Closes GH-32.
  • Loading branch information
crossjs committed Jun 23, 2021
1 parent 59112a0 commit ac4bf0e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/index.js
Expand Up @@ -34,7 +34,7 @@ export function toMarkdown(tree, options = {}) {
configure(context, options)

if (context.options.tightDefinitions) {
context.join.unshift(joinDefinition)
configure(context, {join: [joinDefinition]})
}

/** @type {Handle} */
Expand Down
4 changes: 2 additions & 2 deletions lib/util/container-flow.js
Expand Up @@ -36,11 +36,11 @@ export function containerFlow(parent, context) {
* @returns {string}
*/
function between(left, right) {
let index = -1
let index = context.join.length
/** @type {ReturnType<Join>} */
let result

while (++index < context.join.length) {
while (index--) {
result = context.join[index](left, right, parent, context)

if (result === true || result === 1) {
Expand Down
64 changes: 64 additions & 0 deletions test/index.js
Expand Up @@ -2700,6 +2700,70 @@ test('escape', (t) => {
'should support empty `join`, `handlers`, `extensions` in an extension (coverage)'
)


t.equal(
to(
{
"type": "root",
"children": [
{
"type": "list",
"ordered": true,
"start": 1,
"spread": false,
"children": [
{
"type": "listItem",
"spread": true,
"checked": null,
"children": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "foo"
}
]
},
{
"type": "list",
"ordered": false,
"start": null,
"spread": false,
"children": [
{
"type": "listItem",
"spread": false,
"checked": null,
"children": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "bar"
}
]
}
]
}
]
}
]
}
]
}
]
},
{
join: [() => 0],
}
),
'1. foo\n * bar\n',
'should make `join` from options highest priority'
)

t.equal(
to(
{
Expand Down

0 comments on commit ac4bf0e

Please sign in to comment.