Index of every page on this site: llms.txt
All skills
github avatar

/markdown-to-html

@f10fdb8 official
by githubgithub/awesome-copilot42k stars
5,426
Run it yourself

Convert Markdown files to HTML similar to `marked.js`, `pandoc`, `gomarkdown/markdown`, or similar tools; or writing custom script to convert markdown to html and/or working on web template systems like `jekyll/jekyll`, `gohugoio/hugo`, or similar web templating systems that utilize markdown documents, converting them to html. Use when asked to "convert markdown to html", "transform md to html", "render markdown", "generate html from markdown", or when working with .md files and/or web a templating system that converts markdown to HTML output. Supports CLI and Node.js workflows with GFM, CommonMark, and standard Markdown flavors.

Use this Skill: https://skilld.dev/gh/github/awesome-copilot/markdown-to-html

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesgomarkdown.md

≈1.6k tokens on demand. Your agent reads this file only when SKILL.md points to it.

gomarkdown/markdown Reference

Go library for parsing Markdown and rendering HTML. Fast, extensible, and thread-safe.

Installation

# Add to your Go project
go get github.com/gomarkdown/markdown

# Install CLI tool
go install github.com/gomarkdown/mdtohtml@latest

Basic Usage

Simple Conversion

package main

import (
    "fmt"
    "github.com/gomarkdown/markdown"
)

func main() {
    md := []byte("# Hello World\n\nThis is **bold** text.")
    html := markdown.ToHTML(md, nil, nil)
    fmt.Println(string(html))
}

Using CLI Tool

# Convert file to HTML
mdtohtml input.md output.html

# Output to stdout
mdtohtml input.md

Parser Configuration

Common Extensions

import (
    "github.com/gomarkdown/markdown"
    "github.com/gomarkdown/markdown/parser"
)

// Create parser with extensions
extensions := parser.CommonExtensions | parser.AutoHeadingIDs
p := parser.NewWithExtensions(extensions)

// Parse markdown
doc := p.Parse(md)

Available Parser Extensions

