markdown

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2025 License: AGPL-3.0 Imports: 6 Imported by: 0

README

Markdown Package

The markdown package provides Markdown to HTML conversion functionality for the Dracory framework. It uses the Goldmark library to convert Markdown text into clean, valid HTML with support for GitHub Flavored Markdown (GFM).

Features

  • Convert Markdown text to HTML
  • Support for GitHub Flavored Markdown (GFM)
  • Automatic heading IDs
  • XHTML output
  • Hard line breaks
  • Proper error handling
  • Empty input handling

Installation

go get github.com/dracory/base/markdown

Usage

package main

import (
    "fmt"
    "github.com/dracory/base/markdown"
)

func main() {
    // Example Markdown text
    markdownText := `# Hello World
    
This is a **bold** text and this is *italic*.
    
- List item 1
- List item 2
    
[Link](https://example.com)`

    // Convert Markdown to HTML
    html, err := markdown.MarkdownToHtml(markdownText)
    if err != nil {
        fmt.Printf("Error converting markdown: %v\n", err)
        return
    }

    fmt.Println(html)
}

Configuration

The package uses Goldmark with the following default configuration:

  • GitHub Flavored Markdown (GFM) extension enabled
  • Automatic heading IDs
  • XHTML output
  • Unsafe HTML (allows raw HTML in markdown)
  • Hard line breaks

Error Handling

The MarkdownToHtml function returns an error if:

  • The markdown conversion fails
  • The input text cannot be processed

Empty or whitespace-only input is handled gracefully and returns an empty string without error.

Dependencies

License

This package is part of the dracory/base project and is licensed under the same terms. See the main README.md for license information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarkdownToHtml

func MarkdownToHtml(text string) (string, error)

ToHtml converts a markdown text to html

1. the text is trimmed of any white spaces 2. if the text is empty, it returns an empty string 3. the text is converted to html using the goldmark library

Types

This section is empty.

Jump to

Keyboard shortcuts

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