yumechi-no-kuni/src/text/parse/elements/link.ts

28 lines
513 B
TypeScript
Raw Normal View History

2017-03-17 11:16:32 -05:00
/**
* Link
*/
2018-06-17 05:55:39 -05:00
export type TextElementLink = {
type: "link"
content: string
title: string
url: string
silent: boolean
};
export default function(text: string) {
2017-03-17 14:20:25 -05:00
const match = text.match(/^\??\[([^\[\]]+?)\]\((https?:\/\/[\w\/:%#@\$&\?!\(\)\[\]~\.=\+\-]+?)\)/);
2017-03-17 11:16:32 -05:00
if (!match) return null;
const silent = text[0] == '?';
const link = match[0];
const title = match[1];
const url = match[2];
return {
type: 'link',
content: link,
title: title,
url: url,
silent: silent
2018-06-17 05:55:39 -05:00
} as TextElementLink;
}