Advertisement
zodiak1

Untitled

Nov 2nd, 2022
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. import { Parser } from "simple-text-parser";
  2.  
  3. const parser = new Parser()
  4.  
  5. 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) => {
  6. return `<a href="mailto:${mail}">${mail}</a>`
  7. })
  8. parser.addRule(/(\(?\+?\d{1,3}\)?[\s-]*)?\(?\d{1,3}\)?[\s-]*\d{3}[\s-]?\d{2}[\s-]?\d{2}/g, (tel: string) => {
  9. return `<a href="tel:${tel}">${tel}</a>`
  10. })
  11.  
  12. export function parseTextLinks(html: string) {
  13. console.log(html)
  14. console.log(parser.render(html))
  15. return parser.render(html)
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement