converter

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package converter provides functionality to convert Notion pages and blocks to Markdown format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeID

func NormalizeID(id string) string

NormalizeID removes dashes from Notion IDs for consistent format.

func SanitizeFilename

func SanitizeFilename(name string) string

SanitizeFilename makes a string safe for use as a filename. Only allows pattern [a-z][a-z0-9-]* (lowercase letters, numbers, hyphens). Must start with a letter.

Types

type ConvertOptions

type ConvertOptions struct {
	Folder           string        // Folder name for this page
	PageTitle        string        // Page title (used for child page link paths)
	FilePath         string        // File path (stored in frontmatter)
	LastSynced       time.Time     // When we synced this page
	NotionType       string        // Type: "page" or "database"
	IsRoot           bool          // Whether this is a root page
	ParentID         string        // Resolved parent page/database ID (empty for root pages)
	FileProcessor    FileProcessor // Optional callback to process file URLs
	SimplifiedDepth  int           // Depth limit used if page was depth-limited (0 if not limited)
	DownloadDuration time.Duration // Time to download page from Notion API
}

ConvertOptions contains additional metadata for conversion.

type Converter

type Converter struct {
	// IncludeFrontmatter controls whether to include YAML frontmatter.
	IncludeFrontmatter bool
}

Converter converts Notion pages and blocks to Markdown.

func NewConverter

func NewConverter() *Converter

NewConverter creates a new converter with default settings.

func (*Converter) Convert

func (c *Converter) Convert(page *notion.Page, blocks []notion.Block) []byte

Convert converts a page and its blocks to Markdown.

func (*Converter) ConvertDatabase

func (c *Converter) ConvertDatabase(
	database *notion.Database, dbPages []notion.DatabasePage, opts *ConvertOptions,
) []byte

ConvertDatabase converts a database to Markdown with a list of direct child pages.

func (*Converter) ConvertWithOptions

func (c *Converter) ConvertWithOptions(page *notion.Page, blocks []notion.Block, opts *ConvertOptions) []byte

ConvertWithOptions converts a page and its blocks to Markdown with additional options.

type FileProcessor

type FileProcessor func(fileURL string) string

FileProcessor processes a file URL and returns the local path. If the file should be downloaded, it downloads it and returns the local path. If nil, files are not processed and URLs are used as-is.

Jump to

Keyboard shortcuts

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