Skip to content

Commit

Permalink
fix(plugins/plugin-client-common): replay against files with relative…
Browse files Browse the repository at this point in the history
… image links fail to load image
  • Loading branch information
starpit committed Feb 2, 2022
1 parent efb7d35 commit 04e78b8
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@ function allContentIsRemote(props: Props): boolean {
function handleImage(mdprops: Props, props: ImgProps, key?: string) {
let { src } = props

const isHttp = /^http/i.test(src)
const baseUrlIsHttp = mdprops.baseUrl && /http/i.test(mdprops.baseUrl)
const srcIsHttp = /^http/i.test(src)
const isHttp = srcIsHttp || baseUrlIsHttp
const isLocal = !isHttp && !allContentIsRemote(mdprops)

if (isLocal) {
const absoluteSrc = isAbsolute(src)
? src
: join(mdprops.fullpath ? dirname(mdprops.fullpath) : mdprops.baseUrl || process.cwd(), src)
src = absoluteSrc
} else if (!isHttp && mdprops.baseUrl) {
// then this is a relative path against
src = `${mdprops.baseUrl}${!/\/$/.test(mdprops.baseUrl) ? '/' : ''}${src}`
} else if (!srcIsHttp && mdprops.baseUrl) {
src = mdprops.baseUrl.replace(/{filename}/g, src)
}

const style = props && props.align ? { float: props.align } : undefined
Expand Down

0 comments on commit 04e78b8

Please sign in to comment.