Skip to content

feat: add smart left indent RFC8792 folding#282

Open
panva wants to merge 6 commits into
cabo:masterfrom
panva:extended-include-fold-smart-left
Open

feat: add smart left indent RFC8792 folding#282
panva wants to merge 6 commits into
cabo:masterfrom
panva:extended-include-fold-smart-left

Conversation

@panva
Copy link
Copy Markdown
Contributor

@panva panva commented May 14, 2026

Adds a smart indentation variant for automated RFC 8792 folding.

The new smartN fold option can be used in the same position as leftN (they are mutually exclusive), for example:

{::include-fold69hardsmart2dry generated.json}

Unlike leftN, which uses a fixed continuation indentation, smartN computes the continuation indentation from the line being folded:

continuation indent = leading spaces of first folded line + N

This is useful for nested structured data such as JSON, where folded continuation lines should stay visually aligned with the surrounding nesting level.

Since you moved the docs to the wiki I'll leave those to you to update if this gets accepted.


Example input:

{
  "outer": {
    "array": [
      {
        "description": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
        "nested": {
          "token": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
        }
      }
    ]
  }
}

With fold69hardsmart2dry:

NOTE: '\' line wrapping per RFC 8792

{
  "outer": {
    "array": [
      {
        "description": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
          aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
          aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
        "nested": {
          "token": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
            bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
            bbbbbbbbbbbbbbbb"
        }
      }
    ]
  }
}

Copy link
Copy Markdown
Owner

@cabo cabo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Sorry for nitpicking on the code.

Comment thread lib/kramdown-rfc/command.rb
Comment thread lib/kramdown-rfc/rfc8792.rb Outdated
Comment thread lib/kramdown-rfc/rfc8792.rb Outdated
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
@panva
Copy link
Copy Markdown
Contributor Author

panva commented May 14, 2026

Sorry for nitpicking on the code.

No worries, I welcome the direction.

Copy link
Copy Markdown
Owner

@cabo cabo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more thoughts...

Comment thread lib/kramdown-rfc/rfc8792.rb Outdated
rest = li[col..-1]
indent = left || columns - rest.size
if !left && li[-1] == "\\"
indent = left_indent || columns - rest.size
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, makes me wonder whether there should be a smart_right (right-aligned, but not using more of the line to the left than smart indentation).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible in a follow up, and possibly after there's a test suite, this is getting to a point where changes could use a set of vectors to test with.

@panva
Copy link
Copy Markdown
Contributor Author

panva commented May 28, 2026

@cabo is there anything left to do here before merging and getting a release?

@cabo
Copy link
Copy Markdown
Owner

cabo commented May 28, 2026

Apologies for going on vacation before completing this. I think I had two questions in mind:

1 Is "smart" a good term for indentation based positioning?

2 Did we cover all combinations (here: right aligned with a left boundary based on indentation).

@panva
Copy link
Copy Markdown
Contributor Author

panva commented May 28, 2026

1 Is "smart" a good term for indentation based positioning?

Happy to change the name if one comes to mind.

2 Did we cover all combinations (here: right aligned with a left boundary based on indentation).

It covers the use case I have for it. But I cannot foresee use cases or combinations others might have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants