Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
895ff49a
Commit
895ff49a
authored
Mar 21, 2013
by
Unknown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add func html2str()
parent
e6ab2f73
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
+27
-0
template.go
template.go
+27
-0
No files found.
template.go
View file @
895ff49a
...
...
@@ -54,6 +54,33 @@ func Substr(s string, start, length int) string {
return
string
(
bt
[
start
:
end
])
}
// Html2str() returns escaping text convert from html
func
Html2str
(
html
string
)
string
{
src
:=
string
(
html
)
//将HTML标签全转换成小写
re
,
_
:=
regexp
.
Compile
(
"
\\
<[
\\
S
\\
s]+?
\\
>"
)
src
=
re
.
ReplaceAllStringFunc
(
src
,
strings
.
ToLower
)
//去除STYLE
re
,
_
=
regexp
.
Compile
(
"
\\
<style[
\\
S
\\
s]+?
\\
</style
\\
>"
)
src
=
re
.
ReplaceAllString
(
src
,
""
)
//去除SCRIPT
re
,
_
=
regexp
.
Compile
(
"
\\
<script[
\\
S
\\
s]+?
\\
</script
\\
>"
)
src
=
re
.
ReplaceAllString
(
src
,
""
)
//去除所有尖括号内的HTML代码,并换成换行符
re
,
_
=
regexp
.
Compile
(
"
\\
<[
\\
S
\\
s]+?
\\
>"
)
src
=
re
.
ReplaceAllString
(
src
,
"
\n
"
)
//去除连续的换行符
re
,
_
=
regexp
.
Compile
(
"
\\
s{2,}"
)
src
=
re
.
ReplaceAllString
(
src
,
"
\n
"
)
return
strings
.
TrimSpace
(
src
)
}
// DateFormat takes a time and a layout string and returns a string with the formatted date. Used by the template parser as "dateformat"
func
DateFormat
(
t
time
.
Time
,
layout
string
)
(
datestring
string
)
{
datestring
=
t
.
Format
(
layout
)
...
...
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