Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
unidocs-uni-app-x-zh
提交
d4dba8fa
U
unidocs-uni-app-x-zh
项目概览
DCloud
/
unidocs-uni-app-x-zh
通知
144
Star
2
Fork
33
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
9
列表
看板
标记
里程碑
合并请求
11
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
unidocs-uni-app-x-zh
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
9
Issue
9
列表
看板
标记
里程碑
合并请求
11
合并请求
11
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
d4dba8fa
编写于
4月 24, 2024
作者:
D
DCloud_LXH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: inject-json-to-md 使用新的方式
上级
9356d903
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
152 addition
and
156 deletion
+152
-156
docs/.vuepress/markdown/inject-json-to-md.js
docs/.vuepress/markdown/inject-json-to-md.js
+152
-156
未找到文件。
docs/.vuepress/markdown/inject-json-to-md.js
浏览文件 @
d4dba8fa
let
cssJson
=
{}
;
let
utsJson
=
{}
;
let
utsApiJson
=
{}
;
let
utsComJson
=
{}
;
let
utsUnicloudApiJson
=
{}
;
let
customTypeJson
=
{}
;
let
vueJson
=
{}
;
let
manifestJson
=
{}
;
let
pagesJson
=
{}
;
let
specialStringJson
=
{}
;
let
pageInstanceJson
=
{}
;
let
cssJson
=
{}
let
utsJson
=
{}
let
utsApiJson
=
{}
let
utsComJson
=
{}
let
utsUnicloudApiJson
=
{}
let
customTypeJson
=
{}
let
vueJson
=
{}
let
manifestJson
=
{}
let
pagesJson
=
{}
let
specialStringJson
=
{}
let
pageInstanceJson
=
{}
try
{
cssJson
=
require
(
'
../utils/cssJson.json
'
);
cssJson
=
require
(
'
../utils/cssJson.json
'
)
}
catch
(
error
)
{}
try
{
utsJson
=
require
(
'
../utils/utsJson.json
'
);
utsJson
=
require
(
'
../utils/utsJson.json
'
)
}
catch
(
error
)
{}
try
{
utsApiJson
=
require
(
'
../utils/utsApiJson.json
'
);
utsApiJson
=
require
(
'
../utils/utsApiJson.json
'
)
}
catch
(
error
)
{}
try
{
utsComJson
=
require
(
'
../utils/utsComJson.json
'
);
utsComJson
=
require
(
'
../utils/utsComJson.json
'
)
}
catch
(
error
)
{}
try
{
utsUnicloudApiJson
=
require
(
'
../utils/utsUnicloudApiJson.json
'
);
utsUnicloudApiJson
=
require
(
'
../utils/utsUnicloudApiJson.json
'
)
}
catch
(
error
)
{}
try
{
customTypeJson
=
require
(
'
../utils/customTypeJson.json
'
);
customTypeJson
=
require
(
'
../utils/customTypeJson.json
'
)
}
catch
(
error
)
{}
try
{
vueJson
=
require
(
'
../utils/vueJson.json
'
);
vueJson
=
require
(
'
../utils/vueJson.json
'
)
}
catch
(
error
)
{}
try
{
manifestJson
=
require
(
'
../utils/maniFestJson.json
'
);
manifestJson
=
require
(
'
../utils/manifestJson.json
'
)
}
catch
(
error
)
{}
try
{
pagesJson
=
require
(
'
../utils/pagesJson.json
'
);
pagesJson
=
require
(
'
../utils/pagesJson.json
'
)
}
catch
(
error
)
{}
try
{
specialStringJson
=
require
(
'
../utils/specialStringJson.json
'
);
specialStringJson
=
require
(
'
../utils/specialStringJson.json
'
)
}
catch
(
error
)
{}
try
{
pageInstanceJson
=
require
(
'
../utils/pageInstanceJson.json
'
);
pageInstanceJson
=
require
(
'
../utils/pageInstanceJson.json
'
)
}
catch
(
error
)
{}
function
getRegExp
(
key
)
{
return
new
RegExp
(
`<!--\\s*
${
key
}
.([\\w\\W]+[^\\s])\\s*-->`
)
return
new
RegExp
(
`<!--\\s*
${
key
}
.([\\w\\W]+[^\\s])\\s*-->`
)
}
/**
*
* @param {string} text
* @returns {{match: RegExpMatchArray | null, json: {}}
*/
const
getJSON
=
text
=>
{
let
match
=
text
.
match
(
getRegExp
(
'
CSSJSON
'
));
if
(
match
)
{
return
{
match
,
json
:
cssJson
,
};
}
match
=
text
.
match
(
getRegExp
(
'
UTSJSON
'
));
if
(
match
)
{
return
{
match
,
json
:
utsJson
,
};
}
match
=
text
.
match
(
getRegExp
(
'
UTSAPIJSON
'
));
if
(
match
)
{
return
{
match
,
json
:
utsApiJson
,
};
}
match
=
text
.
match
(
getRegExp
(
'
UTSCOMJSON
'
));
if
(
match
)
{
return
{
match
,
json
:
utsComJson
,
};
}
match
=
text
.
match
(
getRegExp
(
'
UTSUNICLOUDAPIJSON
'
));
if
(
match
)
{
return
{
match
,
json
:
utsUnicloudApiJson
,
};
}
match
=
text
.
match
(
getRegExp
(
'
CUSTOMTYPEJSON
'
));
if
(
match
)
{
return
{
match
,
json
:
customTypeJson
,
};
}
match
=
text
.
match
(
getRegExp
(
'
VUEJSON
'
));
if
(
match
)
{
return
{
match
,
json
:
vueJson
,
};
}
match
=
text
.
match
(
getRegExp
(
'
MANIFESTJSON
'
));
if
(
match
)
{
return
{
match
,
json
:
manifestJson
,
};
}
match
=
text
.
match
(
getRegExp
(
'
PAGESJSON
'
));
if
(
match
)
{
return
{
match
,
json
:
pagesJson
,
};
}
match
=
text
.
match
(
getRegExp
(
'
SPECIALSTRINGJSON
'
));
if
(
match
)
{
return
{
match
,
json
:
specialStringJson
,
};
}
match
=
text
.
match
(
getRegExp
(
'
PAGEINSTANCE
'
));
if
(
match
)
{
return
{
match
,
json
:
pageInstanceJson
,
};
}
return
{
match
:
null
,
json
:
{},
};
};
module
.
exports
=
function
(
md
,
opts
)
{
if
(
Object
.
keys
(
cssJson
)
===
0
)
return
false
;
md
.
core
.
ruler
.
after
(
'
inline
'
,
'
merge-css
'
,
function
(
state
)
{
const
ids
=
[]
let
idIdx
=
1
for
(
let
index
=
0
;
index
<
state
.
tokens
.
length
;
index
++
)
{
const
blockToken
=
state
.
tokens
[
index
];
if
(
blockToken
.
type
===
'
html_block
'
)
{
const
{
match
,
json
}
=
getJSON
(
blockToken
.
content
);
if
(
match
)
{
const
jsonPath
=
match
[
1
];
const
path
=
jsonPath
.
split
(
'
.
'
);
let
temp
=
json
;
path
.
forEach
(
key
=>
{
if
(
!
temp
)
return
false
;
temp
=
temp
[
key
];
});
if
(
!
temp
)
continue
;
const
parseTokens
=
md
.
parse
(
temp
);
parseTokens
.
forEach
(
token
=>
{
if
(
token
.
type
===
'
heading_open
'
)
{
const
id
=
token
.
attrGet
(
'
id
'
)
if
(
ids
.
includes
(
id
))
{
token
.
attrSet
(
'
id
'
,
`
${
id
}
_
${
idIdx
++
}
`
)
}
else
{
ids
.
push
(
id
)
}
}
})
state
.
tokens
.
splice
(
index
,
1
,
...
parseTokens
);
index
=
index
+
parseTokens
.
length
-
1
;
// blockToken.content = temp
}
}
}
return
false
;
});
};
let
match
=
text
.
match
(
getRegExp
(
'
CSSJSON
'
))
if
(
match
)
{
return
{
match
,
json
:
cssJson
,
}
}
match
=
text
.
match
(
getRegExp
(
'
UTSJSON
'
))
if
(
match
)
{
return
{
match
,
json
:
utsJson
,
}
}
match
=
text
.
match
(
getRegExp
(
'
UTSAPIJSON
'
))
if
(
match
)
{
return
{
match
,
json
:
utsApiJson
,
}
}
match
=
text
.
match
(
getRegExp
(
'
UTSCOMJSON
'
))
if
(
match
)
{
return
{
match
,
json
:
utsComJson
,
}
}
match
=
text
.
match
(
getRegExp
(
'
UTSUNICLOUDAPIJSON
'
))
if
(
match
)
{
return
{
match
,
json
:
utsUnicloudApiJson
,
}
}
match
=
text
.
match
(
getRegExp
(
'
CUSTOMTYPEJSON
'
))
if
(
match
)
{
return
{
match
,
json
:
customTypeJson
,
}
}
match
=
text
.
match
(
getRegExp
(
'
VUEJSON
'
))
if
(
match
)
{
return
{
match
,
json
:
vueJson
,
}
}
match
=
text
.
match
(
getRegExp
(
'
MANIFESTJSON
'
))
if
(
match
)
{
return
{
match
,
json
:
manifestJson
,
}
}
match
=
text
.
match
(
getRegExp
(
'
PAGESJSON
'
))
if
(
match
)
{
return
{
match
,
json
:
pagesJson
,
}
}
match
=
text
.
match
(
getRegExp
(
'
SPECIALSTRINGJSON
'
))
if
(
match
)
{
return
{
match
,
json
:
specialStringJson
,
}
}
match
=
text
.
match
(
getRegExp
(
'
PAGEINSTANCE
'
))
if
(
match
)
{
return
{
match
,
json
:
pageInstanceJson
,
}
}
return
{
match
:
null
,
json
:
{},
}
}
const
NEWLINE_CHARACTER
=
/
\r?\n
/
module
.
exports
=
md
=>
{
md
.
parse
=
(
function
(
MD_PARSE
)
{
return
function
(
src
,
...
args
)
{
if
(
src
&&
getJSON
(
src
).
match
)
{
const
lines
=
src
.
split
(
NEWLINE_CHARACTER
)
for
(
let
index
=
0
;
index
<
lines
.
length
;
index
++
)
{
const
line
=
lines
[
index
]
const
{
match
,
json
}
=
getJSON
(
line
)
if
(
match
)
{
const
jsonPath
=
match
[
1
]
const
path
=
jsonPath
.
split
(
'
.
'
)
let
temp
=
json
path
.
forEach
(
key
=>
{
if
(
!
temp
)
return
false
temp
=
temp
[
key
]
})
if
(
!
temp
)
continue
lines
[
index
]
=
temp
}
}
return
MD_PARSE
.
bind
(
this
)(
lines
.
join
(
'
\n
'
),
...
args
)
}
return
MD_PARSE
.
bind
(
this
)(
src
,
...
args
)
}
})(
md
.
parse
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录