MCPcopy Create free account
hub / github.com/Debian/debiman / ToHTML

Method ToHTML

internal/convert/convert.go:407–430  ·  view source on GitHub ↗

TODO(stapelberg): ToHTML’s output currently is used directly as (html/template).HTML, i.e. “known safe HTML document fragment”. We should be more aggressive in whitelisting the allowed tags. resolve, if non-nil, will be called to resolve a reference (like “rm(1)”) into a URL.

(r io.Reader, resolve func(ref string) string)

Source from the content-addressed store, hash-verified

405// resolve, if non-nil, will be called to resolve a reference (like
406// “rm(1)”) into a URL.
407func (p *Process) ToHTML(r io.Reader, resolve func(ref string) string) (doc string, toc []string, err error) {
408 stdout, stderr, err := p.mandoc(r)
409 if stderr != "" {
410 return "", nil, fmt.Errorf("mandoc failed: %v", stderr)
411 }
412 if err != nil {
413 return "", nil, fmt.Errorf("running mandoc failed: %v", err)
414 }
415
416 parsed, err := html.Parse(strings.NewReader(stdout))
417 if err != nil {
418 return "", nil, err
419 }
420
421 err = recurse(parsed, func(n *html.Node) error { return postprocess(resolve, n, &toc) })
422 if err != nil {
423 return "", toc, err
424 }
425 var rendered bytes.Buffer
426 if err := html.Render(&rendered, parsed); err != nil {
427 return "", toc, err
428 }
429 return rendered.String(), toc, nil
430}

Callers 3

TestToHTMLFunction · 0.95
TestReuseFunction · 0.95
convertFileFunction · 0.80

Calls 4

mandocMethod · 0.95
recurseFunction · 0.85
postprocessFunction · 0.85
StringMethod · 0.45

Tested by 2

TestToHTMLFunction · 0.76
TestReuseFunction · 0.76