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
5b7e0361
Commit
5b7e0361
authored
Feb 04, 2016
by
Matt Holt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #573 from miekg/markdown-directive
templates: Add .Markdown directive
parents
32781064
86f36bdb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
0 deletions
+55
-0
middleware/context.go
middleware/context.go
+16
-0
middleware/context_test.go
middleware/context_test.go
+39
-0
No files found.
middleware/context.go
View file @
5b7e0361
...
...
@@ -9,6 +9,8 @@ import (
"strings"
"text/template"
"time"
"github.com/russross/blackfriday"
)
// This file contains the context and functions available for
...
...
@@ -190,3 +192,17 @@ func (c Context) StripExt(path string) string {
func
(
c
Context
)
Replace
(
input
,
find
,
replacement
string
)
string
{
return
strings
.
Replace
(
input
,
find
,
replacement
,
-
1
)
}
// Markdown returns the HTML contents of the markdown contained in filename
// (relative to the site root).
func
(
c
Context
)
Markdown
(
filename
string
)
(
string
,
error
)
{
body
,
err
:=
c
.
Include
(
filename
)
if
err
!=
nil
{
return
""
,
err
}
renderer
:=
blackfriday
.
HtmlRenderer
(
0
,
""
,
""
)
extns
:=
blackfriday
.
EXTENSION_TABLES
|
blackfriday
.
EXTENSION_FENCED_CODE
|
blackfriday
.
EXTENSION_STRIKETHROUGH
|
blackfriday
.
EXTENSION_DEFINITION_LISTS
markdown
:=
blackfriday
.
Markdown
([]
byte
(
body
),
renderer
,
extns
)
return
string
(
markdown
),
nil
}
middleware/context_test.go
View file @
5b7e0361
...
...
@@ -92,6 +92,45 @@ func TestIncludeNotExisting(t *testing.T) {
}
}
func
TestMarkdown
(
t
*
testing
.
T
)
{
context
:=
getContextOrFail
(
t
)
inputFilename
:=
"test_file"
absInFilePath
:=
filepath
.
Join
(
fmt
.
Sprintf
(
"%s"
,
context
.
Root
),
inputFilename
)
defer
func
()
{
err
:=
os
.
Remove
(
absInFilePath
)
if
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
t
.
Fatalf
(
"Failed to clean test file!"
)
}
}()
tests
:=
[]
struct
{
fileContent
string
expectedContent
string
}{
// Test 0 - test parsing of markdown
{
fileContent
:
"* str1
\n
* str2
\n
"
,
expectedContent
:
"<ul>
\n
<li>str1</li>
\n
<li>str2</li>
\n
</ul>
\n
"
,
},
}
for
i
,
test
:=
range
tests
{
testPrefix
:=
getTestPrefix
(
i
)
// WriteFile truncates the contentt
err
:=
ioutil
.
WriteFile
(
absInFilePath
,
[]
byte
(
test
.
fileContent
),
os
.
ModePerm
)
if
err
!=
nil
{
t
.
Fatal
(
testPrefix
+
"Failed to create test file. Error was: %v"
,
err
)
}
content
,
_
:=
context
.
Markdown
(
inputFilename
)
if
content
!=
test
.
expectedContent
{
t
.
Errorf
(
testPrefix
+
"Expected content [%s] but found [%s]. Input file was: %s"
,
test
.
expectedContent
,
content
,
inputFilename
)
}
}
}
func
TestCookie
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
...
...
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