docsmarkdown

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const SoftLineBreak = "\v"

SoftLineBreak is the Google Docs InsertText character for a line break inside the current paragraph. Live Docs API readback returns it inside the same textRun, which lets fenced code blocks keep one shaded paragraph.

Variables

This section is empty.

Functions

func HasTableCellBreaks

func HasTableCellBreaks(markdown string) bool

HasTableCellBreaks reports whether a Markdown table contains HTML line breaks.

func HeadingNormalizedText

func HeadingNormalizedText(text string) string

HeadingNormalizedText collapses heading whitespace for stable matching.

func IsHeadingElement

func IsHeadingElement(t MarkdownElementType) bool

IsHeadingElement reports whether an element is a heading.

func IsTableSeparator

func IsTableSeparator(line string) bool

IsTableSeparator checks if a line is a markdown table separator (|---|---|).

func NormalizeTablesForDriveImport

func NormalizeTablesForDriveImport(markdown string) string

NormalizeTablesForDriveImport ensures Drive conversion receives non-empty table headers.

func ParseTableRow

func ParseTableRow(line string) []string

ParseTableRow parses a single table row into cells.

func StripElementHeadingAnchors

func StripElementHeadingAnchors(elements []MarkdownElement)

StripElementHeadingAnchors removes explicit anchors from parsed heading content.

func StripHeadingAnchors

func StripHeadingAnchors(markdown string) string

StripHeadingAnchors removes explicit heading anchors outside code fences.

Types

type ExplicitHeadingAnchor

type ExplicitHeadingAnchor struct {
	Anchor     string
	Text       string
	Occurrence int
}

ExplicitHeadingAnchor identifies one source heading and its explicit anchor.

func ExplicitHeadingAnchors

func ExplicitHeadingAnchors(markdown string) []ExplicitHeadingAnchor

ExplicitHeadingAnchors returns explicit anchors from parsed Markdown headings.

func ImportExplicitHeadingAnchors

func ImportExplicitHeadingAnchors(markdown string) []ExplicitHeadingAnchor

ImportExplicitHeadingAnchors returns anchors in Drive import heading order.

type MarkdownElement

type MarkdownElement struct {
	Type       MarkdownElementType
	Content    string
	Anchor     string // for headings: explicit Pandoc-style {#id}
	Children   []MarkdownElement
	URL        string     // for links
	Level      int        // for headings and lists
	TableCells [][]string // for tables: rows of cells
}

MarkdownElement represents a parsed markdown element

func ParseMarkdown

func ParseMarkdown(text string) []MarkdownElement

ParseMarkdown parses markdown text into structured elements

type MarkdownElementType

type MarkdownElementType int

MarkdownElementType represents the type of markdown element

const (
	MDText MarkdownElementType = iota
	MDHeading1
	MDHeading2
	MDHeading3
	MDHeading4
	MDHeading5
	MDHeading6
	MDBold
	MDItalic
	MDBoldItalic
	MDCode
	MDCodeBlock
	MDLink
	MDImage
	MDListItem
	MDNumberedList
	MDBlockquote
	MDHorizontalRule
	MDParagraph
	MDEmptyLine
	MDTable
)

type TableData

type TableData struct {
	StartIndex int64
	Cells      [][]string
}

TableData represents a table to be inserted natively

func MarkdownToDocsRequests

func MarkdownToDocsRequests(elements []MarkdownElement, baseIndex int64, tabID string) ([]*docs.Request, string, []TableData)

MarkdownToDocsRequests converts parsed markdown elements to Google Docs batch update requests. baseIndex is the insertion location in the document. Returns: requests, plainText, tableData (for native table insertion)

type TextStyle

type TextStyle struct {
	Bold          bool
	Italic        bool
	Strikethrough bool
	Code          bool
	Link          string
	Start         int64
	End           int64
}

TextStyle represents text formatting

func ParseInlineFormatting

func ParseInlineFormatting(text string) ([]TextStyle, string)

ParseInlineFormatting parses inline markdown formatting within text Returns styles with indices relative to the stripped plain text (UTF-16 code units)

Jump to

Keyboard shortcuts

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