File: handle_render.go

package info (click to toggle)
golang-github-johanneskaufmann-html-to-markdown 2.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,080 kB
  • sloc: makefile: 3
file content (47 lines) | stat: -rw-r--r-- 998 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package commonmark

import (
	"github.com/JohannesKaufmann/dom"
	"github.com/JohannesKaufmann/html-to-markdown/v2/converter"
	"golang.org/x/net/html"
)

func (c *commonmark) handleRender(ctx converter.Context, w converter.Writer, n *html.Node) converter.RenderStatus {
	name := dom.NodeName(n)

	switch name {
	case "strong", "b",
		"em", "i":
		return c.renderBoldItalic(ctx, w, n)
	case "hr":
		return c.renderDivider(ctx, w, n)
	case "br":
		return c.renderBreak(ctx, w, n)
	case "ul", "ol":
		return c.renderListContainer(ctx, w, n)

	case "pre":
		return c.renderBlockCode(ctx, w, n)
	case "code",
		"var", "samp", "kbd", "tt":
		return c.renderInlineCode(ctx, w, n)

	case "blockquote":
		return c.renderBlockquote(ctx, w, n)

	case "h1", "h2", "h3", "h4", "h5", "h6":
		return c.renderHeading(ctx, w, n)

	case "img":
		return c.renderImage(ctx, w, n)

	case "a":
		return c.renderLink(ctx, w, n)

	case "#comment":
		return c.renderComment(ctx, w, n)
	}

	return converter.RenderTryNext

}