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
043e0004
Commit
043e0004
authored
Sep 18, 2015
by
Henrique Dias
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1 from mholt/master
Update
parents
4c642e9d
66fb8f03
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
0 deletions
+34
-0
middleware/context.go
middleware/context.go
+34
-0
No files found.
middleware/context.go
View file @
043e0004
...
...
@@ -131,6 +131,40 @@ func (c Context) Truncate(input string, length int) string {
return
input
}
// StripHTML returns s without HTML tags. It is fairly naive
// but works with most valid HTML inputs.
func
(
c
Context
)
StripHTML
(
s
string
)
string
{
var
buf
bytes
.
Buffer
var
inTag
,
inQuotes
bool
var
tagStart
int
for
i
,
ch
:=
range
s
{
if
inTag
{
if
ch
==
'>'
&&
!
inQuotes
{
inTag
=
false
}
else
if
ch
==
'<'
&&
!
inQuotes
{
// false start
buf
.
WriteString
(
s
[
tagStart
:
i
])
tagStart
=
i
}
else
if
ch
==
'"'
{
inQuotes
=
!
inQuotes
}
continue
}
if
ch
==
'<'
{
inTag
=
true
tagStart
=
i
continue
}
buf
.
WriteRune
(
ch
)
}
if
inTag
{
// false start
buf
.
WriteString
(
s
[
tagStart
:
])
inTag
=
false
}
return
buf
.
String
()
}
// StripExt returns the input string without the extension,
// which is the suffix starting with the final '.' character
// but not before the final path separator ('/') character.
...
...
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