yumechi-no-kuni/src/common/text/elements/link.js

20 lines
369 B
JavaScript
Raw Normal View History

2017-03-17 11:16:32 -05:00
/**
* Link
*/
module.exports = text => {
2017-03-17 12:28:31 -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
};
};