mirror of
https://github.com/russross/blackfriday.git
synced 2024-03-22 13:40:34 +08:00
More lint: markdown.go and ripples to other files
This commit is contained in:
parent
72633fddee
commit
e054c962e7
|
@ -1572,7 +1572,7 @@ func TestCompletePage(t *testing.T) {
|
|||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title></title>
|
||||
<meta name="GENERATOR" content="Blackfriday Markdown Processor v1.4" />
|
||||
<meta name="GENERATOR" content="Blackfriday Markdown Processor v2.0" />
|
||||
<meta charset="utf-8" />
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -54,7 +54,7 @@ func doTests(t *testing.T, tests []string) {
|
|||
doTestsParam(t, tests, TestParams{
|
||||
Options: DefaultOptions,
|
||||
HTMLRendererParameters: HTMLRendererParameters{
|
||||
Flags: CommonHtmlFlags,
|
||||
Flags: CommonHTMLFlags,
|
||||
Extensions: CommonExtensions,
|
||||
},
|
||||
})
|
||||
|
@ -106,7 +106,7 @@ func doLinkTestsInline(t *testing.T, tests []string) {
|
|||
HTMLRendererParameters: params,
|
||||
})
|
||||
doTestsInlineParam(t, transformTests, TestParams{
|
||||
HTMLFlags: CommonHtmlFlags,
|
||||
HTMLFlags: CommonHTMLFlags,
|
||||
HTMLRendererParameters: params,
|
||||
})
|
||||
}
|
||||
|
|
2
html.go
2
html.go
|
@ -727,7 +727,7 @@ func (r *HTMLRenderer) writeDocumentHeader(w *bytes.Buffer, sr *SPRenderer) {
|
|||
}
|
||||
w.WriteString("</title>\n")
|
||||
w.WriteString(" <meta name=\"GENERATOR\" content=\"Blackfriday Markdown Processor v")
|
||||
w.WriteString(VERSION)
|
||||
w.WriteString(Version)
|
||||
w.WriteString("\"")
|
||||
w.WriteString(ending)
|
||||
w.WriteString(">\n")
|
||||
|
|
14
inline.go
14
inline.go
|
@ -285,7 +285,7 @@ func link(p *parser, data []byte, offset int) int {
|
|||
|
||||
var (
|
||||
i = 1
|
||||
noteId int
|
||||
noteID int
|
||||
title, link, altContent []byte
|
||||
textHasNl = false
|
||||
)
|
||||
|
@ -501,7 +501,7 @@ func link(p *parser, data []byte, offset int) int {
|
|||
|
||||
if t == linkInlineFootnote {
|
||||
// create a new reference
|
||||
noteId = len(p.notes) + 1
|
||||
noteID = len(p.notes) + 1
|
||||
|
||||
var fragment []byte
|
||||
if len(id) > 0 {
|
||||
|
@ -512,11 +512,11 @@ func link(p *parser, data []byte, offset int) int {
|
|||
}
|
||||
copy(fragment, slugify(id))
|
||||
} else {
|
||||
fragment = append([]byte("footnote-"), []byte(strconv.Itoa(noteId))...)
|
||||
fragment = append([]byte("footnote-"), []byte(strconv.Itoa(noteID))...)
|
||||
}
|
||||
|
||||
ref := &reference{
|
||||
noteId: noteId,
|
||||
noteID: noteID,
|
||||
hasBlock: false,
|
||||
link: fragment,
|
||||
title: id,
|
||||
|
@ -534,7 +534,7 @@ func link(p *parser, data []byte, offset int) int {
|
|||
}
|
||||
|
||||
if t == linkDeferredFootnote {
|
||||
lr.noteId = len(p.notes) + 1
|
||||
lr.noteID = len(p.notes) + 1
|
||||
p.notes = append(p.notes, lr)
|
||||
}
|
||||
|
||||
|
@ -542,7 +542,7 @@ func link(p *parser, data []byte, offset int) int {
|
|||
link = lr.link
|
||||
// if inline footnote, title == footnote contents
|
||||
title = lr.title
|
||||
noteId = lr.noteId
|
||||
noteID = lr.noteID
|
||||
}
|
||||
|
||||
// rewind the whitespace
|
||||
|
@ -596,7 +596,7 @@ func link(p *parser, data []byte, offset int) int {
|
|||
linkNode := NewNode(Link)
|
||||
linkNode.Destination = link
|
||||
linkNode.Title = title
|
||||
linkNode.NoteID = noteId
|
||||
linkNode.NoteID = noteID
|
||||
p.currBlock.appendChild(linkNode)
|
||||
if t == linkInlineFootnote {
|
||||
i++
|
||||
|
|
2
latex.go
2
latex.go
|
@ -311,7 +311,7 @@ func (r *Latex) DocumentHeader() {
|
|||
r.w.WriteString(" pdfstartview=FitH,%\n")
|
||||
r.w.WriteString(" breaklinks=true,%\n")
|
||||
r.w.WriteString(" pdfauthor={Blackfriday Markdown Processor v")
|
||||
r.w.WriteString(VERSION)
|
||||
r.w.WriteString(Version)
|
||||
r.w.WriteString("}}\n")
|
||||
r.w.WriteString("\n")
|
||||
r.w.WriteString("\\newcommand{\\HRule}{\\rule{\\linewidth}{0.5mm}}\n")
|
||||
|
|
52
markdown.go
52
markdown.go
|
@ -13,7 +13,7 @@
|
|||
//
|
||||
//
|
||||
|
||||
// Blackfriday markdown processor.
|
||||
// Package blackfriday is a markdown processor.
|
||||
//
|
||||
// Translates plain text with simple formatting rules into HTML or LaTeX.
|
||||
package blackfriday
|
||||
|
@ -26,8 +26,11 @@ import (
|
|||
"unicode/utf8"
|
||||
)
|
||||
|
||||
const VERSION = "1.4"
|
||||
// Version string of the package.
|
||||
const Version = "2.0"
|
||||
|
||||
// Extensions is a bitwise or'ed collection of enabled Blackfriday's
|
||||
// extensions.
|
||||
type Extensions int
|
||||
|
||||
// These are the supported markdown parsing extensions.
|
||||
|
@ -58,7 +61,7 @@ const (
|
|||
TOC // Generate a table of contents
|
||||
OmitContents // Skip the main contents (for a standalone table of contents)
|
||||
|
||||
CommonHtmlFlags HTMLFlags = UseXHTML
|
||||
CommonHTMLFlags HTMLFlags = UseXHTML
|
||||
|
||||
CommonExtensions Extensions = NoIntraEmphasis | Tables | FencedCode |
|
||||
Autolink | Strikethrough | SpaceHeaders | HeaderIDs |
|
||||
|
@ -66,10 +69,13 @@ const (
|
|||
SmartypantsFractions | SmartypantsDashes | SmartypantsLatexDashes
|
||||
)
|
||||
|
||||
// DefaultOptions is a convenience variable with all the options that are
|
||||
// enabled by default.
|
||||
var DefaultOptions = Options{
|
||||
Extensions: CommonExtensions,
|
||||
}
|
||||
|
||||
// TODO: this should probably be unexported. Or moved to node.go
|
||||
type LinkType int
|
||||
|
||||
// These are the possible flag values for the link renderer.
|
||||
|
@ -81,6 +87,7 @@ const (
|
|||
LinkTypeEmail
|
||||
)
|
||||
|
||||
// ListType contains bitwise or'ed flags for list and list item objects.
|
||||
type ListType int
|
||||
|
||||
// These are the possible flag values for the ListItem renderer.
|
||||
|
@ -96,6 +103,7 @@ const (
|
|||
ListItemEndOfList
|
||||
)
|
||||
|
||||
// CellAlignFlags holds a type of alignment in a table cell.
|
||||
type CellAlignFlags int
|
||||
|
||||
// These are the possible flag values for the table cell renderer.
|
||||
|
@ -213,7 +221,7 @@ func (p *parser) getRef(refid string) (ref *reference, found bool) {
|
|||
return &reference{
|
||||
link: []byte(r.Link),
|
||||
title: []byte(r.Title),
|
||||
noteId: 0,
|
||||
noteID: 0,
|
||||
hasBlock: false,
|
||||
text: []byte(r.Text)}, true
|
||||
}
|
||||
|
@ -312,29 +320,21 @@ func MarkdownBasic(input []byte) []byte {
|
|||
return Markdown(input, renderer, Options{})
|
||||
}
|
||||
|
||||
// Call Markdown with most useful extensions enabled
|
||||
// MarkdownCommon is a convenience function for simple rendering.
|
||||
// It processes markdown input with common extensions enabled, including:
|
||||
// MarkdownCommon is a convenience function for simple rendering. It calls
|
||||
// Markdown with most useful extensions enabled, including:
|
||||
//
|
||||
// * Smartypants processing with smart fractions and LaTeX dashes
|
||||
//
|
||||
// * Intra-word emphasis suppression
|
||||
//
|
||||
// * Tables
|
||||
//
|
||||
// * Fenced code blocks
|
||||
//
|
||||
// * Autolinking
|
||||
//
|
||||
// * Strikethrough support
|
||||
//
|
||||
// * Strict header parsing
|
||||
//
|
||||
// * Custom Header IDs
|
||||
func MarkdownCommon(input []byte) []byte {
|
||||
// set up the HTML renderer
|
||||
renderer := NewHTMLRenderer(HTMLRendererParameters{
|
||||
Flags: CommonHtmlFlags,
|
||||
Flags: CommonHTMLFlags,
|
||||
Extensions: CommonExtensions,
|
||||
})
|
||||
return Markdown(input, renderer, DefaultOptions)
|
||||
|
@ -354,6 +354,10 @@ func Markdown(input []byte, renderer Renderer, options Options) []byte {
|
|||
return renderer.Render(Parse(input, options))
|
||||
}
|
||||
|
||||
// Parse is an entry point to the parsing part of Blackfriday. It takes an
|
||||
// input markdown document and produces a syntax tree for its contents. This
|
||||
// tree can then be rendered with a default or custom renderer, or
|
||||
// analyzed/transformed by the caller to whatever non-standard needs they have.
|
||||
func Parse(input []byte, opts Options) *Node {
|
||||
extensions := opts.Extensions
|
||||
|
||||
|
@ -592,7 +596,7 @@ func secondPass(p *parser, input []byte) {
|
|||
|
||||
if p.flags&Footnotes != 0 && len(p.notes) > 0 {
|
||||
flags := ListItemBeginningOfList
|
||||
for i := 0; i < len(p.notes); i += 1 {
|
||||
for i := 0; i < len(p.notes); i++ {
|
||||
ref := p.notes[i]
|
||||
if ref.hasBlock {
|
||||
flags |= ListItemContainsBlock
|
||||
|
@ -642,14 +646,14 @@ func secondPass(p *parser, input []byte) {
|
|||
type reference struct {
|
||||
link []byte
|
||||
title []byte
|
||||
noteId int // 0 if not a footnote ref
|
||||
noteID int // 0 if not a footnote ref
|
||||
hasBlock bool
|
||||
text []byte
|
||||
}
|
||||
|
||||
func (r *reference) String() string {
|
||||
return fmt.Sprintf("{link: %q, title: %q, text: %q, noteId: %d, hasBlock: %v}",
|
||||
r.link, r.title, r.text, r.noteId, r.hasBlock)
|
||||
return fmt.Sprintf("{link: %q, title: %q, text: %q, noteID: %d, hasBlock: %v}",
|
||||
r.link, r.title, r.text, r.noteID, r.hasBlock)
|
||||
}
|
||||
|
||||
// Check whether or not data starts with a reference link.
|
||||
|
@ -667,7 +671,7 @@ func isReference(p *parser, data []byte, tabSize int) int {
|
|||
i++
|
||||
}
|
||||
|
||||
noteId := 0
|
||||
noteID := 0
|
||||
|
||||
// id part: anything but a newline between brackets
|
||||
if data[i] != '[' {
|
||||
|
@ -678,7 +682,7 @@ func isReference(p *parser, data []byte, tabSize int) int {
|
|||
if i < len(data) && data[i] == '^' {
|
||||
// we can set it to anything here because the proper noteIds will
|
||||
// be assigned later during the second pass. It just has to be != 0
|
||||
noteId = 1
|
||||
noteID = 1
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
@ -721,7 +725,7 @@ func isReference(p *parser, data []byte, tabSize int) int {
|
|||
hasBlock bool
|
||||
)
|
||||
|
||||
if p.flags&Footnotes != 0 && noteId != 0 {
|
||||
if p.flags&Footnotes != 0 && noteID != 0 {
|
||||
linkOffset, linkEnd, raw, hasBlock = scanFootnote(p, data, i, tabSize)
|
||||
lineEnd = linkEnd
|
||||
} else {
|
||||
|
@ -734,11 +738,11 @@ func isReference(p *parser, data []byte, tabSize int) int {
|
|||
// a valid ref has been found
|
||||
|
||||
ref := &reference{
|
||||
noteId: noteId,
|
||||
noteID: noteID,
|
||||
hasBlock: hasBlock,
|
||||
}
|
||||
|
||||
if noteId > 0 {
|
||||
if noteID > 0 {
|
||||
// reusing the link field for the id since footnotes don't have links
|
||||
ref.link = data[idOffset:idEnd]
|
||||
// if footnote, it's not really a title, it's the contained text
|
||||
|
|
Loading…
Reference in New Issue
Block a user