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

@panva panva commented May 14, 2026

Copy link
Copy Markdown
Contributor

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"
        }
      }
    ]
  }
}

@cabo cabo left a comment

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.

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

panva commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

Sorry for nitpicking on the code.

No worries, I welcome the direction.

@cabo cabo left a comment

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.

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

panva commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

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

@cabo

cabo commented May 28, 2026

Copy link
Copy Markdown
Owner

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

panva commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

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.

@cabo

cabo commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Sorry for leaving this really useful addition hanging; will do more kramdown-rfc things again when the IETF 126 submission frenzy is completed later today.

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