Sharkey/src/mfm/parse/elements/inline-code.ts

26 lines
482 B
TypeScript
Raw Normal View History

2017-02-11 23:41:57 +09:00
/**
* Code (inline)
*/
2017-03-18 20:05:11 +09:00
import genHtml from '../core/syntax-highlighter';
2018-06-17 19:55:39 +09:00
export type TextElementInlineCode = {
2018-06-18 14:28:43 +09:00
type: 'inline-code'
2018-06-17 19:55:39 +09:00
content: string
code: string
html: string
};
export default function(text: string) {
2017-02-11 23:41:57 +09:00
const match = text.match(/^`(.+?)`/);
if (!match) return null;
2018-08-15 20:23:50 +09:00
if (match[1].includes('´')) return null;
2017-02-11 23:41:57 +09:00
const code = match[0];
return {
type: 'inline-code',
content: code,
2018-08-15 20:23:50 +09:00
code: match[1],
html: genHtml(match[1])
2018-06-17 19:55:39 +09:00
} as TextElementInlineCode;
}