MCPcopy Index your code
hub / github.com/TruthHun/BookStack / Convert

Function Convert

utils/html2md/html2markdown.go:37–53  ·  view source on GitHub ↗

convert html to markdown 将html转成markdown

(htmlstr string)

Source from the content-addressed store, hash-verified

35//convert html to markdown
36//将html转成markdown
37func Convert(htmlstr string) (md string) {
38 var maps map[string]string
39 doc, _ := goquery.NewDocumentFromReader(strings.NewReader(htmlstr))
40 doc = trimAttr(doc)
41 doc, maps = compress(doc)
42 doc = handleNextLine(doc) //<div>...
43 doc = handleBlockTag(doc) //<div>...
44 doc = handleA(doc) //<a>
45 doc = handleImg(doc) //<img>
46 doc = handleHead(doc) //h1~h6
47 doc = handleTag2Tag(doc) //<strong>、<i>、eg..
48 doc = handleHr(doc) //<hr>
49 doc = handleLi(doc) //<li>
50 md, _ = doc.Find("body").Html()
51 md = depress(md, maps)
52 return
53}
54
55// 解压,释放code和pre
56func depress(md string, maps map[string]string) string {

Callers 5

ContentMethod · 0.92
fixFileLinksMethod · 0.92
CrawlHtml2MarkdownFunction · 0.92
Export2MarkdownMethod · 0.92
TestConvertFunction · 0.85

Calls 12

trimAttrFunction · 0.85
compressFunction · 0.85
handleNextLineFunction · 0.85
handleBlockTagFunction · 0.85
handleAFunction · 0.85
handleImgFunction · 0.85
handleHeadFunction · 0.85
handleTag2TagFunction · 0.85
handleHrFunction · 0.85
handleLiFunction · 0.85
depressFunction · 0.85
FindMethod · 0.45

Tested by 1

TestConvertFunction · 0.68