rehype-og-card 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -43,18 +43,18 @@ const rehypeOGCard = (options) => {
43
43
  visitParents(tree, ["element", "text"], (node, ancestors) => {
44
44
  var _a;
45
45
  let anchorNode = null;
46
- if (node.type === "text" && isValidURL(node.value.trim())) {
46
+ const isBareLink = node.type === "text" && isValidURL(node.value.trim());
47
+ const isValidAnchor = isAnchorElement(node) && isValidURL(node.properties.href);
48
+ if (isBareLink) {
47
49
  anchorNode = convertTextToAnchorElement(node);
48
50
  }
49
- else if (mergedOptions.enableSameTextURLConversion &&
50
- isAnchorElement(node) &&
51
- isValidURL(node.properties.href)) {
52
- const isBareLink =
51
+ else if (mergedOptions.enableSameTextURLConversion && isValidAnchor) {
52
+ const isSameTextURL =
53
53
  // eslint-disable-next-line no-magic-numbers
54
54
  node.children.length === 1 &&
55
55
  isTextNode(node.children[0]) &&
56
56
  node.children[0].value === node.properties.href;
57
- if (!isBareLink)
57
+ if (!isSameTextURL)
58
58
  return;
59
59
  anchorNode = node;
60
60
  }
package/dist/util.js CHANGED
@@ -31,9 +31,10 @@ const isAnchorElement = (node) => Boolean(node) && isElement(node, "a") && "href
31
31
  * @returns `true` if the URL is valid, `false` otherwise.
32
32
  */
33
33
  const isValidURL = (url) => {
34
+ const ALLOWED_PROTOCOLS = ["http:", "https:"];
34
35
  try {
35
- new URL(url);
36
- return true;
36
+ const { protocol } = new URL(url);
37
+ return ALLOWED_PROTOCOLS.includes(protocol.toLowerCase());
37
38
  }
38
39
  catch (_a) {
39
40
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rehype-og-card",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Rehype plugin to convert text links to link cards",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",