UNPKG

js-markdown

Version:
43 lines (37 loc) 942 B
/** * match a auto link * * String between "<" and ">" must be a valid url. * * syntax like this: * * <http://hello.world> * */ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; function parse(str, children, renderTree) { var result = str.match(/^<(?:((https?|ftp|mailto):[^>]+)|(.*?@.*?\.[a-zA-Z]+))>/); if (!result) { return; } return [{ type: 'AutoLink', href: result[3] ? 'mailto:' + result[3] : result[1], rawValue: result[3] ? result[3] : result[1] }, result[0].length]; } function render() { var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; var node = arguments.length > 1 ? arguments[1] : undefined; var href = node.rawValue || ''; return "<a href=\"".concat(href, "\">").concat(href).concat(data, "</a>"); } var _default = { parse: parse, render: render }; exports["default"] = _default;