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

Method paragraph

block.go:1453–1575  ·  view source on GitHub ↗
(data []byte)

Source from the content-addressed store, hash-verified

1451}
1452
1453func (p *Markdown) paragraph(data []byte) int {
1454 // prev: index of 1st char of previous line
1455 // line: index of 1st char of current line
1456 // i: index of cursor/end of current line
1457 var prev, line, i int
1458 tabSize := TabSizeDefault
1459 if p.extensions&TabSizeEight != 0 {
1460 tabSize = TabSizeDouble
1461 }
1462 // keep going until we find something to mark the end of the paragraph
1463 for i < len(data) {
1464 // mark the beginning of the current line
1465 prev = line
1466 current := data[i:]
1467 line = i
1468
1469 // did we find a reference or a footnote? If so, end a paragraph
1470 // preceding it and report that we have consumed up to the end of that
1471 // reference:
1472 if refEnd := isReference(p, current, tabSize); refEnd > 0 {
1473 p.renderParagraph(data[:i])
1474 return i + refEnd
1475 }
1476
1477 // did we find a blank line marking the end of the paragraph?
1478 if n := p.isEmpty(current); n > 0 {
1479 // did this blank line followed by a definition list item?
1480 if p.extensions&DefinitionLists != 0 {
1481 if i < len(data)-1 && data[i+1] == ':' {
1482 return p.list(data[prev:], ListTypeDefinition)
1483 }
1484 }
1485
1486 p.renderParagraph(data[:i])
1487 return i + n
1488 }
1489
1490 // an underline under some text marks a heading, so our paragraph ended on prev line
1491 if i > 0 {
1492 if level := p.isUnderlinedHeading(current); level > 0 {
1493 // render the paragraph
1494 p.renderParagraph(data[:prev])
1495
1496 // ignore leading and trailing whitespace
1497 eol := i - 1
1498 for prev < eol && data[prev] == ' ' {
1499 prev++
1500 }
1501 for eol > prev && data[eol-1] == ' ' {
1502 eol--
1503 }
1504
1505 id := ""
1506 if p.extensions&AutoHeadingIDs != 0 {
1507 id = SanitizedAnchorName(string(data[prev:eol]))
1508 }
1509
1510 block := p.addBlock(Heading, data[prev:eol])

Callers 1

blockMethod · 0.95

Calls 15

renderParagraphMethod · 0.95
isEmptyMethod · 0.95
listMethod · 0.95
isUnderlinedHeadingMethod · 0.95
addBlockMethod · 0.95
htmlMethod · 0.95
isPrefixHeadingMethod · 0.95
isHRuleMethod · 0.95
fencedCodeBlockMethod · 0.95
dliPrefixMethod · 0.95
uliPrefixMethod · 0.95
oliPrefixMethod · 0.95

Tested by

no test coverage detected