Sharkey/src/text/parse/elements/code.ts

18 lines
355 B
TypeScript
Raw Normal View History

2017-02-09 01:07:06 +09:00
/**
* Code (block)
2017-02-09 01:07:06 +09:00
*/
2017-03-18 20:05:11 +09:00
import genHtml from '../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
};