Extension Description
parser.CommonExtensions Tables, fenced code, autolinks, strikethrough
parser.Tables Pipe tables support
parser.FencedCode Fenced code blocks with language
parser.Autolink Auto-detect URLs
parser.Strikethrough strikethrough text
parser.SpaceHeadings Require space after # in headings
parser.HeadingIDs Custom heading IDs {#id}
parser.AutoHeadingIDs Auto-generate heading IDs
parser.Footnotes Footnote support
parser.NoEmptyLineBeforeBlock No blank line required before blocks
parser.HardLineBreak Newlines become <br>
parser.MathJax MathJax support
parser.SuperSubscript Super^script^ and subscript
parser.Mmark Mmark syntax support

HTML Renderer Configuration

Common Flags

import (
    "github.com/gomarkdown/markdown"
    "github.com/gomarkdown/markdown/html"
    "github.com/gomarkdown/markdown/parser"
)

// Parser
p := parser.NewWithExtensions(parser.CommonExtensions)

// Renderer
htmlFlags := html.CommonFlags | html.HrefTargetBlank
opts := html.RendererOptions{
    Flags: htmlFlags,
    Title: "My Document",
    CSS: "style.css",
}
renderer := html.NewRenderer(opts)

// Convert
html := markdown.ToHTML(md, p, renderer)

Available HTML Flags

Flag Description
html.CommonFlags Common sensible defaults
html.HrefTargetBlank Add target="_blank" to links
html.CompletePage Generate complete HTML document
html.UseXHTML Use XHTML output
html.FootnoteReturnLinks Add return links in footnotes
html.FootnoteNoHRTag No <hr> before footnotes
html.Smartypants Smart punctuation
html.SmartypantsFractions Smart fractions (1/2 → ½)
html.SmartypantsDashes Smart dashes (-- → –)
html.SmartypantsLatexDashes LaTeX-style dashes

Renderer Options

opts := html.RendererOptions{
    Flags:          htmlFlags,
    Title:          "Document Title",
    CSS:            "path/to/style.css",
    Icon:           "favicon.ico",
    Head:           []byte("<meta name='author' content='...'>"),
    RenderNodeHook: customRenderHook,
}

Complete Example

package main

import (
    "os"
    "github.com/gomarkdown/markdown"
    "github.com/gomarkdown/markdown/html"
    "github.com/gomarkdown/markdown/parser"
)

func mdToHTML(md []byte) []byte {
    // Parser with extensions
    extensions := parser.CommonExtensions | 
                  parser.AutoHeadingIDs | 
                  parser.NoEmptyLineBeforeBlock
    p := parser.NewWithExtensions(extensions)
    doc := p.Parse(md)

    // HTML renderer with options
    htmlFlags := html.CommonFlags | html.HrefTargetBlank
    opts := html.RendererOptions{Flags: htmlFlags}
    renderer := html.NewRenderer(opts)

    return markdown.Render(doc, renderer)
}

func main() {
    md, _ := os.ReadFile("input.md")
    html := mdToHTML(md)
    os.WriteFile("output.html", html, 0644)
}

Security: Sanitizing Output

Important: gomarkdown does not sanitize HTML output. Use Bluemonday for untrusted input:

import (
    "github.com/microcosm-cc/bluemonday"
    "github.com/gomarkdown/markdown"
)

// Convert markdown to potentially unsafe HTML
unsafeHTML := markdown.ToHTML(md, nil, nil)

// Sanitize using Bluemonday
p := bluemonday.UGCPolicy()
safeHTML := p.SanitizeBytes(unsafeHTML)

Bluemonday Policies

Policy Description
UGCPolicy() User-generated content (most common)
StrictPolicy() Strip all HTML
StripTagsPolicy() Strip tags, keep text
NewPolicy() Build custom policy

Working with AST

Accessing the AST

import (
    "github.com/gomarkdown/markdown/ast"
    "github.com/gomarkdown/markdown/parser"
)

p := parser.NewWithExtensions(parser.CommonExtensions)
doc := p.Parse(md)

// Walk the AST
ast.WalkFunc(doc, func(node ast.Node, entering bool) ast.WalkStatus {
    if heading, ok := node.(*ast.Heading); ok && entering {
        fmt.Printf("Found heading level %d\n", heading.Level)
    }
    return ast.GoToNext
})

Custom Renderer

type MyRenderer struct {
    *html.Renderer
}

func (r *MyRenderer) RenderNode(w io.Writer, node ast.Node, entering bool) ast.WalkStatus {
    // Custom rendering logic
    if heading, ok := node.(*ast.Heading); ok && entering {
        fmt.Fprintf(w, "<h%d class='custom'>", heading.Level)
        return ast.GoToNext
    }
    return r.Renderer.RenderNode(w, node, entering)
}

Handling Newlines

Windows and Mac newlines need normalization:

// Normalize newlines before parsing
normalized := parser.NormalizeNewlines(input)
html := markdown.ToHTML(normalized, nil, nil)

Resources

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning12d5 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    The skill provides a comprehensive guide for converting Markdown to HTML using industry-standard tools and libraries. It includes appropriate security warnings and detailed remediation steps for handling untrusted input.

  • Socket12d

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

  • Runlayer9mo

    13/16 files flagged

  • ZeroLeaks7mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at f10fdb8. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 4 days ago.

Activeupdated 7 months ago
  • markdown
  • html
  • conversion
  • marked
  • pandoc
  • static-site-generator
  • jekyll
  • hugo
  • gfm

README badge

README badge for github/awesome-copilot/markdown-to-html

Converts Markdown files to HTML using marked.js, pandoc, or custom scripts, with support for GFM, CommonMark, and standard Markdown flavors. Handles single files, batch conversions, code blocks, tables, collapsed sections, and mathematical expressions. Suitable for static site generators like Jekyll and Hugo, or building custom markdown-to-HTML conversion tools.

Generated from the current SKILL.md.

Does this skill support GitHub Flavored Markdown?
Yes. The skill supports GFM, CommonMark, and standard Markdown flavors, with GFM enabled via the `gfm: true` option in marked.js or equivalent settings in pandoc.
What tools does this skill cover?
The skill provides guidance for marked.js (Node.js and CLI), pandoc (command-line tool), and custom conversion scripts. It also references jekyll and hugo for templating systems that convert markdown to HTML.
Does marked.js sanitize HTML output?
No. Marked does not sanitize output HTML. The skill recommends using DOMPurify, sanitize-html, or js-xss to sanitize untrusted markdown before display.
Can this skill handle batch conversions and advanced features like tables and math expressions?
Yes. The skill covers single and batch file conversions, tables with alignment, code blocks with language tags, collapsed sections (details/summary), and mathematical expressions with MathML rendering.
Does pandoc require additional software for PDF output?
Yes. Pandoc requires a LaTeX installation (MacTeX on macOS, MiKTeX on Windows, texlive on Linux) to generate PDF output from markdown.

Generated from the current SKILL.md. These answers refresh after source changes.