Sharkey/src/common/text/elements/code.js

18 lines
360 B
JavaScript
Raw Normal View History

2017-02-09 01:07:06 +09:00
/**
* Code (block)
2017-02-09 01:07:06 +09:00
*/
const genHtml = require('../core/syntax-highlighter');
2017-02-11 02:32:00 +09:00
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(),
html: genHtml(code.substr(3, code.length - 6).trim())
2017-02-11 02:32:00 +09:00
};
2017-02-09 01:07:06 +09:00
};