doc.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. Package html implements HTML renderer of parsed markdown document.
  3. Configuring and customizing a renderer
  4. A renderer can be configured with multiple options:
  5. import "github.com/gomarkdown/markdown/html"
  6. flags := html.CommonFlags | html.CompletePage | html.HrefTargetBlank
  7. opts := html.RendererOptions{
  8. Title: "A custom title",
  9. Flags: flags,
  10. }
  11. renderer := html.NewRenderer(opts)
  12. You can also re-use most of the logic and customize rendering of selected nodes
  13. by providing node render hook.
  14. This is most useful for rendering nodes that allow for design choices, like
  15. links or code blocks.
  16. import (
  17. "github.com/gomarkdown/markdown/html"
  18. "github.com/gomarkdown/markdown/ast"
  19. )
  20. // a very dummy render hook that will output "code_replacements" instead of
  21. // <code>${content}</code> emitted by html.Renderer
  22. func renderHookCodeBlock(w io.Writer, node ast.Node, entering bool) (ast.WalkStatus, bool) {
  23. _, ok := node.(*ast.CodeBlock)
  24. if !ok {
  25. return ast.GoToNext, false
  26. }
  27. io.WriteString(w, "code_replacement")
  28. return ast.GoToNext, true
  29. }
  30. opts := html.RendererOptions{
  31. RenderNodeHook: renderHookCodeBlock,
  32. }
  33. renderer := html.NewRenderer(opts)
  34. */
  35. package html