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

21 lines
367 B
TypeScript
Raw Normal View History

2018-02-27 12:32:01 +09:00
/**
* Quoted text
*/
2018-06-17 19:55:39 +09:00
export type TextElementQuote = {
type: "quote"
content: string
quote: string
};
export default function(text: string) {
2018-02-27 12:32:01 +09:00
const match = text.match(/^"([\s\S]+?)\n"/);
if (!match) return null;
const quote = match[0];
return {
type: 'quote',
content: quote,
quote: quote.substr(1, quote.length - 2).trim(),
2018-06-17 19:55:39 +09:00
} as TextElementQuote;
}