mdgo

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2025 License: MIT Imports: 5 Imported by: 2

README

mdgo

Project Badges

Manipulating Markdown files with Go code.

Usage example:

import (
	"embed"
	"github.com/cdvelop/mdgo"
)

// create handler with project root
m := mdgo.New("/project/root", "deploy")

// provide input as a path relative to root
m.InputPath("templates/server.md")

// extract into a Go file (extension decides code type)
if err := m.Extract("main.go"); err != nil {
	// handle error
}

You can also provide input as bytes (InputByte) or from an embed.FS (InputEmbed).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mdgo

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

func New

func New(rootDir, destination string) *Mdgo

New creates a new Mdgo instance with the root directory. Destination (output directory) and input must be set via methods.

func (*Mdgo) Extract

func (m *Mdgo) Extract(outputFile string) error

Extract extracts code blocks from the configured input and writes to outputFile The output file extension determines which code type to extract (.go, .js, .css)

func (*Mdgo) InputByte

func (m *Mdgo) InputByte(content []byte) *Mdgo

InputByte sets the input as a byte slice (markdown content)

func (*Mdgo) InputEmbed

func (m *Mdgo) InputEmbed(r ReaderFile, path string) *Mdgo

InputEmbed sets the input as any ReaderFile implementation and a relative path inside it

func (*Mdgo) InputPath

func (m *Mdgo) InputPath(pathFile string) *Mdgo

InputPath sets the input as a file path (relative to rootDir)

func (*Mdgo) SetLogger

func (m *Mdgo) SetLogger(logger func(...any)) *Mdgo

SetLogger sets a custom logger function

type ReaderFile

type ReaderFile interface {
	ReadFile(name string) ([]byte, error)
}

ReaderFile abstracts a file reader (e.g. embed.FS or any custom provider)

Jump to

Keyboard shortcuts

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