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
1b7415a8
Commit
1b7415a8
authored
Mar 20, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Markdown handles titles a little better
parent
abdadf1e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
1 deletion
+19
-1
middleware/markdown/markdown.go
middleware/markdown/markdown.go
+19
-1
No files found.
middleware/markdown/markdown.go
View file @
1b7415a8
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
package
markdown
package
markdown
import
(
import
(
"bytes"
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
"path"
"path"
...
@@ -75,18 +76,35 @@ func (m Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) {
...
@@ -75,18 +76,35 @@ func (m Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) {
scripts
+=
strings
.
Replace
(
jsTemplate
,
"{{url}}"
,
script
,
1
)
+
"
\r\n
"
scripts
+=
strings
.
Replace
(
jsTemplate
,
"{{url}}"
,
script
,
1
)
+
"
\r\n
"
}
}
// Title is first line (length-limited), otherwise filename
title
:=
path
.
Base
(
fpath
)
newline
:=
bytes
.
Index
(
body
,
[]
byte
(
"
\n
"
))
if
newline
>
-
1
{
firstline
:=
body
[
:
newline
]
newTitle
:=
strings
.
TrimSpace
(
string
(
firstline
))
if
len
(
newTitle
)
>
1
{
if
len
(
newTitle
)
>
128
{
title
=
newTitle
[
:
128
]
}
else
{
title
=
newTitle
}
}
}
html
:=
htmlTemplate
html
:=
htmlTemplate
html
=
strings
.
Replace
(
html
,
"{{title}}"
,
path
.
Base
(
fpath
)
,
1
)
html
=
strings
.
Replace
(
html
,
"{{title}}"
,
title
,
1
)
html
=
strings
.
Replace
(
html
,
"{{css}}"
,
styles
,
1
)
html
=
strings
.
Replace
(
html
,
"{{css}}"
,
styles
,
1
)
html
=
strings
.
Replace
(
html
,
"{{js}}"
,
scripts
,
1
)
html
=
strings
.
Replace
(
html
,
"{{js}}"
,
scripts
,
1
)
html
=
strings
.
Replace
(
html
,
"{{body}}"
,
string
(
content
),
1
)
html
=
strings
.
Replace
(
html
,
"{{body}}"
,
string
(
content
),
1
)
w
.
Write
([]
byte
(
html
))
w
.
Write
([]
byte
(
html
))
return
return
}
}
}
}
}
}
// Didn't qualify to serve as markdown; pass-thru
m
.
Next
(
w
,
r
)
m
.
Next
(
w
,
r
)
}
}
...
...
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