Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mayi-mp-shop
Overview
Overview
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
程默
mayi-mp-shop
Commits
4458647b
Commit
4458647b
authored
Dec 22, 2021
by
李嘉林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
富文本组件
parent
66613e44
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
12 deletions
+27
-12
src/components/basicTool/rich-text/index.vue
+27
-12
No files found.
src/components/basicTool/rich-text/index.vue
View file @
4458647b
...
...
@@ -20,24 +20,39 @@
*/
function
formatRichText
(
html
)
{
let
newContent
=
html
.
replace
(
/<img
[^
>
]
*>/gi
,
function
(
match
,
capture
)
{
match
=
match
.
replace
(
/style="
[^
"
]
+"/gi
,
""
).
replace
(
/style='
[^
'
]
+'/gi
,
""
);
match
=
match
.
replace
(
/width="
[^
"
]
+"/gi
,
""
).
replace
(
/width='
[^
'
]
+'/gi
,
""
);
match
=
match
.
replace
(
/height="
[^
"
]
+"/gi
,
""
)
.
replace
(
/height='
[^
'
]
+'/gi
,
""
);
// match = match.replace(/style="[^"]+"/gi, "").replace(/style='[^']+'/gi, "");
// match = match.replace(/width="[^"]+"/gi, "").replace(/width='[^']+'/gi, "");
// match = match
// .replace(/height="[^"]+"/gi, "")
// .replace(/height='[^']+'/gi, "");
let
maxWidth
=
375
;
match
.
replace
(
/width="
(
.+
?)
"/g
,
function
(
val
,
val1
)
{
if
(
val1
>
maxWidth
)
{
match
=
match
.
replace
(
/width="
[^
"
]
+"/gi
,
""
)
.
replace
(
/width='
[^
'
]
+'/gi
,
""
);
match
=
match
.
replace
(
/\<img/gi
,
'<img style="max-width:100%;height:auto;display:block;margin-top:0;margin-bottom:0;"'
);
}
});
return
match
;
});
newContent
=
newContent
.
replace
(
/style="
[^
"
]
+"/gi
,
function
(
match
,
capture
)
{
match
=
match
.
replace
(
/width:
[^
;
]
+;/gi
,
"max-width:100%;"
)
.
replace
(
/width:
[^
;
]
+;/gi
,
"max-width:100%;"
);
.
replace
(
/ width:
[^
;
]
+;/gi
,
"max-width:100%;"
)
.
replace
(
/ width:
[^
;
]
+;/gi
,
"max-width:100%;"
);
match
=
match
.
replace
(
/max-width:
[^
;
]
+;/gi
,
"max-width:100%;"
)
.
replace
(
/max-width:
[^
;
]
+;/gi
,
"max-width:100%;"
);
return
match
;
});
newContent
=
newContent
.
replace
(
/<br
[^
>
]
*
\/
>/gi
,
""
);
newContent
=
newContent
.
replace
(
/\<img/gi
,
'<img style="max-width:100%;height:auto;display:block;margin-top:0;margin-bottom:0;"'
);
//
newContent = newContent.replace(/
<
br
[
^>
]
*
\
/>
/gi, ""
)
;
//
newContent = newContent.replace(
//
/\
<
img
/
gi
,
//
'
<
img
style
=
"max-width:100%;height:auto;display:block;margin-top:0;margin-bottom:0;"
'
//
);
return newContent;
}
export default {
...
...
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