convert html to markdown 将html转成markdown
(htmlstr string)
| 35 | //convert html to markdown |
| 36 | //将html转成markdown |
| 37 | func 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 |
| 56 | func depress(md string, maps map[string]string) string { |