Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Parser } from "simple-text-parser";
- const parser = new Parser()
- parser.addRule(/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/, (mail: string) => {
- return `<a href="mailto:${mail}">${mail}</a>`
- })
- parser.addRule(/(\(?\+?\d{1,3}\)?[\s-]*)?\(?\d{1,3}\)?[\s-]*\d{3}[\s-]?\d{2}[\s-]?\d{2}/g, (tel: string) => {
- return `<a href="tel:${tel}">${tel}</a>`
- })
- export function parseTextLinks(html: string) {
- console.log(html)
- console.log(parser.render(html))
- return parser.render(html)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement