@@ -404,21 +404,20 @@ M.indent = function(config, node, state)
404
404
end
405
405
end
406
406
407
- if indent_size == 0 or not with_markers then
408
- local len = indent_size + padding
407
+ if indent_size == 0 then
409
408
local expander = get_expander ()
410
- if level == 0 or not expander then
411
- if marker_start_level == 0 then
412
- len = len + indent_size
413
- end
409
+ local len = 0
410
+ if expander then
411
+ len = indent_size * level - strlen (expander ) - 1
412
+ return {
413
+ text = string.rep (" " , len ) .. expander .. " " ,
414
+ highlight = expander_highlight ,
415
+ }
416
+ else
414
417
return {
415
418
text = string.rep (" " , len ),
416
419
}
417
420
end
418
- return {
419
- text = string.rep (" " , len - strlen (expander ) - 1 ) .. expander .. " " ,
420
- highlight = expander_highlight ,
421
- }
422
421
end
423
422
424
423
local indent_marker = config .indent_marker or " │"
@@ -430,60 +429,47 @@ M.indent = function(config, node, state)
430
429
table.insert (indent , { text = string.rep (" " , padding ) })
431
430
end
432
431
432
+ local root_indent_applied = false
433
+
433
434
for i = 0 , level do
435
+ local char = " "
434
436
local highlight = nil
435
- local char = marker_start_level ~= 0 and " " or " "
436
- local separator = i < marker_start_level and " " or " "
437
- local additional_spaces = string.rep (" " , math.max (0 , indent_size - 2 ))
437
+ local current_indent_size = indent_size
438
+ local expander = get_expander ()
438
439
439
- if marker_start_level ~= 0 then
440
- if i <= 0 then
441
- additional_spaces = " "
442
- end
443
- if level == 0 then
444
- char = " "
445
- separator = " "
446
- additional_spaces = " "
440
+ if i < marker_start_level then
441
+ if i == 0 and not root_indent_applied then
442
+ current_indent_size = 0
443
+ root_indent_applied = true
444
+ else
445
+ current_indent_size = 0
447
446
end
448
447
end
449
448
450
- if indent_size == 1 then
451
- separator = " "
452
- additional_spaces = " "
453
- end
454
-
455
- if marker_start_level >= 2 and i > 0 then
456
- char = " "
457
- separator = " "
458
- end
459
-
460
- if i >= marker_start_level then
461
- highlight = marker_highlight
462
- if i == level then
463
- if node .is_last_child then
449
+ if i == level and expander and level ~= 0 then
450
+ char = expander
451
+ highlight = expander_highlight
452
+ elseif with_markers then
453
+ if i >= marker_start_level then
454
+ char = indent_marker
455
+ if skip_marker [i ] then
456
+ char = " "
457
+ end
458
+ if i == level and node .is_last_child then
464
459
char = last_indent_marker
465
- -- proof of concept for extended markers
466
- -- if indent_size > 2 then
467
- -- separator = "─"
468
- -- end
469
- else
470
- char = indent_marker
471
460
end
472
- elseif not skip_marker [i ] then
473
- char = indent_marker
474
- end
475
- end
476
-
477
- if i == level and i >= 1 then
478
- local expander = get_expander ()
479
- if expander then
480
- char = expander
481
- highlight = expander_highlight
461
+ highlight = marker_highlight
462
+ elseif i < marker_start_level and i == 0 and level > 0 and not root_indent_applied then
463
+ char = " "
464
+ root_indent_applied = true
482
465
end
466
+ elseif not with_markers and not expander then
467
+ char = " "
483
468
end
484
469
470
+ local prefix = string.rep (" " , current_indent_size - strlen (char ))
485
471
table.insert (indent , {
486
- text = char .. separator .. additional_spaces ,
472
+ text = char .. prefix ,
487
473
highlight = highlight ,
488
474
no_next_padding = true ,
489
475
})
0 commit comments