Skip to content

Apply context-sensitive resolution (CSR) consistently in MarkdownRendering.kt #61

Description

@morisil

Summary

markanywhere-render/src/commonMain/kotlin/MarkdownRendering.kt applies Kotlin context-sensitive resolution (CSR) inconsistently: some when/lambda sites over a BlockFrame subject drop the BlockFrame. prefix (e.g. is Pre, is Code, is Inline, is Frontmatter), while structurally identical sites still use the fully-qualified BlockFrame.X. Per CLAUDE.md ("Inside a when whose subject has a known sealed type … drop the type prefix … CSR also applies to is/as against that type"), these should be consistent. This is a style/readability cleanup, surfaced during review of #57 (which added several of the unqualified forms next to pre-existing qualified ones).

Already unqualified (correct, the target style)

  • blockMarkerEscapingAllowed() — it is Pre || it is Code || it is Frontmatter
  • the blank-text dispatch — it is Pre || it is Code
  • enclosingInlineDelimiterMask / inInlineCode — is Inline, is TaggedInline, is Code
  • the inline-code early-return — inInlineCode() (was blockStack.lastOrNull() is Code)

Still fully-qualified (to normalize)

In MarkdownRendering.kt (line numbers approximate, will drift):

  • buildPrefix when (subject BlockFrame): is BlockFrame.Blockquote, is BlockFrame.List, (next as? BlockFrame.ListItem)
  • spillActiveLinks: frame !is BlockFrame.Link
  • the block-spill guard: blockStack.any { it is BlockFrame.Link && !it.rawMode }
  • tagged Unmark path: frame is BlockFrame.SelfClosed, frame is BlockFrame.TaggedInline
  • list handling: parent is BlockFrame.ListItem, blockStack.lastOrNull() is BlockFrame.ListItem, (blockStack.last() as BlockFrame.ListItem), blockStack.lastOrNull() as? BlockFrame.List, blockStack.lastOrNull() is BlockFrame.Pre
  • the Unmark when (frame.name) casts: frame as BlockFrame.Frontmatter, (frame as BlockFrame.Paragraph).suppressClose, frame as BlockFrame.Inline, frame as BlockFrame.Link
  • "ul"/"ol" close: blockStack.lastOrNull() is BlockFrame.ListItem

Notes / caveats

  • CSR applies to is/as against the sealed type and inside a when whose subject is the sealed type. For a nullable receiver (blockStack.lastOrNull() as? BlockFrame.List) and bare as casts, confirm CSR resolves before mass-replacing — compile each target. CLAUDE.md notes CSR does not apply in some positions (supertype lists, generic constraints, type-annotation positions), so this is a per-site check, not a blind find/replace of BlockFrame..
  • Construction sites (addLast(BlockFrame.Inline(...)), BlockFrame.SelfClosed as a value, etc.) are not CSR positions and must stay qualified.

Scope

Pure refactor, no behavior change; verify by running :markanywhere-render:jvmTest. Kept out of #57 to avoid ballooning that PR's diff with churn in untouched code.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions