File tree Expand file tree Collapse file tree 7 files changed +39
-38
lines changed Expand file tree Collapse file tree 7 files changed +39
-38
lines changed Original file line number Diff line number Diff line change 4
4
* @typedef {import('../state.js').State } State
5
5
*/
6
6
7
- import { resolve } from '../util/resolve.js'
8
-
9
7
/**
10
8
* @param {State } state
11
9
* State.
@@ -20,7 +18,7 @@ export function a(state, node) {
20
18
/** @type {Link } */
21
19
const result = {
22
20
type : 'link' ,
23
- url : resolve ( state , String ( properties . href || '' ) || null ) ,
21
+ url : state . resolve ( String ( properties . href || '' ) || null ) ,
24
22
title : properties . title ? String ( properties . title ) : null ,
25
23
// @ts -expect-error: assume valid children.
26
24
children : state . all ( node )
Original file line number Diff line number Diff line change 4
4
* @typedef {import('../state.js').State } State
5
5
*/
6
6
7
- import { resolve } from '../util/resolve.js'
8
-
9
7
/**
10
8
* @param {State } state
11
9
* State.
@@ -28,7 +26,7 @@ export function iframe(state, node) {
28
26
const result = {
29
27
type : 'link' ,
30
28
title : null ,
31
- url : resolve ( state , src ) ,
29
+ url : state . resolve ( src ) ,
32
30
children : [ { type : 'text' , value : title } ]
33
31
}
34
32
state . patch ( node , result )
Original file line number Diff line number Diff line change 4
4
* @typedef {import('../state.js').State } State
5
5
*/
6
6
7
- import { resolve } from '../util/resolve.js'
8
-
9
7
/**
10
8
* @param {State } state
11
9
* State.
@@ -20,7 +18,7 @@ export function img(state, node) {
20
18
/** @type {Image } */
21
19
const result = {
22
20
type : 'image' ,
23
- url : resolve ( state , String ( properties . src || '' ) || null ) ,
21
+ url : state . resolve ( String ( properties . src || '' ) || null ) ,
24
22
title : properties . title ? String ( properties . title ) : null ,
25
23
alt : properties . alt ? String ( properties . alt ) : ''
26
24
}
Original file line number Diff line number Diff line change 8
8
*/
9
9
10
10
import { findSelectedOptions } from '../util/find-selected-options.js'
11
- import { resolve } from '../util/resolve.js'
12
11
13
12
const defaultChecked = '[x]'
14
13
const defaultUnchecked = '[ ]'
@@ -53,7 +52,7 @@ export function input(state, node) {
53
52
/** @type {Image } */
54
53
const result = {
55
54
type : 'image' ,
56
- url : resolve ( state , String ( properties . src || '' ) || null ) ,
55
+ url : state . resolve ( String ( properties . src || '' ) || null ) ,
57
56
title : String ( properties . title || '' ) || null ,
58
57
alt : String ( alt )
59
58
}
@@ -102,7 +101,7 @@ export function input(state, node) {
102
101
let index = - 1
103
102
104
103
while ( ++ index < values . length ) {
105
- const value = resolve ( state , values [ index ] [ 0 ] )
104
+ const value = state . resolve ( values [ index ] [ 0 ] )
106
105
/** @type {Link } */
107
106
const result = {
108
107
type : 'link' ,
Original file line number Diff line number Diff line change 9
9
10
10
import { toString } from 'mdast-util-to-string'
11
11
import { visit , EXIT } from 'unist-util-visit'
12
- import { resolve } from '../util/resolve.js'
13
12
import { wrapNeeded } from '../util/wrap.js'
14
13
15
14
/**
@@ -62,7 +61,7 @@ export function media(state, node) {
62
61
const image = {
63
62
type : 'image' ,
64
63
title : null ,
65
- url : resolve ( state , poster ) ,
64
+ url : state . resolve ( poster ) ,
66
65
alt : toString ( nodes )
67
66
}
68
67
state . patch ( node , image )
@@ -74,7 +73,7 @@ export function media(state, node) {
74
73
const result = {
75
74
type : 'link' ,
76
75
title : properties . title ? String ( properties . title ) : null ,
77
- url : resolve ( state , src ) ,
76
+ url : state . resolve ( src ) ,
78
77
// @ts -expect-error Assume phrasing content.
79
78
children : nodes
80
79
}
Original file line number Diff line number Diff line change 21
21
* Transform the children of a hast parent to mdast.
22
22
* @property {One } one
23
23
* Transform a hast node to mdast.
24
+ * @property {Resolve } resolve
25
+ * Resolve a URL relative to a base.
24
26
* @property {Options } options
25
27
* User configuration.
26
28
* @property {Map<string, Element> } elementById
60
62
* Parent of `node`.
61
63
* @returns {MdastNode | Array<MdastNode> | void }
62
64
* mdast result.
65
+ *
66
+ * @callback Resolve
67
+ * Resolve a URL relative to a base.
68
+ * @param {string | null | undefined } url
69
+ * Possible URL value.
70
+ * @returns {string }
71
+ * URL, resolved to a `base` element, if any.
63
72
*/
64
73
65
74
import { position } from 'unist-util-position'
@@ -79,6 +88,7 @@ export function createState(options) {
79
88
/** @type {State } */
80
89
const state = {
81
90
patch,
91
+ resolve,
82
92
all,
83
93
one,
84
94
options,
@@ -197,3 +207,25 @@ function all(parent) {
197
207
? results
198
208
: results . slice ( start , end )
199
209
}
210
+
211
+ /**
212
+ * @this {State}
213
+ * Info passed around about the current state.
214
+ * @param {string | null | undefined } url
215
+ * Possible URL value.
216
+ * @returns {string }
217
+ * URL, resolved to a `base` element, if any.
218
+ */
219
+ export function resolve ( url ) {
220
+ const base = this . frozenBaseUrl
221
+
222
+ if ( url === null || url === undefined ) {
223
+ return ''
224
+ }
225
+
226
+ if ( base ) {
227
+ return String ( new URL ( url , base ) )
228
+ }
229
+
230
+ return url
231
+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments