test1/src/mfm/parse/elements/inline-code.ts
2018-11-03 22:38:12 +09:00

26 lines
486 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Code (inline)
*/
import genHtml from '../core/syntax-highlighter';
export type TextElementInlineCode = {
type: 'inline-code';
content: string;
code: string;
html: string;
};
export default function(text: string) {
const match = text.match(/^`(.+?)`/);
if (!match) return null;
if (match[1].includes('´')) return null;
const code = match[0];
return {
type: 'inline-code',
content: code,
code: match[1],
html: genHtml(match[1])
} as TextElementInlineCode;
}