|
@@ -5,15 +5,15 @@ module.exports = { |
|
@@ -5,15 +5,15 @@ module.exports = { |
5
|
/**
|
5
|
/**
|
6
|
* 分离 CSS
|
6
|
* 分离 CSS
|
7
|
* @param {*} $
|
7
|
* @param {*} $
|
8
|
- * @param {*} prefix
|
8
|
+ * @param {*} option
|
9
|
*/
|
9
|
*/
|
10
|
- processStyle($, prefix) {
|
10
|
+ processStyle($, option) {
|
11
|
let css = [];
|
11
|
let css = [];
|
12
|
|
12
|
|
13
|
$('*').each(function(index) {
|
13
|
$('*').each(function(index) {
|
14
|
let $this = $(this);
|
14
|
let $this = $(this);
|
15
|
let localStyle = $this.attr('style');
|
15
|
let localStyle = $this.attr('style');
|
16
|
- let className = `yoho-inline-style-${prefix}-${index}`;
|
16
|
+ let className = `yoho-inline-style-${option.prefix}-${index}`;
|
17
|
|
17
|
|
18
|
if (localStyle) {
|
18
|
if (localStyle) {
|
19
|
css.push(`.${className}{${localStyle}}`);
|
19
|
css.push(`.${className}{${localStyle}}`);
|
|
@@ -28,13 +28,13 @@ module.exports = { |
|
@@ -28,13 +28,13 @@ module.exports = { |
28
|
* 替换标签
|
28
|
* 替换标签
|
29
|
* @param {*} $
|
29
|
* @param {*} $
|
30
|
*/
|
30
|
*/
|
31
|
- processTag($, prefix) {
|
31
|
+ processTag($, option) {
|
32
|
let css = [];
|
32
|
let css = [];
|
33
|
|
33
|
|
34
|
// mip-anim
|
34
|
// mip-anim
|
35
|
$('img[src*=".gif"]').each(function() {
|
35
|
$('img[src*=".gif"]').each(function() {
|
36
|
let $this = $(this);
|
36
|
let $this = $(this);
|
37
|
- let mipAnim = `<mip-anim layout="responsive" width="350" height="263" src="${$this.attr('src')}" alt="${$this.attr('alt') || ''}" class="${$this.attr('class') || ''}"></mip-anim>`; // eslint-disable-line
|
37
|
+ let mipAnim = `<mip-anim layout="container" src="${$this.attr('src')}" alt="${$this.attr('alt') || ''}" class="${$this.attr('class') || ''}"></mip-anim>`; // eslint-disable-line
|
38
|
|
38
|
|
39
|
$this.replaceWith(mipAnim);
|
39
|
$this.replaceWith(mipAnim);
|
40
|
});
|
40
|
});
|
|
@@ -50,7 +50,7 @@ module.exports = { |
|
@@ -50,7 +50,7 @@ module.exports = { |
50
|
// mip-video
|
50
|
// mip-video
|
51
|
$('video').each(function() {
|
51
|
$('video').each(function() {
|
52
|
let $this = $(this);
|
52
|
let $this = $(this);
|
53
|
- let mipVideo = `<mip-video layout="responsive" width="350" height="263" poster="${$this.attr('poster') || ''}" src="${$this.attr('src')}" alt="${$this.attr('alt') || ''}" class="${$this.attr('class') || ''}"></mip-video>`; // eslint-disable-line
|
53
|
+ let mipVideo = `<mip-video layout="container" poster="${$this.attr('poster') || ''}" src="${$this.attr('src')}" alt="${$this.attr('alt') || ''}" class="${$this.attr('class') || ''}"></mip-video>`; // eslint-disable-line
|
54
|
|
54
|
|
55
|
$this.replaceWith(mipVideo);
|
55
|
$this.replaceWith(mipVideo);
|
56
|
});
|
56
|
});
|
|
@@ -66,7 +66,7 @@ module.exports = { |
|
@@ -66,7 +66,7 @@ module.exports = { |
66
|
// mip-iframe
|
66
|
// mip-iframe
|
67
|
$('iframe').each(function() {
|
67
|
$('iframe').each(function() {
|
68
|
let $this = $(this);
|
68
|
let $this = $(this);
|
69
|
- let mipIframe = `<mip-iframe layout="responsive" width="350" height="263" src="${$this.attr('src')}" class="${$this.attr('class') || ''}"></mip-iframe>`; // eslint-disable-line
|
69
|
+ let mipIframe = `<mip-iframe layout="container" src="${$this.attr('src')}" class="${$this.attr('class') || ''}"></mip-iframe>`; // eslint-disable-line
|
70
|
|
70
|
|
71
|
$this.replaceWith(mipIframe);
|
71
|
$this.replaceWith(mipIframe);
|
72
|
});
|
72
|
});
|
|
@@ -80,7 +80,7 @@ module.exports = { |
|
@@ -80,7 +80,7 @@ module.exports = { |
80
|
});
|
80
|
});
|
81
|
|
81
|
|
82
|
// mip-link
|
82
|
// mip-link
|
83
|
- if (prefix.mipLint) {
|
83
|
+ if (option.mipLink) {
|
84
|
$('a').each(function() {
|
84
|
$('a').each(function() {
|
85
|
let $this = $(this);
|
85
|
let $this = $(this);
|
86
|
let mipLink = `<a data-type="mip" class="${$this.attr('class') || ''}"
|
86
|
let mipLink = `<a data-type="mip" class="${$this.attr('class') || ''}"
|
|
@@ -107,17 +107,17 @@ module.exports = { |
|
@@ -107,17 +107,17 @@ module.exports = { |
107
|
/**
|
107
|
/**
|
108
|
* 处理 HTML 为 MIP 所需要的格式
|
108
|
* 处理 HTML 为 MIP 所需要的格式
|
109
|
* @param {*} html HTML
|
109
|
* @param {*} html HTML
|
110
|
- * @param {*} prefix CSS 前缀
|
110
|
+ * @param {*} option.prefix CSS 前缀
|
111
|
*/
|
111
|
*/
|
112
|
|
112
|
|
113
|
- process(html = '', prefix = 0) {
|
113
|
+ process(html = '', option = '') {
|
114
|
html = _.isString(html) ? html : '';
|
114
|
html = _.isString(html) ? html : '';
|
115
|
|
115
|
|
116
|
let $ = cheerio.load(html, {
|
116
|
let $ = cheerio.load(html, {
|
117
|
decodeEntities: false
|
117
|
decodeEntities: false
|
118
|
});
|
118
|
});
|
119
|
- let inlineStyle = this.processStyle($, prefix); // 必须先处理内联样式
|
|
|
120
|
- let tagHtml = this.processTag($, prefix);
|
119
|
+ let inlineStyle = this.processStyle($, option); // 必须先处理内联样式
|
|
|
120
|
+ let tagHtml = this.processTag($, option);
|
121
|
|
121
|
|
122
|
return {
|
122
|
return {
|
123
|
mipHtml: tagHtml.mipHtml,
|
123
|
mipHtml: tagHtml.mipHtml,
|