Skip to content

[shared] feat: soft-wrap continuation indent via frontmatter - #381

Open
liukun wants to merge 1 commit into
Shpigford:mainfrom
liukun:soft-wrap-indent
Open

liukun wants to merge 1 commit into
Shpigford:mainfrom
liukun:soft-wrap-indent

Conversation

@liukun

@liukun liukun commented May 31, 2026

Copy link
Copy Markdown

What

Adds two opt-in frontmatter keys that indent soft-wrapped (auto-wrapped) continuation lines while hard line breaks stay flush left:

---
wrapIndent: 2em        # indent for soft-wrapped continuation lines
firstLineIndent: 0     # optional indent for the first line of each paragraph
---

Values accept explicit CSS units (em, ch, px, pt); a bare number defaults to em. The editor resolves them to NSParagraphStyle points and the preview emits them verbatim as CSS, so the editor, WKWebView preview, PDF
export, and QuickLook all render the same indent
.

When neither key is present, nothing changes — the default behavior is completely untouched.

image

Also includes a small editor fix: a leading --- … --- block is now recognized structurally, so a half-typed frontmatter field (e.g. a key before its colon) no longer drops the block's syntax highlighting or the live indent — a pre-existing display glitch, surfaced while testing this feature.

Why

For log / changelog / reference-style notes, a hanging indent makes wrapped lines line up under a leading column (timestamp, key, citation, etc.) and visually distinguishes a soft wrap from a deliberate hard break. Several editors (and a popular Obsidian CSS snippet, --wrap-indent) and Emacs' visual-wrap-extra-indent do exactly this. I wanted it for a specific set of my own documents.

Scope / design notes

I tried to keep this in line with the project's "stay boring" philosophy:

  • No new UI, no settings toggle — config lives only in per-document frontmatter, default off.
  • No new infrastructure — no sidebar, vault, index, or anything like that. It's purely a paragraph-style/CSS tweak.
  • Core logic lives in ClearlyCore (shared), so Mac and iOS behave identically, and the same value feeds preview/PDF/QuickLook.
  • Added unit tests for parsing, unit resolution, and CSS emission; the full ClearlyCore suite is green (swift test --package-path Packages/ClearlyCore).

A note on stance

This scratches a personal itch for specific documents — I completely understand if niche per-document layout knobs aren't a direction you want for Clearly, and it's totally fine if this doesn't get merged. Sharing it in case it's useful.

Either way: thank you for open-sourcing such a clean, genuinely pleasant markdown editor. It's a joy to use, and the codebase was a pleasure to work in.

@liukun
liukun marked this pull request as draft May 31, 2026 14:50
Add wrapIndent/firstLineIndent frontmatter keys that indent soft-wrapped
continuation lines while hard line breaks stay flush. Values accept
explicit CSS units (em/ch/px/pt; a bare number defaults to em); the
editor resolves them to points and the preview emits them verbatim, so
editor, preview, PDF export, and QuickLook stay in sync.

The layout-directive keys are hidden from the preview's rendered
frontmatter block (they're rendering config, not content metadata).

Also hardens the editor's frontmatter syntax highlighting: a leading
'--- ... ---' block is recognized structurally, so a half-typed field
line (e.g. a key without its colon yet) no longer drops the whole
block's highlight or the live indent refresh.
@liukun
liukun force-pushed the soft-wrap-indent branch from e03b969 to 0915770 Compare May 31, 2026 14:51
@liukun
liukun marked this pull request as ready for review May 31, 2026 14:54
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.

1 participant