summaryrefslogtreecommitdiff
path: root/src/api/common/text/elements/code.ts
blob: 4821e95fe25f2bca349b1e727f2a0e6c3524ca81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/**
 * Code (block)
 */

import genHtml from '../core/syntax-highlighter';

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())
	};
};