mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-30 02:58:05 +08:00
修复 tinymce sdk css 问题
This commit is contained in:
parent
5d588da47e
commit
34fc9dd094
@ -1,31 +1,38 @@
|
||||
/* eslint-disable */
|
||||
|
||||
var rLinkScript = /(<!(?:--)?\[[\s\S]*?<\!\[endif\](?:--)?>|<!--[\s\S]*?(?:-->|$))|(?:(\s*<script([^>]*)>([\s\S]*?)<\/script>)|(?:\s*(<link([^>]*?)(?:\/)?>)|(<style([^>]*)>([\s\S]*?)<\/style>)))(<!--ignore-->)?\n?/ig;
|
||||
var rLinkScript = /(<!(?:--)?\[[\s\S]*?<\!\[endif\](?:--)?>|<!--[\s\S]*?(?:-->|$))|(?:(\s*<script([^>]*)>([\s\S]*?)<\/script>)|(?:\s*(<link([^>]*?)(?:\/)?>)|(<style([^>]*)>([\s\S]*?)<\/style>)))(<!--ignore-->)?\n?/gi;
|
||||
var rScriptType = /type=('|")(.*?)\1/i;
|
||||
var rSrcHref = /\s*(?:src|href)=('|")(.+?)\1/i;
|
||||
var rRefStyle = /rel=('|")stylesheet\1/i;
|
||||
var path = require('path');
|
||||
var css = require('css');
|
||||
var rSourceMap = /(?:\/\/\#\s*sourceMappingURL[^\r\n\'\"]*|\/\*\#\s*sourceMappingURL[^\r\n\'\"]*\*\/)(?:\r?\n|$)/ig;
|
||||
var rSourceMap = /(?:\/\/\#\s*sourceMappingURL[^\r\n\'\"]*|\/\*\#\s*sourceMappingURL[^\r\n\'\"]*\*\/)(?:\r?\n|$)/gi;
|
||||
var caches = {};
|
||||
var createResource = fis.require('postpackager-loader/lib/resource.js');
|
||||
|
||||
function prefixCss(code, prefix) {
|
||||
var cssAst = css.parse(code);
|
||||
prefixNode(cssAst);
|
||||
return css.stringify(cssAst) + '\n' + prefix + '{background-color: #f0f3f4;position: relative;} \n' + prefix + ' .app {padding-bottom:0;}';
|
||||
return (
|
||||
css.stringify(cssAst) +
|
||||
'\n' +
|
||||
prefix +
|
||||
'{background-color: #f0f3f4;position: relative;} \n' +
|
||||
prefix +
|
||||
' .app {padding-bottom:0;}'
|
||||
);
|
||||
|
||||
function prefixSelector(sel){
|
||||
function prefixSelector(sel) {
|
||||
if (sel.match(/^@/)) return sel;
|
||||
var m = sel.match(/(^| )(body|html)($|\W.*)/i);
|
||||
if (m)
|
||||
return m[1] + prefix + m[3];
|
||||
if (m) return m[1] + prefix + m[3];
|
||||
else if (sel.match(/^\.is\-modalOpened/))
|
||||
return sel.replace(/^\.is\-modalOpened\s/, '.is-modalOpened ' + prefix + ' ')
|
||||
else if (sel.match(/^(?:\.fr-|\.fa)/))
|
||||
return sel;
|
||||
else
|
||||
return prefix + ' ' + sel;
|
||||
return sel.replace(
|
||||
/^\.is\-modalOpened\s/,
|
||||
'.is-modalOpened ' + prefix + ' '
|
||||
);
|
||||
else if (sel.match(/^(?:\.fr-|\.fa|\.tox)/)) return sel;
|
||||
else return prefix + ' ' + sel;
|
||||
}
|
||||
|
||||
function prefixNode(node) {
|
||||
@ -40,12 +47,15 @@ function prefixCss(code, prefix) {
|
||||
}
|
||||
|
||||
function unicodeJs(str) {
|
||||
return str.replace(/([\u4E00-\u9FA5]|[\uFE30-\uFFA0]|[\u2019])/g, function(_, value){
|
||||
return str.replace(/([\u4E00-\u9FA5]|[\uFE30-\uFFA0]|[\u2019])/g, function(
|
||||
_,
|
||||
value
|
||||
) {
|
||||
return '\\u' + value.charCodeAt(0).toString(16);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = function (ret, pack, settings, opt) {
|
||||
module.exports = function(ret, pack, settings, opt) {
|
||||
var root = fis.project.getProjectPath();
|
||||
|
||||
var tpl = ret.pkg['/examples/sdk-placeholder.html'];
|
||||
@ -66,13 +76,25 @@ module.exports = function (ret, pack, settings, opt) {
|
||||
var resource = tpl._resource;
|
||||
|
||||
var files = ret.pkg;
|
||||
Object.keys(files).forEach(function (subpath) {
|
||||
Object.keys(files).forEach(function(subpath) {
|
||||
var file = files[subpath];
|
||||
|
||||
mapping[file.getUrl()] = file;
|
||||
});
|
||||
|
||||
contents.replace(rLinkScript, function (all, comment, script, attrs, body, link, lattrs, style, sattrs, sbody, ignored) {
|
||||
contents.replace(rLinkScript, function(
|
||||
all,
|
||||
comment,
|
||||
script,
|
||||
attrs,
|
||||
body,
|
||||
link,
|
||||
lattrs,
|
||||
style,
|
||||
sattrs,
|
||||
sbody,
|
||||
ignored
|
||||
) {
|
||||
// 忽略注释。
|
||||
if (comment || ignored) {
|
||||
return all;
|
||||
@ -84,7 +106,9 @@ module.exports = function (ret, pack, settings, opt) {
|
||||
let file = resource.getFileByUrl(src);
|
||||
|
||||
if (!file) {
|
||||
file = resource.getFileByUrl(fis.util(path.join(path.dirname(tpl.release), src)));
|
||||
file = resource.getFileByUrl(
|
||||
fis.util(path.join(path.dirname(tpl.release), src))
|
||||
);
|
||||
}
|
||||
|
||||
if (!file) {
|
||||
@ -103,7 +127,11 @@ module.exports = function (ret, pack, settings, opt) {
|
||||
} catch (e) {
|
||||
d = (/((?:https?|file)\:.*)$/.test(e.stack) && RegExp.$1).replace(/\\/[^\\/]*$/, '');
|
||||
}
|
||||
${contents.replace(/\"url\"\s*\:\s*('|")(\.\/.*)\1/g, function(_, quote, value) {
|
||||
${contents.replace(/\"url\"\s*\:\s*('|")(\.\/.*)\1/g, function(
|
||||
_,
|
||||
quote,
|
||||
value
|
||||
) {
|
||||
return `"url": d + ${quote}${value.substring(1)}${quote}`;
|
||||
})}
|
||||
})()`;
|
||||
@ -111,8 +139,13 @@ module.exports = function (ret, pack, settings, opt) {
|
||||
|
||||
jsContents += contents + ';\n';
|
||||
}
|
||||
|
||||
} else if (script && !rScriptType.test(attrs) || rScriptType.test(attrs) && ~['text/javascript', 'application/javascript'].indexOf(RegExp.$2.toLowerCase())) {
|
||||
} else if (
|
||||
(script && !rScriptType.test(attrs)) ||
|
||||
(rScriptType.test(attrs) &&
|
||||
~['text/javascript', 'application/javascript'].indexOf(
|
||||
RegExp.$2.toLowerCase()
|
||||
))
|
||||
) {
|
||||
entryJs += ';' + body;
|
||||
all = '';
|
||||
} else if (link && rRefStyle.test(lattrs) && rSrcHref.test(lattrs)) {
|
||||
@ -120,14 +153,15 @@ module.exports = function (ret, pack, settings, opt) {
|
||||
let file = resource.getFileByUrl(href);
|
||||
|
||||
if (!file) {
|
||||
file = resource.getFileByUrl(fis.util(path.join(path.dirname(tpl.release), href)));
|
||||
file = resource.getFileByUrl(
|
||||
fis.util(path.join(path.dirname(tpl.release), href))
|
||||
);
|
||||
}
|
||||
|
||||
if (!file) {
|
||||
file = mapping[href];
|
||||
}
|
||||
|
||||
|
||||
if (file) {
|
||||
cssContents += '\n' + file.getContent();
|
||||
file.skiped = true;
|
||||
|
Loading…
Reference in New Issue
Block a user