Documentation
¶
Overview ¶
Package logseqext provides generic extensions to the logseq-go library. Functions here are candidates for upstreaming into logseq-go once that library is restructured.
This package must remain self-contained: it may only import logseq-go, the Go standard library, and golang.org/x packages. It must never import logseq-doctor internal packages (doing so would also create a cyclic import).
Index ¶
- Constants
- Variables
- func AddSibling(page logseq.Page, newBlock, before *content.Block, after ...*content.Block)
- func AddTask(opts *AddTaskOptions) error
- func BlockContentText(block *content.Block) string
- func BlockProperties(block *content.Block) *content.Properties
- func CleanTaskName(taskContent, marker string) string
- func DateYYYYMMDD(time time.Time) int
- func ExtractBlockRefUUID(block *content.Block) string
- func ExtractBlockRefUUIDs(page logseq.Page) []string
- func ExtractDirectTags(contentText string) []string
- func ExtractFirstLine(taskContent string) string
- func FindBlockByIDProperty(page logseq.Page, uuid string) *content.Block
- func FindBlockByKey(page logseq.Page, parentBlock *content.Block, key string) *content.Block
- func FindBlockContainingText(page logseq.Page, searchText string) *content.Block
- func FindTaskMarkerByKey(page logseq.Page, parentBlock *content.Block, key string) *content.TaskMarker
- func FormatLogseqDate(t time.Time) string
- func JournalDayToTime(journalDay int) time.Time
- func NormalizeTagPrefixes(tags []string)
- func OpenGraphFromPath(path string) *logseq.Graph
- func OpenPage(graph *logseq.Graph, pageTitle string) logseq.Page
- func ParseLogseqDate(dateStr string) (time.Time, error)
- func ParsePriorityFromContent(contentStr string) content.PriorityValue
- func ReadJournalTitleFormat(graphPath string) string
- func RemoveEmptyBlocks(save bool, blocks ...*content.Block) bool
- func SetPriority(block *content.Block, priority content.PriorityValue) error
- func SetTaskCanceled(block *content.Block) error
- func UniqueStrings(items []string) []string
- type AddTaskOptions
- type LogseqFinder
- type SectionedUUID
Constants ¶
const JournalDayDivisorMonth = 100
JournalDayDivisorMonth is used to extract the month from a journalDay integer (YYYYMMDD).
const JournalDayDivisorYear = 10000
JournalDayDivisorYear is used to extract the year from a journalDay integer (YYYYMMDD).
Variables ¶
var ErrNoParagraph = errors.New("block has no paragraph to insert priority into")
ErrNoParagraph is returned when SetPriority is called on a block with no paragraph.
Functions ¶
func AddSibling ¶
AddSibling inserts newBlock into page relative to the given anchor blocks. It inserts after the last non-nil block in after, or before the before block, or appends to the page if neither is provided.
func AddTask ¶
func AddTask(opts *AddTaskOptions) error
AddTask adds a task to Logseq. If Key is provided, it searches for an existing task containing that key (case-insensitive) and updates it. Otherwise, creates a new task. If Page is provided, adds to that page. Otherwise, adds to journal for Date. If BlockText is provided, adds as a child of the first block containing that text.
func BlockContentText ¶
BlockContentText extracts the text content from a block's content nodes.
func BlockProperties ¶
func BlockProperties(block *content.Block) *content.Properties
BlockProperties returns the Properties node for a task block. logseq-go's block.Properties() only checks the first child — task blocks have a Paragraph first, so it would prepend a new empty Properties node before the TODO line. The parser creates an empty Properties placeholder at position 0; the real properties (id::, collapsed::, etc.) appear after the first Paragraph. This helper finds the first Properties that comes after a Paragraph in the content.
func CleanTaskName ¶
CleanTaskName extracts the task name from content: first line, marker stripped, time prefix stripped.
func DateYYYYMMDD ¶
DateYYYYMMDD returns the current date in YYYYMMDD format.
func ExtractBlockRefUUID ¶
ExtractBlockRefUUID extracts the UUID from a block ref inside a child block.
func ExtractBlockRefUUIDs ¶
ExtractBlockRefUUIDs extracts all block ref UUIDs from a page (ordered).
func ExtractDirectTags ¶
ExtractDirectTags extracts #hashtags and [[page refs]] from content text.
func ExtractFirstLine ¶
ExtractFirstLine extracts the first line of task content, stripping the marker and priority.
func FindBlockByIDProperty ¶
FindBlockByIDProperty finds a block in a page by its id:: property value. It searches Properties nodes within block content because logseq-go's block.Properties() only checks the first child — task blocks have a paragraph first, then properties.
func FindBlockByKey ¶
FindBlockByKey searches for a block containing the specified key (case-insensitive). If parentBlock is provided, searches only among its children. Otherwise, searches in the entire page. Returns the Block if found, nil otherwise.
func FindBlockContainingText ¶
FindBlockContainingText searches for the first block containing the specified text using FindDeep.
func FindTaskMarkerByKey ¶
func FindTaskMarkerByKey(page logseq.Page, parentBlock *content.Block, key string) *content.TaskMarker
FindTaskMarkerByKey searches for a task marker containing the specified key (case-insensitive). If parentBlock is provided, searches only among its children. Otherwise, searches in the entire page. Returns the TaskMarker if found, nil otherwise.
func FormatLogseqDate ¶
FormatLogseqDate formats a time.Time as a Logseq date string: "[[Saturday, 21.03.2026]]".
func JournalDayToTime ¶
JournalDayToTime converts a Logseq journalDay integer (YYYYMMDD) to a time.Time. Returns zero time for zero input.
func NormalizeTagPrefixes ¶
func NormalizeTagPrefixes(tags []string)
NormalizeTagPrefixes ensures all tags start with "#", are lowercase, and slugified (accents removed, non-alphanumeric chars stripped) to match Python's slugify(t, separator=").
func OpenGraphFromPath ¶
OpenGraphFromPath opens a Logseq graph from the given directory path. Aborts the program if path is empty or the graph cannot be opened, to avoid error-handling boilerplate at every call site.
func OpenPage ¶
OpenPage opens a page in the Logseq graph. Aborts the program in case of error to avoid boilerplate at every call site.
func ParseLogseqDate ¶
ParseLogseqDate parses a Logseq date string like "[[Saturday, 21.03.2026]]" into a time.Time. Returns zero time (not error) for empty or unparseable strings.
func ParsePriorityFromContent ¶
func ParsePriorityFromContent(contentStr string) content.PriorityValue
ParsePriorityFromContent extracts a priority value from a Logseq API content string. It looks for [#A], [#B], or [#C] patterns and returns the corresponding PriorityValue. Returns PriorityNone if no priority marker is found.
func ReadJournalTitleFormat ¶
ReadJournalTitleFormat reads the JS-style date format string used for journal page titles from logseq/config.edn (e.g. "EEEE, dd.MM.yyyy"). Returns the Logseq default "EEE do, MMM yyyy" if the file cannot be read or the key is absent. This is a candidate for upstreaming to logseq-go.
func RemoveEmptyBlocks ¶
RemoveEmptyBlocks removes blocks that have no child blocks and returns true if any were removed.
func SetPriority ¶
func SetPriority(block *content.Block, priority content.PriorityValue) error
SetPriority sets or replaces the priority marker ([#A]/[#B]/[#C]) on a block. If a Priority node exists, it is updated in place. Otherwise, a new Priority node is inserted after the TaskMarker (or at the start of the first paragraph for plain blocks).
func SetTaskCanceled ¶
SetTaskCanceled changes the task marker to CANCELED using logseq-go's WithStatus API.
func UniqueStrings ¶
UniqueStrings deduplicates a string slice preserving order.
Types ¶
type AddTaskOptions ¶
type AddTaskOptions struct {
Graph *logseq.Graph
Date time.Time
Page string // Page name to add the task to (empty = journal)
BlockText string // Partial text to search for in parent blocks
Key string // Unique key to search for existing task (case-insensitive)
Name string // Short name of the task
TimeNow func() time.Time // For testing
}
AddTaskOptions contains options for adding a task to Logseq.
type LogseqFinder ¶
LogseqFinder provides methods for searching within a Logseq graph.
func NewLogseqFinder ¶
func NewLogseqFinder(graph *logseq.Graph) LogseqFinder
NewLogseqFinder creates a new LogseqFinder backed by the given graph.
type SectionedUUID ¶
SectionedUUID pairs a block-ref UUID with whether it lives under a section header (ranked=false means it is under Overdue, New tasks, Triaged, Scheduled, or Unranked — any divider that is not the implicit "ranked" area at the top).
func ExtractSectionedBlockRefUUIDs ¶
func ExtractSectionedBlockRefUUIDs(page logseq.Page, unrankedSectionTexts []string) []SectionedUUID
ExtractSectionedBlockRefUUIDs scans a backlog page and returns every block-ref UUID together with whether it is in the ranked area (above all section dividers) or the unranked area (under any divider whose text matches one of unrankedSectionTexts, case-insensitive substring).
The ranked area is defined as top-level blocks that are NOT section-header blocks and NOT descendants of any section-header block.