mirror of
https://github.com/danog/blackfriday.git
synced 2025-01-22 21:31:20 +01:00
refactoring: newlines as hard breaks changed from HTML option to global markdown option
This commit is contained in:
parent
812e8d0185
commit
f5e3dc8073
22
html.go
22
html.go
@ -387,32 +387,12 @@ func htmlListItem(out *bytes.Buffer, text []byte, flags int, opaque interface{})
|
||||
}
|
||||
|
||||
func htmlParagraph(out *bytes.Buffer, text []byte, opaque interface{}) {
|
||||
options := opaque.(*htmlOptions)
|
||||
|
||||
if out.Len() > 0 {
|
||||
out.WriteByte('\n')
|
||||
}
|
||||
|
||||
out.WriteString("<p>")
|
||||
if options.flags&HTML_HARD_WRAP != 0 {
|
||||
org := 0
|
||||
for i := 0; i < len(text); i++ {
|
||||
if text[i] != '\n' {
|
||||
continue
|
||||
}
|
||||
|
||||
if i > org {
|
||||
out.Write(text[org:i])
|
||||
}
|
||||
org = i
|
||||
|
||||
out.WriteString("<br")
|
||||
out.WriteString(options.closeTag)
|
||||
}
|
||||
out.Write(text[org:])
|
||||
} else {
|
||||
out.Write(text)
|
||||
}
|
||||
out.Write(text)
|
||||
out.WriteString("</p>\n")
|
||||
}
|
||||
|
||||
|
@ -157,9 +157,11 @@ func inlineCodeSpan(out *bytes.Buffer, rndr *render, data []byte, offset int) in
|
||||
|
||||
}
|
||||
|
||||
// '\n' preceded by two spaces
|
||||
// newline preceded by two spaces becomes <br>
|
||||
// newline without two spaces works when EXTENSION_HARD_LINE_BREAK is enabled
|
||||
func inlineLineBreak(out *bytes.Buffer, rndr *render, data []byte, offset int) int {
|
||||
if offset < 2 || data[offset-1] != ' ' || data[offset-2] != ' ' {
|
||||
if rndr.flags&EXTENSION_HARD_LINE_BREAK == 0 &&
|
||||
(offset < 2 || data[offset-1] != ' ' || data[offset-2] != ' ') {
|
||||
return 0
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ const (
|
||||
EXTENSION_STRIKETHROUGH
|
||||
EXTENSION_LAX_HTML_BLOCKS
|
||||
EXTENSION_SPACE_HEADERS
|
||||
EXTENSION_HARD_LINE_BREAK
|
||||
)
|
||||
|
||||
// These are the possible flag values for the link renderer.
|
||||
|
Loading…
x
Reference in New Issue
Block a user