Refactoring ✨
This commit is contained in:
parent
c20cd97be2
commit
1b2d080651
6 changed files with 52 additions and 68 deletions
|
@ -2,19 +2,16 @@
|
|||
* Code
|
||||
*/
|
||||
|
||||
const regexp = /```([\s\S]+?)```/;
|
||||
|
||||
module.exports = {
|
||||
test: x => new RegExp('^' + regexp.source).test(x),
|
||||
parse: text => {
|
||||
const code = text.match(new RegExp('^' + regexp.source))[0];
|
||||
return {
|
||||
type: 'code',
|
||||
content: code,
|
||||
code: code.substr(3, code.length - 6).trim(),
|
||||
codeHtml: genHtml(code.substr(3, code.length - 6).trim())
|
||||
};
|
||||
}
|
||||
module.exports = text => {
|
||||
const match = text.match(/^```([\s\S]+?)```/);
|
||||
if (!match) return null;
|
||||
const code = match[0];
|
||||
return {
|
||||
type: 'code',
|
||||
content: code,
|
||||
code: code.substr(3, code.length - 6).trim(),
|
||||
codeHtml: genHtml(code.substr(3, code.length - 6).trim())
|
||||
};
|
||||
};
|
||||
|
||||
function escape(text) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue