1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-02 19:05:55 +02:00
Files
misskey/src/mfm/parse/elements/url.ts

21 lines
335 B
TypeScript

/**
* URL
*/
export type TextElementUrl = {
type: 'url'
content: string
url: string
};
export default function(text: string) {
const match = text.match(/^https?:\/\/[\w\/:%#@\$&\?!\(\)\[\]~\.=\+\-]+/);
if (!match) return null;
const url = match[0];
return {
type: 'url',
content: url,
url: url
} as TextElementUrl;
}