markdown

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package markdown 提供 Markdown 转 HTML 工具。

主要功能:

  • 将 Markdown 文本转换为 HTML
  • 支持代码高亮
  • 自定义渲染钩子
  • 链接在新标签页打开

使用场景:

  • 博客文章渲染
  • 评论系统
  • 文档生成
  • 富文本编辑器

基本用法:

import "github.com/L8CHAT/l8chat-util/markdown"

// Markdown 转 HTML markdownText := ` # 标题

这是一段文本。

` + "```go" + `

func main() {
   fmt.Println("Hello, World!")
}

` + "```" + ` `

html := markdown.ToHtml(markdownText) fmt.Println(html)

特性:

  • 代码块自动高亮(使用 syntaxhighlight)
  • 链接自动添加 target="_blank"
  • 支持 GitHub Flavored Markdown
  • 自定义 CSS 类名

依赖:

  • github.com/gomarkdown/markdown
  • github.com/sourcegraph/syntaxhighlight

注意事项:

  • 代码高亮使用特定的 CSS 类名(pl-en, pl-k, pl-s1, pl-c)
  • 需要配合相应的 CSS 样式使用
  • 空字符串输入返回空字符串

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToHtml

func ToHtml(v string) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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