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.

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