mirror of
https://github.com/danog/blackfriday.git
synced 2025-01-23 05:41:27 +01:00
Add footnote prefix option. Needs testing
This commit is contained in:
parent
5c12499aa1
commit
ec41294bc4
@ -21,7 +21,7 @@ func runMarkdownBlock(input string, extensions int) string {
|
|||||||
htmlFlags := 0
|
htmlFlags := 0
|
||||||
htmlFlags |= HTML_USE_XHTML
|
htmlFlags |= HTML_USE_XHTML
|
||||||
|
|
||||||
renderer := HtmlRenderer(htmlFlags, "", "", "")
|
renderer := HtmlRenderer(htmlFlags, "", "")
|
||||||
|
|
||||||
return string(Markdown([]byte(input), renderer, extensions))
|
return string(Markdown([]byte(input), renderer, extensions))
|
||||||
}
|
}
|
||||||
|
49
html.go
49
html.go
@ -41,7 +41,7 @@ const (
|
|||||||
HTML_USE_SMARTYPANTS // enable smart punctuation substitutions
|
HTML_USE_SMARTYPANTS // enable smart punctuation substitutions
|
||||||
HTML_SMARTYPANTS_FRACTIONS // enable smart fractions (with HTML_USE_SMARTYPANTS)
|
HTML_SMARTYPANTS_FRACTIONS // enable smart fractions (with HTML_USE_SMARTYPANTS)
|
||||||
HTML_SMARTYPANTS_LATEX_DASHES // enable LaTeX-style dashes (with HTML_USE_SMARTYPANTS)
|
HTML_SMARTYPANTS_LATEX_DASHES // enable LaTeX-style dashes (with HTML_USE_SMARTYPANTS)
|
||||||
HTML_ABSOLUTE_LINKS // convert all links to absolute links
|
HTML_ABSOLUTE_LINKS // convert all links to absolute links, using AbsolutePrefix
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -55,15 +55,21 @@ var (
|
|||||||
htmlEntity = regexp.MustCompile(`&[a-z]{2,5};`)
|
htmlEntity = regexp.MustCompile(`&[a-z]{2,5};`)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type HtmlRendererParameters struct {
|
||||||
|
AbsolutePrefix string
|
||||||
|
FootnotePrefix string
|
||||||
|
}
|
||||||
|
|
||||||
// Html is a type that implements the Renderer interface for HTML output.
|
// Html is a type that implements the Renderer interface for HTML output.
|
||||||
//
|
//
|
||||||
// Do not create this directly, instead use the HtmlRenderer function.
|
// Do not create this directly, instead use the HtmlRenderer function.
|
||||||
type Html struct {
|
type Html struct {
|
||||||
flags int // HTML_* options
|
flags int // HTML_* options
|
||||||
closeTag string // how to end singleton tags: either " />\n" or ">\n"
|
closeTag string // how to end singleton tags: either " />\n" or ">\n"
|
||||||
title string // document title
|
title string // document title
|
||||||
css string // optional css file url (used with HTML_COMPLETE_PAGE)
|
css string // optional css file url (used with HTML_COMPLETE_PAGE)
|
||||||
absolutePrefix string
|
|
||||||
|
parameters HtmlRendererParameters
|
||||||
|
|
||||||
// table of contents data
|
// table of contents data
|
||||||
tocMarker int
|
tocMarker int
|
||||||
@ -86,7 +92,12 @@ const (
|
|||||||
// title is the title of the document, and css is a URL for the document's
|
// title is the title of the document, and css is a URL for the document's
|
||||||
// stylesheet.
|
// stylesheet.
|
||||||
// title and css are only used when HTML_COMPLETE_PAGE is selected.
|
// title and css are only used when HTML_COMPLETE_PAGE is selected.
|
||||||
func HtmlRenderer(flags int, title string, css string, absolutePrefix string) Renderer {
|
func HtmlRenderer(flags int, title string, css string) Renderer {
|
||||||
|
return HtmlRendererWithParameters(flags, title, css, HtmlRendererParameters{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func HtmlRendererWithParameters(flags int, title string,
|
||||||
|
css string, renderParameters HtmlRendererParameters) Renderer {
|
||||||
// configure the rendering engine
|
// configure the rendering engine
|
||||||
closeTag := htmlClose
|
closeTag := htmlClose
|
||||||
if flags&HTML_USE_XHTML != 0 {
|
if flags&HTML_USE_XHTML != 0 {
|
||||||
@ -94,11 +105,11 @@ func HtmlRenderer(flags int, title string, css string, absolutePrefix string) Re
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &Html{
|
return &Html{
|
||||||
flags: flags,
|
flags: flags,
|
||||||
closeTag: closeTag,
|
closeTag: closeTag,
|
||||||
title: title,
|
title: title,
|
||||||
css: css,
|
css: css,
|
||||||
absolutePrefix: absolutePrefix,
|
parameters: renderParameters,
|
||||||
|
|
||||||
headerCount: 0,
|
headerCount: 0,
|
||||||
currentLevel: 0,
|
currentLevel: 0,
|
||||||
@ -352,7 +363,9 @@ func (options *Html) FootnoteItem(out *bytes.Buffer, name, text []byte, flags in
|
|||||||
if flags&LIST_ITEM_CONTAINS_BLOCK != 0 || flags&LIST_ITEM_BEGINNING_OF_LIST != 0 {
|
if flags&LIST_ITEM_CONTAINS_BLOCK != 0 || flags&LIST_ITEM_BEGINNING_OF_LIST != 0 {
|
||||||
doubleSpace(out)
|
doubleSpace(out)
|
||||||
}
|
}
|
||||||
out.WriteString(`<li id="fn:`)
|
out.WriteString(`<li id="`)
|
||||||
|
out.WriteString(options.parameters.FootnotePrefix)
|
||||||
|
out.WriteString(`fn:`)
|
||||||
out.Write(slugify(name))
|
out.Write(slugify(name))
|
||||||
out.WriteString(`">`)
|
out.WriteString(`">`)
|
||||||
out.Write(text)
|
out.Write(text)
|
||||||
@ -467,7 +480,7 @@ func (options *Html) Emphasis(out *bytes.Buffer, text []byte) {
|
|||||||
|
|
||||||
func (options *Html) maybeWriteAbsolutePrefix(out *bytes.Buffer, link []byte) {
|
func (options *Html) maybeWriteAbsolutePrefix(out *bytes.Buffer, link []byte) {
|
||||||
if options.flags&HTML_ABSOLUTE_LINKS != 0 && isRelativeLink(link) {
|
if options.flags&HTML_ABSOLUTE_LINKS != 0 && isRelativeLink(link) {
|
||||||
out.WriteString(options.absolutePrefix)
|
out.WriteString(options.parameters.AbsolutePrefix)
|
||||||
if link[0] != '/' {
|
if link[0] != '/' {
|
||||||
out.WriteByte('/')
|
out.WriteByte('/')
|
||||||
}
|
}
|
||||||
@ -569,9 +582,13 @@ func (options *Html) StrikeThrough(out *bytes.Buffer, text []byte) {
|
|||||||
|
|
||||||
func (options *Html) FootnoteRef(out *bytes.Buffer, ref []byte, id int) {
|
func (options *Html) FootnoteRef(out *bytes.Buffer, ref []byte, id int) {
|
||||||
slug := slugify(ref)
|
slug := slugify(ref)
|
||||||
out.WriteString(`<sup class="footnote-ref" id="fnref:`)
|
out.WriteString(`<sup class="footnote-ref" id="`)
|
||||||
|
out.WriteString(options.parameters.FootnotePrefix)
|
||||||
|
out.WriteString(`fnref:`)
|
||||||
out.Write(slug)
|
out.Write(slug)
|
||||||
out.WriteString(`"><a rel="footnote" href="#fn:`)
|
out.WriteString(`"><a rel="footnote" href="#`)
|
||||||
|
out.WriteString(options.parameters.FootnotePrefix)
|
||||||
|
out.WriteString(`fn:`)
|
||||||
out.Write(slug)
|
out.Write(slug)
|
||||||
out.WriteString(`">`)
|
out.WriteString(`">`)
|
||||||
out.WriteString(strconv.Itoa(id))
|
out.WriteString(strconv.Itoa(id))
|
||||||
|
@ -23,7 +23,7 @@ func runMarkdownInline(input string, extensions, htmlFlags int) string {
|
|||||||
|
|
||||||
htmlFlags |= HTML_USE_XHTML
|
htmlFlags |= HTML_USE_XHTML
|
||||||
|
|
||||||
renderer := HtmlRenderer(htmlFlags, "", "", "")
|
renderer := HtmlRenderer(htmlFlags, "", "")
|
||||||
|
|
||||||
return string(Markdown([]byte(input), renderer, extensions))
|
return string(Markdown([]byte(input), renderer, extensions))
|
||||||
}
|
}
|
||||||
|
@ -202,7 +202,7 @@ type parser struct {
|
|||||||
func MarkdownBasic(input []byte) []byte {
|
func MarkdownBasic(input []byte) []byte {
|
||||||
// set up the HTML renderer
|
// set up the HTML renderer
|
||||||
htmlFlags := HTML_USE_XHTML
|
htmlFlags := HTML_USE_XHTML
|
||||||
renderer := HtmlRenderer(htmlFlags, "", "", "")
|
renderer := HtmlRenderer(htmlFlags, "", "")
|
||||||
|
|
||||||
// set up the parser
|
// set up the parser
|
||||||
extensions := 0
|
extensions := 0
|
||||||
@ -237,7 +237,7 @@ func MarkdownCommon(input []byte) []byte {
|
|||||||
htmlFlags |= HTML_SMARTYPANTS_FRACTIONS
|
htmlFlags |= HTML_SMARTYPANTS_FRACTIONS
|
||||||
htmlFlags |= HTML_SMARTYPANTS_LATEX_DASHES
|
htmlFlags |= HTML_SMARTYPANTS_LATEX_DASHES
|
||||||
htmlFlags |= HTML_SANITIZE_OUTPUT
|
htmlFlags |= HTML_SANITIZE_OUTPUT
|
||||||
renderer := HtmlRenderer(htmlFlags, "", "", "")
|
renderer := HtmlRenderer(htmlFlags, "", "")
|
||||||
|
|
||||||
// set up the parser
|
// set up the parser
|
||||||
extensions := 0
|
extensions := 0
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func runMarkdownReference(input string, flag int) string {
|
func runMarkdownReference(input string, flag int) string {
|
||||||
renderer := HtmlRenderer(0, "", "", "")
|
renderer := HtmlRenderer(0, "", "")
|
||||||
return string(Markdown([]byte(input), renderer, flag))
|
return string(Markdown([]byte(input), renderer, flag))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user