barkey/src/api/common/text/elements/link.ts
syuilo 45e8331e26 🍣
Closes #12, #227 and #58
2017-03-18 20:05:11 +09:00

19 lines
370 B
TypeScript

/**
* Link
*/
module.exports = text => {
const match = text.match(/^\??\[([^\[\]]+?)\]\((https?:\/\/[\w\/:%#@\$&\?!\(\)\[\]~\.=\+\-]+?)\)/);
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
};
};