MCPcopy
hub / github.com/russross/blackfriday / RenderNode

Method RenderNode

html.go:508–834  ·  view source on GitHub ↗

RenderNode is a default renderer of a single node of a syntax tree. For block nodes it will be called twice: first time with entering=true, second time with entering=false, so that it could know when it's working on an open tag and when on close. It writes the result to w. The return value is a way

(w io.Writer, node *Node, entering bool)

Source from the content-addressed store, hash-verified

506// The typical behavior is to return GoToNext, which asks for the usual
507// traversal to the next node.
508func (r *HTMLRenderer) RenderNode(w io.Writer, node *Node, entering bool) WalkStatus {
509 attrs := []string{}
510 switch node.Type {
511 case Text:
512 if r.Flags&Smartypants != 0 {
513 var tmp bytes.Buffer
514 escapeHTML(&tmp, node.Literal)
515 r.sr.Process(w, tmp.Bytes())
516 } else {
517 if node.Parent.Type == Link {
518 escLink(w, node.Literal)
519 } else {
520 escapeHTML(w, node.Literal)
521 }
522 }
523 case Softbreak:
524 r.cr(w)
525 // TODO: make it configurable via out(renderer.softbreak)
526 case Hardbreak:
527 if r.Flags&UseXHTML == 0 {
528 r.out(w, brTag)
529 } else {
530 r.out(w, brXHTMLTag)
531 }
532 r.cr(w)
533 case Emph:
534 if entering {
535 r.out(w, emTag)
536 } else {
537 r.out(w, emCloseTag)
538 }
539 case Strong:
540 if entering {
541 r.out(w, strongTag)
542 } else {
543 r.out(w, strongCloseTag)
544 }
545 case Del:
546 if entering {
547 r.out(w, delTag)
548 } else {
549 r.out(w, delCloseTag)
550 }
551 case HTMLSpan:
552 if r.Flags&SkipHTML != 0 {
553 break
554 }
555 r.out(w, node.Literal)
556 case Link:
557 // mark it but don't link it if it is not a safe link: no smartypants
558 dest := node.LinkData.Destination
559 if needSkipLink(r.Flags, dest) {
560 if entering {
561 r.out(w, ttTag)
562 } else {
563 r.out(w, ttCloseTag)
564 }
565 } else {

Callers 1

writeTOCMethod · 0.95

Calls 15

crMethod · 0.95
outMethod · 0.95
addAbsPrefixMethod · 0.95
tagMethod · 0.95
ensureUniqueHeadingIDMethod · 0.95
outHRTagMethod · 0.95
escapeHTMLFunction · 0.85
escLinkFunction · 0.85
needSkipLinkFunction · 0.85
footnoteRefFunction · 0.85
appendLinkAttrsFunction · 0.85
escapeAllHTMLFunction · 0.85

Tested by

no test coverage detected