Documentation
¶
Index ¶
- func FlowToMarkdown(ctx context.Context, n *Node) (string, error)
- func InlineToMarkdown(ctx context.Context, n *Node) (string, error)
- func IsInlineHTML(n *Node) bool
- func ListToMarkdown(ctx context.Context, n *Node) (string, error)
- func RunTestCases(t *testing.T, testCases []TestCase)
- func TableCellToMarkdown(ctx context.Context, n *Node) (string, error)
- func TableRowToMarkdown(ctx context.Context, n *Node) (string, error)
- func TableToMarkdown(ctx context.Context, n *Node) (string, error)
- type AlignType
- type Content
- type DataKey
- type DataTable
- type FlowContent
- type ListContent
- type Node
- func (n *Node) AddFlowChild(child FlowContent)
- func (n *Node) AddListChild(child ListContent)
- func (n *Node) AddPhrasingChild(child PhrasingContent)
- func (n *Node) AddTableChild(child TableContent)
- func (n *Node) GetData(key DataKey) (any, bool)
- func (n *Node) GetType() NodeType
- func (n *Node) IsFlow()
- func (n *Node) IsList()
- func (n *Node) IsPhrasing()
- func (n *Node) IsTable()
- func (n *Node) SetData(key DataKey, value any)
- func (n *Node) ToMarkdown(ctx context.Context) (string, error)
- type NodeType
- type PhrasingContent
- type Point
- type Position
- type ReferenceType
- type TableContent
- type TestCase
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FlowToMarkdown ¶
FlowToMarkdown 将流式内容转换为 Markdown
func InlineToMarkdown ¶
InlineToMarkdown 将内联元素转换为 Markdown
func ListToMarkdown ¶
ListToMarkdown 将列表内容转换为 Markdown
Types ¶
type DataKey ¶
type DataKey string
DataKey 定义 Data 中的键
const ( NDK_Alt DataKey = "alt" NDK_URL DataKey = "url" NDK_Title DataKey = "title" NDK_Identifier DataKey = "identifier" NDK_Label DataKey = "label" NDK_ReferenceType DataKey = "referenceType" NDK_Depth DataKey = "depth" NDK_Lang DataKey = "lang" NDK_Meta DataKey = "meta" NDK_Ordered DataKey = "ordered" NDK_Start DataKey = "start" NDK_Spread DataKey = "spread" NDK_Checked DataKey = "checked" NDK_Align DataKey = "align" )
定义 Data 中的常量
type DataTable ¶
DataTable 定义 Data 类型
func (DataTable) GetAlignType ¶
GetAlignType 从 DataTable 中获取 AlignType 值
func (DataTable) GetReferenceType ¶
func (dt DataTable) GetReferenceType(key DataKey) (ReferenceType, bool)
GetReferenceType 从 DataTable 中获取 ReferenceType 值
type Node ¶
type Node struct {
Type NodeType
Value string
FlowChildren []FlowContent
PhrasingChildren []PhrasingContent
ListChildren []ListContent
TableChildren []TableContent
Data DataTable
// contains filtered or unexported fields
}
Node 结构体现在包含特定类型的子节点字段
func (*Node) AddPhrasingChild ¶
func (n *Node) AddPhrasingChild(child PhrasingContent)
AddPhrasingChild 添加一个短语子节点
func (*Node) AddTableChild ¶
func (n *Node) AddTableChild(child TableContent)
AddTableChild 添加一个表格子节点
func (*Node) ToMarkdown ¶
ToMarkdown 将节点转换为 Markdown 文本
Example (ComplexList) ¶
node := createComplexList()
result, err := node.ToMarkdown(context.Background())
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Print(result)
Output: 1. First item 2. Second item with *emphasis* - Subitem
Example (ComplexStructure) ¶
root := NewNode(NodeRoot)
root.AddFlowChild(createHeadingNode(1, "Complex Example"))
para := NewNode(NodeParagraph)
para.AddPhrasingChild(&Node{Type: NodeText, Value: "This is a "})
para.AddPhrasingChild(&Node{Type: NodeEmphasis, PhrasingChildren: []PhrasingContent{&Node{Type: NodeText, Value: "complex"}}})
para.AddPhrasingChild(&Node{Type: NodeText, Value: " example with "})
para.AddPhrasingChild(&Node{Type: NodeStrong, PhrasingChildren: []PhrasingContent{&Node{Type: NodeText, Value: "nested"}}})
para.AddPhrasingChild(&Node{Type: NodeText, Value: " elements."})
root.AddFlowChild(para)
// 添加调试信息
fmt.Fprintf(os.Stderr, "Root node type: %s\n", root.Type)
fmt.Fprintf(os.Stderr, "Number of children: %d\n", len(root.FlowChildren))
for i, child := range root.FlowChildren {
fmt.Fprintf(os.Stderr, "Child %d type: %s\n", i, child.GetType())
}
markdown, err := root.ToMarkdown(context.Background())
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
return
}
fmt.Print(markdown)
Output: # Complex Example This is a *complex* example with **nested** elements.
Example (Definition) ¶
node := createDefinitionNode("example", "https://example.com", "Example Title")
markdown, err := node.ToMarkdown(context.Background())
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Print(markdown)
Output: [example]: https://example.com "Example Title"
Example (Emphasis) ¶
node := &Node{Type: NodeEmphasis, PhrasingChildren: []PhrasingContent{&Node{Type: NodeText, Value: "emphasized text"}}}
result, err := node.ToMarkdown(context.Background())
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Print(result)
Output: *emphasized text*
Example (Heading) ¶
node := createHeadingNode(2, "Example Heading")
result, err := node.ToMarkdown(context.Background())
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Print(result)
Output: ## Example Heading
Example (ImageReference) ¶
node := createImageReferenceNode("example", "Alt Text", "full")
markdown, err := node.ToMarkdown(context.Background())
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Print(markdown)
Output: ![Alt Text][example]
Example (NestedInline) ¶
node := createNestedInlineNode()
result, err := node.ToMarkdown(context.Background())
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Print(result)
Output: This is *emphasized and **strong** text* with `code`
type NodeType ¶
type NodeType string
NodeType 表示 Markdown AST 节点的类型
const ( NodeRoot NodeType = "root" NodeParagraph NodeType = "paragraph" NodeHeading NodeType = "heading" NodeText NodeType = "text" NodeEmphasis NodeType = "emphasis" NodeStrong NodeType = "strong" NodeDelete NodeType = "delete" NodeLink NodeType = "link" NodeImage NodeType = "image" NodeCode NodeType = "code" NodeInlineCode NodeType = "inlineCode" NodeBlockquote NodeType = "blockquote" NodeList NodeType = "list" NodeListItem NodeType = "listItem" NodeTable NodeType = "table" NodeTableRow NodeType = "tableRow" NodeTableCell NodeType = "tableCell" NodeThematicBreak NodeType = "thematicBreak" NodeBreak NodeType = "break" NodeHTML NodeType = "html" NodeDefinition NodeType = "definition" NodeImageReference NodeType = "imageReference" NodeLinkReference NodeType = "linkReference" NodeFootnote NodeType = "footnote" NodeFootnoteReference NodeType = "footnoteReference" NodeFootnoteDefinition NodeType = "footnoteDefinition" NodeYaml NodeType = "yaml" )
定义所有的节点类型
func (NodeType) IsTableContent ¶
IsTableContent 检查节点是否为表格内容
type PhrasingContent ¶
type PhrasingContent interface {
Content
IsPhrasing()
}
PhrasingContent 接口定义了短语内容节点
type ReferenceType ¶
type ReferenceType string
ReferenceType 表示引用的类型
const ( ReferenceShortcut ReferenceType = "shortcut" ReferenceCollapsed ReferenceType = "collapsed" ReferenceFull ReferenceType = "full" )
Click to show internal directories.
Click to hide internal directories.