markdown

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package mdfile implements reading and writing of Markdown translation files.

Each Markdown file is split into translatable segments:

  • Frontmatter scalar fields (YAML between --- delimiters) are stored as individual segments with keys like "fm:title", "fm:hero.text", "fm:features.0.title".

  • The Markdown body is split on headings (# to ######) and horizontal rules (---, ***, ___) into sections, stored as segments with keys like "sec:0", "sec:1", ...

  • Code blocks (``` ... ```) and HTML blocks are NOT split on and are included verbatim in the section that contains them.

The round-trip serialization reconstructs the original file structure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SyncKeys

func SyncKeys(src, target *File)

SyncKeys ensures target has the same segment keys as src, preserving existing translations and adding empty segments for new keys.

Types

type File

type File struct {
	// contains filtered or unexported fields
}

File represents a parsed Markdown translation file.

func NewTranslationFile

func NewTranslationFile(src *File, _ string) *File

NewTranslationFile creates an empty target File with the same structure as srcFile but all values cleared.

func Parse

func Parse(data []byte) (*File, error)

Parse parses Markdown data into a File.

func ParseFile

func ParseFile(path string) (*File, error)

ParseFile reads and parses a Markdown translation file.

func (*File) Get

func (f *File) Get(key string) (string, bool)

Get returns the current value for the given key.

func (*File) Keys

func (f *File) Keys() []string

Keys returns all segment keys in document order.

func (*File) Marshal

func (f *File) Marshal() ([]byte, error)

Marshal serialises the file back to Markdown.

func (*File) Set

func (f *File) Set(key, value string) bool

Set updates the value for the given key. Returns false if the key is not found.

func (*File) SourceValues

func (f *File) SourceValues() map[string]string

SourceValues returns a map of key → value.

func (*File) Stats

func (f *File) Stats() (int, int, float64)

Stats returns (total, translated, percent).

func (*File) UntranslatedKeys

func (f *File) UntranslatedKeys() []string

UntranslatedKeys returns keys whose value is empty.

func (*File) WriteFile

func (f *File) WriteFile(path string) error

WriteFile serialises the file and writes it to the given path.

type Segment

type Segment struct {
	// Key identifies this segment (e.g. "fm:title", "sec:0").
	Key string
	// Value is the current translated text (empty = untranslated).
	Value string
}

Segment is a single translatable unit extracted from the Markdown file.

Jump to

Keyboard shortcuts

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