Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
45e783c3
Commit
45e783c3
authored
May 01, 2016
by
Tobias Weingartner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix headers and unexport plaintext renderer.
parent
2bccc146
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
37 deletions
+41
-37
middleware/markdown/markdown.go
middleware/markdown/markdown.go
+3
-0
middleware/markdown/summary/render.go
middleware/markdown/summary/render.go
+37
-36
middleware/markdown/summary/summary.go
middleware/markdown/summary/summary.go
+1
-1
No files found.
middleware/markdown/markdown.go
View file @
45e783c3
...
...
@@ -6,6 +6,7 @@ import (
"net/http"
"os"
"path"
"strconv"
"strings"
"text/template"
"time"
...
...
@@ -142,6 +143,8 @@ func (md Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
return
http
.
StatusInternalServerError
,
err
}
w
.
Header
()
.
Set
(
"Content-Type"
,
"text/html; charset=utf-8"
)
w
.
Header
()
.
Set
(
"Content-Length"
,
strconv
.
FormatInt
(
int64
(
len
(
html
)),
10
))
middleware
.
SetLastModifiedHeader
(
w
,
lastModTime
)
if
r
.
Method
==
http
.
MethodGet
{
w
.
Write
(
html
)
...
...
middleware/markdown/summary/render.go
View file @
45e783c3
...
...
@@ -7,32 +7,33 @@ import (
)
// Ensure we implement the Blackfriday Markdown Renderer interface
var
_
blackfriday
.
Renderer
=
(
*
R
enderer
)(
nil
)
var
_
blackfriday
.
Renderer
=
(
*
r
enderer
)(
nil
)
// Renderer is a plain-text Markdown renderer that implements the
// blackfriday.Renderer interface. Many of the required methods are
// stubs with no output.
type
Renderer
struct
{}
// renderer renders Markdown to plain-text meant for listings and excerpts,
// and implements the blackfriday.Renderer interface.
//
// Many of the methods are stubs with no output to prevent output of HTML markup.
type
renderer
struct
{}
// Blocklevel callbacks
// Stub BlockCode is the code tag callback.
func
(
r
R
enderer
)
BlockCode
(
out
*
bytes
.
Buffer
,
text
[]
byte
,
land
string
)
{}
func
(
r
r
enderer
)
BlockCode
(
out
*
bytes
.
Buffer
,
text
[]
byte
,
land
string
)
{}
// Stub BlockQuote is teh quote tag callback.
func
(
r
R
enderer
)
BlockQuote
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{}
func
(
r
r
enderer
)
BlockQuote
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{}
// Stub BlockHtml is the HTML tag callback.
func
(
r
R
enderer
)
BlockHtml
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{}
func
(
r
r
enderer
)
BlockHtml
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{}
// Stub Header is the header tag callback.
func
(
r
R
enderer
)
Header
(
out
*
bytes
.
Buffer
,
text
func
()
bool
,
level
int
,
id
string
)
{}
func
(
r
r
enderer
)
Header
(
out
*
bytes
.
Buffer
,
text
func
()
bool
,
level
int
,
id
string
)
{}
// Stub HRule is the horizontal rule tag callback.
func
(
r
R
enderer
)
HRule
(
out
*
bytes
.
Buffer
)
{}
func
(
r
r
enderer
)
HRule
(
out
*
bytes
.
Buffer
)
{}
// List is the list tag callback.
func
(
r
R
enderer
)
List
(
out
*
bytes
.
Buffer
,
text
func
()
bool
,
flags
int
)
{
func
(
r
r
enderer
)
List
(
out
*
bytes
.
Buffer
,
text
func
()
bool
,
flags
int
)
{
// TODO: This is not desired (we'd rather not write lists as part of summary),
// but see this issue: https://github.com/russross/blackfriday/issues/189
marker
:=
out
.
Len
()
...
...
@@ -43,11 +44,11 @@ func (r Renderer) List(out *bytes.Buffer, text func() bool, flags int) {
}
// Stub ListItem is the list item tag callback.
func
(
r
R
enderer
)
ListItem
(
out
*
bytes
.
Buffer
,
text
[]
byte
,
flags
int
)
{}
func
(
r
r
enderer
)
ListItem
(
out
*
bytes
.
Buffer
,
text
[]
byte
,
flags
int
)
{}
// Paragraph is the paragraph tag callback. This renders simple paragraph text
// into plain text, such that summaries can be easily generated.
func
(
r
R
enderer
)
Paragraph
(
out
*
bytes
.
Buffer
,
text
func
()
bool
)
{
func
(
r
r
enderer
)
Paragraph
(
out
*
bytes
.
Buffer
,
text
func
()
bool
)
{
marker
:=
out
.
Len
()
if
!
text
()
{
out
.
Truncate
(
marker
)
...
...
@@ -56,34 +57,34 @@ func (r Renderer) Paragraph(out *bytes.Buffer, text func() bool) {
}
// Stub Table is the table tag callback.
func
(
r
R
enderer
)
Table
(
out
*
bytes
.
Buffer
,
header
[]
byte
,
body
[]
byte
,
columnData
[]
int
)
{}
func
(
r
r
enderer
)
Table
(
out
*
bytes
.
Buffer
,
header
[]
byte
,
body
[]
byte
,
columnData
[]
int
)
{}
// Stub TableRow is the table row tag callback.
func
(
r
R
enderer
)
TableRow
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{}
func
(
r
r
enderer
)
TableRow
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{}
// Stub TableHeaderCell is the table header cell tag callback.
func
(
r
R
enderer
)
TableHeaderCell
(
out
*
bytes
.
Buffer
,
text
[]
byte
,
flags
int
)
{}
func
(
r
r
enderer
)
TableHeaderCell
(
out
*
bytes
.
Buffer
,
text
[]
byte
,
flags
int
)
{}
// Stub TableCell is the table cell tag callback.
func
(
r
R
enderer
)
TableCell
(
out
*
bytes
.
Buffer
,
text
[]
byte
,
flags
int
)
{}
func
(
r
r
enderer
)
TableCell
(
out
*
bytes
.
Buffer
,
text
[]
byte
,
flags
int
)
{}
// Stub Footnotes is the foot notes tag callback.
func
(
r
R
enderer
)
Footnotes
(
out
*
bytes
.
Buffer
,
text
func
()
bool
)
{}
func
(
r
r
enderer
)
Footnotes
(
out
*
bytes
.
Buffer
,
text
func
()
bool
)
{}
// Stub FootnoteItem is the footnote item tag callback.
func
(
r
R
enderer
)
FootnoteItem
(
out
*
bytes
.
Buffer
,
name
,
text
[]
byte
,
flags
int
)
{}
func
(
r
r
enderer
)
FootnoteItem
(
out
*
bytes
.
Buffer
,
name
,
text
[]
byte
,
flags
int
)
{}
// Stub TitleBlock is the title tag callback.
func
(
r
R
enderer
)
TitleBlock
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{}
func
(
r
r
enderer
)
TitleBlock
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{}
// Spanlevel callbacks
// Stub AutoLink is the autolink tag callback.
func
(
r
R
enderer
)
AutoLink
(
out
*
bytes
.
Buffer
,
link
[]
byte
,
kind
int
)
{}
func
(
r
r
enderer
)
AutoLink
(
out
*
bytes
.
Buffer
,
link
[]
byte
,
kind
int
)
{}
// CodeSpan is the code span tag callback. Outputs a simple Markdown version
// of the code span.
func
(
r
R
enderer
)
CodeSpan
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{
func
(
r
r
enderer
)
CodeSpan
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{
out
.
Write
([]
byte
(
"`"
))
out
.
Write
(
text
)
out
.
Write
([]
byte
(
"`"
))
...
...
@@ -91,62 +92,62 @@ func (r Renderer) CodeSpan(out *bytes.Buffer, text []byte) {
// DoubleEmphasis is the double emphasis tag callback. Outputs a simple
// plain-text version of the input.
func
(
r
R
enderer
)
DoubleEmphasis
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{
func
(
r
r
enderer
)
DoubleEmphasis
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{
out
.
Write
(
text
)
}
// Emphasis is the emphasis tag callback. Outputs a simple plain-text
// version of the input.
func
(
r
R
enderer
)
Emphasis
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{
func
(
r
r
enderer
)
Emphasis
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{
out
.
Write
(
text
)
}
// Stub Image is the image tag callback.
func
(
r
R
enderer
)
Image
(
out
*
bytes
.
Buffer
,
link
[]
byte
,
title
[]
byte
,
alt
[]
byte
)
{}
func
(
r
r
enderer
)
Image
(
out
*
bytes
.
Buffer
,
link
[]
byte
,
title
[]
byte
,
alt
[]
byte
)
{}
// Stub LineBreak is the line break tag callback.
func
(
r
R
enderer
)
LineBreak
(
out
*
bytes
.
Buffer
)
{}
func
(
r
r
enderer
)
LineBreak
(
out
*
bytes
.
Buffer
)
{}
// Link is the link tag callback. Outputs a sipmle plain-text version
// of the input.
func
(
r
R
enderer
)
Link
(
out
*
bytes
.
Buffer
,
link
[]
byte
,
title
[]
byte
,
content
[]
byte
)
{
func
(
r
r
enderer
)
Link
(
out
*
bytes
.
Buffer
,
link
[]
byte
,
title
[]
byte
,
content
[]
byte
)
{
out
.
Write
(
content
)
}
// Stub RawHtmlTag is the raw HTML tag callback.
func
(
r
R
enderer
)
RawHtmlTag
(
out
*
bytes
.
Buffer
,
tag
[]
byte
)
{}
func
(
r
r
enderer
)
RawHtmlTag
(
out
*
bytes
.
Buffer
,
tag
[]
byte
)
{}
// TripleEmphasis is the triple emphasis tag callback. Outputs a simple plain-text
// version of the input.
func
(
r
R
enderer
)
TripleEmphasis
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{
func
(
r
r
enderer
)
TripleEmphasis
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{
out
.
Write
(
text
)
}
// Stub StrikeThrough is the strikethrough tag callback.
func
(
r
R
enderer
)
StrikeThrough
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{}
func
(
r
r
enderer
)
StrikeThrough
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{}
// Stub FootnoteRef is the footnote ref tag callback.
func
(
r
R
enderer
)
FootnoteRef
(
out
*
bytes
.
Buffer
,
ref
[]
byte
,
id
int
)
{}
func
(
r
r
enderer
)
FootnoteRef
(
out
*
bytes
.
Buffer
,
ref
[]
byte
,
id
int
)
{}
// Lowlevel callbacks
// Entity callback. Outputs a simple plain-text version of the input.
func
(
r
R
enderer
)
Entity
(
out
*
bytes
.
Buffer
,
entity
[]
byte
)
{
func
(
r
r
enderer
)
Entity
(
out
*
bytes
.
Buffer
,
entity
[]
byte
)
{
out
.
Write
(
entity
)
}
// NormalText callback. Outputs a simple plain-text version of the input.
func
(
r
R
enderer
)
NormalText
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{
func
(
r
r
enderer
)
NormalText
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{
out
.
Write
(
text
)
}
// Header and footer
// Stub DocumentHeader callback.
func
(
r
R
enderer
)
DocumentHeader
(
out
*
bytes
.
Buffer
)
{}
func
(
r
r
enderer
)
DocumentHeader
(
out
*
bytes
.
Buffer
)
{}
// Stub DocumentFooter callback.
func
(
r
R
enderer
)
DocumentFooter
(
out
*
bytes
.
Buffer
)
{}
func
(
r
r
enderer
)
DocumentFooter
(
out
*
bytes
.
Buffer
)
{}
// Stub GetFlags returns zero.
func
(
r
R
enderer
)
GetFlags
()
int
{
return
0
}
func
(
r
r
enderer
)
GetFlags
()
int
{
return
0
}
middleware/markdown/summary/summary.go
View file @
45e783c3
...
...
@@ -9,7 +9,7 @@ import (
// Markdown formats input using a plain-text renderer, and
// then returns up to the first `wordcount` words as a summary.
func
Markdown
(
input
[]
byte
,
wordcount
int
)
[]
byte
{
words
:=
bytes
.
Fields
(
blackfriday
.
Markdown
(
input
,
R
enderer
{},
0
))
words
:=
bytes
.
Fields
(
blackfriday
.
Markdown
(
input
,
r
enderer
{},
0
))
if
wordcount
>
len
(
words
)
{
wordcount
=
len
(
words
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment