oast-to-hast 4.5.2 → 4.5.3

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.
Files changed (2) hide show
  1. package/lib/state.js +16 -1
  2. package/package.json +1 -1
package/lib/state.js CHANGED
@@ -54,7 +54,7 @@ export function createState(_tree, options = {}) {
54
54
  linkTarget: '_self',
55
55
  selectTags: [],
56
56
  excludeTags: ['noexport'],
57
- linkHref: (link) => link.path.value,
57
+ linkHref: defaultLinkHref,
58
58
  ...options
59
59
  }
60
60
  }
@@ -121,6 +121,21 @@ export function createState(_tree, options = {}) {
121
121
  }
122
122
  }
123
123
 
124
+ /**
125
+ * @param {import('orga').Link} link
126
+ * @returns {string}
127
+ */
128
+ function defaultLinkHref(link) {
129
+ const protocol = link.path.protocol
130
+ if (!protocol || protocol === 'internal' || protocol === 'file') {
131
+ return link.path.value
132
+ }
133
+ if (protocol === 'http' || protocol === 'https') {
134
+ return link.path.value
135
+ }
136
+ return `${protocol}:${link.path.value}`
137
+ }
138
+
124
139
  /** @type {Handler} */
125
140
  function unkownHandler(state, node) {
126
141
  if (node?.children) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oast-to-hast",
3
- "version": "4.5.2",
3
+ "version": "4.5.3",
4
4
  "description": "Transform OAST to HAST",
5
5
  "files": [
6
6
  "lib",