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 44 * @typedef {import('../state.js').State } State
55 */
66
7- import { resolve } from '../util/resolve.js'
8-
97/**
108 * @param {State } state
119 * State.
@@ -20,7 +18,7 @@ export function a(state, node) {
2018 /** @type {Link } */
2119 const result = {
2220 type : 'link' ,
23- url : resolve ( state , String ( properties . href || '' ) || null ) ,
21+ url : state . resolve ( String ( properties . href || '' ) || null ) ,
2422 title : properties . title ? String ( properties . title ) : null ,
2523 // @ts -expect-error: assume valid children.
2624 children : state . all ( node )
Original file line number Diff line number Diff line change 44 * @typedef {import('../state.js').State } State
55 */
66
7- import { resolve } from '../util/resolve.js'
8-
97/**
108 * @param {State } state
119 * State.
@@ -28,7 +26,7 @@ export function iframe(state, node) {
2826 const result = {
2927 type : 'link' ,
3028 title : null ,
31- url : resolve ( state , src ) ,
29+ url : state . resolve ( src ) ,
3230 children : [ { type : 'text' , value : title } ]
3331 }
3432 state . patch ( node , result )
Original file line number Diff line number Diff line change 44 * @typedef {import('../state.js').State } State
55 */
66
7- import { resolve } from '../util/resolve.js'
8-
97/**
108 * @param {State } state
119 * State.
@@ -20,7 +18,7 @@ export function img(state, node) {
2018 /** @type {Image } */
2119 const result = {
2220 type : 'image' ,
23- url : resolve ( state , String ( properties . src || '' ) || null ) ,
21+ url : state . resolve ( String ( properties . src || '' ) || null ) ,
2422 title : properties . title ? String ( properties . title ) : null ,
2523 alt : properties . alt ? String ( properties . alt ) : ''
2624 }
Original file line number Diff line number Diff line change 88 */
99
1010import { findSelectedOptions } from '../util/find-selected-options.js'
11- import { resolve } from '../util/resolve.js'
1211
1312const defaultChecked = '[x]'
1413const defaultUnchecked = '[ ]'
@@ -53,7 +52,7 @@ export function input(state, node) {
5352 /** @type {Image } */
5453 const result = {
5554 type : 'image' ,
56- url : resolve ( state , String ( properties . src || '' ) || null ) ,
55+ url : state . resolve ( String ( properties . src || '' ) || null ) ,
5756 title : String ( properties . title || '' ) || null ,
5857 alt : String ( alt )
5958 }
@@ -102,7 +101,7 @@ export function input(state, node) {
102101 let index = - 1
103102
104103 while ( ++ index < values . length ) {
105- const value = resolve ( state , values [ index ] [ 0 ] )
104+ const value = state . resolve ( values [ index ] [ 0 ] )
106105 /** @type {Link } */
107106 const result = {
108107 type : 'link' ,
Original file line number Diff line number Diff line change 99
1010import { toString } from 'mdast-util-to-string'
1111import { visit , EXIT } from 'unist-util-visit'
12- import { resolve } from '../util/resolve.js'
1312import { wrapNeeded } from '../util/wrap.js'
1413
1514/**
@@ -62,7 +61,7 @@ export function media(state, node) {
6261 const image = {
6362 type : 'image' ,
6463 title : null ,
65- url : resolve ( state , poster ) ,
64+ url : state . resolve ( poster ) ,
6665 alt : toString ( nodes )
6766 }
6867 state . patch ( node , image )
@@ -74,7 +73,7 @@ export function media(state, node) {
7473 const result = {
7574 type : 'link' ,
7675 title : properties . title ? String ( properties . title ) : null ,
77- url : resolve ( state , src ) ,
76+ url : state . resolve ( src ) ,
7877 // @ts -expect-error Assume phrasing content.
7978 children : nodes
8079 }
Original file line number Diff line number Diff line change 2121 * Transform the children of a hast parent to mdast.
2222 * @property {One } one
2323 * Transform a hast node to mdast.
24+ * @property {Resolve } resolve
25+ * Resolve a URL relative to a base.
2426 * @property {Options } options
2527 * User configuration.
2628 * @property {Map<string, Element> } elementById
6062 * Parent of `node`.
6163 * @returns {MdastNode | Array<MdastNode> | void }
6264 * 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.
6372 */
6473
6574import { position } from 'unist-util-position'
@@ -79,6 +88,7 @@ export function createState(options) {
7988 /** @type {State } */
8089 const state = {
8190 patch,
91+ resolve,
8292 all,
8393 one,
8494 options,
@@ -197,3 +207,25 @@ function all(parent) {
197207 ? results
198208 : results . slice ( start , end )
199209}
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