Skip to content

Commit ac4bf0e

Browse files
author
李文富
authored
Fix join order
Closes GH-32.
1 parent 59112a0 commit ac4bf0e

File tree

3 files changed

+67
-3
lines changed

3 files changed

+67
-3
lines changed

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function toMarkdown(tree, options = {}) {
3434
configure(context, options)
3535

3636
if (context.options.tightDefinitions) {
37-
context.join.unshift(joinDefinition)
37+
configure(context, {join: [joinDefinition]})
3838
}
3939

4040
/** @type {Handle} */

lib/util/container-flow.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ export function containerFlow(parent, context) {
3636
* @returns {string}
3737
*/
3838
function between(left, right) {
39-
let index = -1
39+
let index = context.join.length
4040
/** @type {ReturnType<Join>} */
4141
let result
4242

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

4646
if (result === true || result === 1) {

test/index.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2700,6 +2700,70 @@ test('escape', (t) => {
27002700
'should support empty `join`, `handlers`, `extensions` in an extension (coverage)'
27012701
)
27022702

2703+
2704+
t.equal(
2705+
to(
2706+
{
2707+
"type": "root",
2708+
"children": [
2709+
{
2710+
"type": "list",
2711+
"ordered": true,
2712+
"start": 1,
2713+
"spread": false,
2714+
"children": [
2715+
{
2716+
"type": "listItem",
2717+
"spread": true,
2718+
"checked": null,
2719+
"children": [
2720+
{
2721+
"type": "paragraph",
2722+
"children": [
2723+
{
2724+
"type": "text",
2725+
"value": "foo"
2726+
}
2727+
]
2728+
},
2729+
{
2730+
"type": "list",
2731+
"ordered": false,
2732+
"start": null,
2733+
"spread": false,
2734+
"children": [
2735+
{
2736+
"type": "listItem",
2737+
"spread": false,
2738+
"checked": null,
2739+
"children": [
2740+
{
2741+
"type": "paragraph",
2742+
"children": [
2743+
{
2744+
"type": "text",
2745+
"value": "bar"
2746+
}
2747+
]
2748+
}
2749+
]
2750+
}
2751+
]
2752+
}
2753+
]
2754+
}
2755+
]
2756+
}
2757+
]
2758+
},
2759+
{
2760+
join: [() => 0],
2761+
}
2762+
),
2763+
'1. foo\n * bar\n',
2764+
'should make `join` from options highest priority'
2765+
)
2766+
27032767
t.equal(
27042768
to(
27052769
{

0 commit comments

Comments
 (0)