insert

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package insert places formatted entries into context file content at the correct position based on entry type and section headers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AfterHeader

func AfterHeader(content, entry, header string) []byte

AfterHeader finds a header line and inserts content after it.

Skips blank lines and HTML comment blocks (<!-- ... -->) between the header and the insertion point, so new entries land after index tables, format guides, and other comment-wrapped metadata. Falls back to appending at the end if the header is not found.

Parameters:

  • content: Existing file content
  • entry: Formatted entry to insert
  • header: Header line to find (e.g., "# Learnings")

Returns:

  • []byte: Modified content with entry inserted

func AppendAtEnd

func AppendAtEnd(content, entry string) []byte

AppendAtEnd appends an entry at the end of content.

Ensures proper newline separation between existing content and the new entry.

Parameters:

  • content: Existing file content
  • entry: Formatted entry to append

Returns:

  • []byte: Content with entry appended

func AppendEntry

func AppendEntry(
	existing []byte, entry string, fileType string, section string,
) []byte

AppendEntry inserts a formatted entry into existing file content.

For tasks, inserts after the target section header. For decisions and learnings, inserts before existing entries (reverse-chronological order). For conventions, appends to the end of the file.

Parameters:

  • existing: Current file content as bytes
  • entry: Pre-formatted entry text to insert
  • fileType: AppendEntry type (e.g., "task", "decision", "learning", "convention")
  • section: Target section header for tasks; defaults to "## Next Up" if empty; a "## " prefix is added automatically if missing

Returns:

  • []byte: Modified file content with the entry inserted

func Decision

func Decision(content, entry, header string) []byte

Decision inserts a decision entry before existing entries.

Finds the first "## [" marker that is NOT inside an HTML comment block and inserts before it, maintaining reverse-chronological order. Falls back to AfterHeader if no real entries exist yet.

Parameters:

  • content: Existing file content
  • entry: Formatted entry to insert
  • header: Header line to insert after (e.g., "# Decisions")

Returns:

  • []byte: Modified content with entry inserted

func ExistsInsideHTMLComment

func ExistsInsideHTMLComment(content string, idx int) bool

ExistsInsideHTMLComment reports whether the position idx in content falls inside an HTML comment block (<!-- ... -->).

Parameters:

  • content: String to check
  • idx: Position to test

Returns:

  • bool: True if idx is between a <!-- and its closing -->

func Learning

func Learning(content, entry string) []byte

Learning inserts a learning entry before existing entries.

Finds the first "## [" marker that is NOT inside an HTML comment block and inserts before it, maintaining reverse-chronological order. Falls back to AfterHeader if no real entries exist yet.

Parameters:

  • content: Existing file content
  • entry: Formatted entry to insert

Returns:

  • []byte: Modified content with entry inserted

func Task

func Task(entry, existingStr, section string) []byte

Task inserts a task entry into TASKS.md.

When section is explicitly provided, inserts after that section header. When section is empty (default), finds the first unchecked task and inserts before it, so the new task lands among existing pending work. Falls back to appending at the end if neither is found.

Parameters:

  • entry: Formatted task entry to insert
  • existingStr: Existing file content
  • section: Explicit section name, or empty for auto-placement

Returns:

  • []byte: Modified content with task inserted

func TaskAfterSection

func TaskAfterSection(entry, content, section string) []byte

TaskAfterSection inserts a task after a named section header.

Normalizes the section name to a Markdown heading, finds it in the content, and inserts the entry immediately after. Falls back to appending at the end if the header is not found.

Parameters:

  • entry: Formatted task entry to insert
  • content: Existing file content
  • section: Section name (e.g., "Phase 1", "Maintenance")

Returns:

  • []byte: Modified content with task inserted

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL