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
Łukasz Nowak
caddy
Commits
2df30d18
Commit
2df30d18
authored
Jul 21, 2015
by
Maxime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a test on markdown for the default template
parent
6451e10d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
2 deletions
+69
-2
middleware/markdown/log/test.md
middleware/markdown/log/test.md
+15
-0
middleware/markdown/markdown_test.go
middleware/markdown/markdown_test.go
+53
-1
middleware/markdown/process.go
middleware/markdown/process.go
+1
-1
No files found.
middleware/markdown/log/test.md
0 → 100644
View file @
2df30d18
---
title
:
Markdown test
variables
:
sitename
:
A Caddy website
---
## Welcome on the blog
Body
```
go
func
getTrue
()
bool
{
return
true
}
```
middleware/markdown/markdown_test.go
View file @
2df30d18
...
@@ -3,6 +3,7 @@ package markdown
...
@@ -3,6 +3,7 @@ package markdown
import
(
import
(
"net/http"
"net/http"
"net/http/httptest"
"net/http/httptest"
"strings"
"testing"
"testing"
"github.com/russross/blackfriday"
"github.com/russross/blackfriday"
...
@@ -18,11 +19,19 @@ func TestMarkdown(t *testing.T) {
...
@@ -18,11 +19,19 @@ func TestMarkdown(t *testing.T) {
Config
{
Config
{
Renderer
:
blackfriday
.
HtmlRenderer
(
0
,
""
,
""
),
Renderer
:
blackfriday
.
HtmlRenderer
(
0
,
""
,
""
),
PathScope
:
"/blog"
,
PathScope
:
"/blog"
,
Extensions
:
[]
string
{
"md"
},
Extensions
:
[]
string
{
"
.
md"
},
Styles
:
[]
string
{},
Styles
:
[]
string
{},
Scripts
:
[]
string
{},
Scripts
:
[]
string
{},
Templates
:
templates
,
Templates
:
templates
,
},
},
Config
{
Renderer
:
blackfriday
.
HtmlRenderer
(
0
,
""
,
""
),
PathScope
:
"/log"
,
Extensions
:
[]
string
{
".md"
},
Styles
:
[]
string
{
"/resources/css/log.css"
,
"/resources/css/default.css"
},
Scripts
:
[]
string
{
"/resources/js/log.js"
,
"/resources/js/default.js"
},
Templates
:
make
(
map
[
string
]
string
),
},
},
},
IndexFiles
:
[]
string
{
"index.html"
},
IndexFiles
:
[]
string
{
"index.html"
},
}
}
...
@@ -62,7 +71,50 @@ func getTrue() bool {
...
@@ -62,7 +71,50 @@ func getTrue() bool {
</body>
</body>
</html>
</html>
`
`
if
respBody
!=
expectedBody
{
t
.
Fatalf
(
"Expected body: %v got: %v"
,
expectedBody
,
respBody
)
}
req
,
err
=
http
.
NewRequest
(
"GET"
,
"/log/test.md"
,
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"Could not create HTTP request: %v"
,
err
)
}
rec
=
httptest
.
NewRecorder
()
md
.
ServeHTTP
(
rec
,
req
)
if
rec
.
Code
!=
http
.
StatusOK
{
t
.
Fatalf
(
"Wrong status, expected: %d and got %d"
,
http
.
StatusOK
,
rec
.
Code
)
}
respBody
=
rec
.
Body
.
String
()
expectedBody
=
`<!DOCTYPE html>
<html>
<head>
<title>Markdown test</title>
<meta charset="utf-8">
<link rel="stylesheet" href="/resources/css/log.css">
<link rel="stylesheet" href="/resources/css/default.css">
<script src="/resources/js/log.js"></script>
<script src="/resources/js/default.js"></script>
</head>
<body>
<h2>Welcome on the blog</h2>
<p>Body</p>
<p><code>go
func getTrue() bool {
return true
}
</code></p>
</body>
</html>`
replacer
:=
strings
.
NewReplacer
(
"
\r
"
,
""
,
"
\n
"
,
""
)
respBody
=
replacer
.
Replace
(
respBody
)
expectedBody
=
replacer
.
Replace
(
expectedBody
)
if
respBody
!=
expectedBody
{
if
respBody
!=
expectedBody
{
t
.
Fatalf
(
"Expected body: %v got: %v"
,
expectedBody
,
respBody
)
t
.
Fatalf
(
"Expected body: %v got: %v"
,
expectedBody
,
respBody
)
}
}
...
...
middleware/markdown/process.go
View file @
2df30d18
...
@@ -191,7 +191,7 @@ const (
...
@@ -191,7 +191,7 @@ const (
{{js}}
{{js}}
</head>
</head>
<body>
<body>
{{.
m
arkdown}}
{{.
M
arkdown}}
</body>
</body>
</html>`
</html>`
cssTemplate
=
`<link rel="stylesheet" href="{{url}}">`
cssTemplate
=
`<link rel="stylesheet" href="{{url}}">`
...
...
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