[ok]handle tag h1~h6
(doc *goquery.Document)
| 293 | |
| 294 | //[ok]handle tag h1~h6 |
| 295 | func handleHead(doc *goquery.Document) *goquery.Document { |
| 296 | heads := map[string]string{ |
| 297 | "title": "# ", |
| 298 | "h1": "# ", |
| 299 | "h2": "## ", |
| 300 | "h3": "### ", |
| 301 | "h4": "#### ", |
| 302 | "h5": "##### ", |
| 303 | "h6": "###### ", |
| 304 | } |
| 305 | for tag, replace := range heads { |
| 306 | doc.Find(tag).Each(func(i int, selection *goquery.Selection) { |
| 307 | text, _ := selection.Html() |
| 308 | selection.BeforeHtml("\n\r" + replace + text + "\n\r") |
| 309 | selection.Remove() |
| 310 | }) |
| 311 | } |
| 312 | return doc |
| 313 | } |
| 314 | |
| 315 | func handleTag2Tag(doc *goquery.Document) *goquery.Document { |
| 316 | for tag, toTag := range tag2tag { |