mdq

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: MIT Imports: 11 Imported by: 0

README

mdq

Quick .md to .html conversion with sensible defaults.

Installation

go get github.com/Phillip-England/mdq

Usage

Convert a single Markdown file
package main

import (
    "fmt"
    "github.com/Phillip-England/mdq"
)

func main() {
    mdFile, err := mdq.NewMdFileFromPath("example.md", "dracula")
    if err != nil {
        panic(err)
    }
    fmt.Println(mdFile.Html)
}

This will:

✅ Read example.md
✅ Convert it to HTML with syntax highlighting (dracula theme)
✅ Prepend meta tags (from the markdown context) to the HTML <head> section


Convert all Markdown files in a directory
package main

import (
    "fmt"
    "github.com/Phillip-England/mdq"
)

func main() {
    mdFiles, err := mdq.NewMdFilesFromDir("./markdowns", "dracula")
    if err != nil {
        panic(err)
    }
    for _, mdFile := range mdFiles {
        fmt.Println(mdFile.Path, mdFile.Html)
    }
}

Access meta configuration in a Markdown file

mdFile.Context is a map[string]any that holds key-value pairs from the frontmatter (meta) of the Markdown file.

Example:

---
title: Hello World
author: Phillip
---

# Welcome

This is a markdown file.

You can access:

fmt.Println(mdFile.Context["title"])  // Hello World
fmt.Println(mdFile.Context["author"]) // Phillip

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MdFile

type MdFile struct {
	Path     string
	Text     string
	Theme    string
	Html     string
	Context  map[string]any
	MetaHtml string
	Name     string
}

func NewMdFileFromPath

func NewMdFileFromPath(path string, theme string) (MdFile, error)

func NewMdFilesFromDir

func NewMdFilesFromDir(path string, theme string) ([]MdFile, error)

Jump to

Keyboard shortcuts

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