Skip to content

baseUrl with relative prefix not working as expected. #1466

@mjhenkes

Description

@mjhenkes

Describe the bug
For usage in github pages I'd like to use the baseUrl option to add a prefix of the project name for relative links. For instance with a github pages site like matt.github.io/derp with derp being the project name. I'd like relative links to change from /link to /derp/link.

Marked options

const options = {
    baseUrl: '/derp/',
}

Markdown

![alt text](/favicon.ico "relative")'

Output html

<p><img src="/derp/favicon.ico" alt="alt text" title="relative"></p>

What is actually happening is:

<p><img src="/derp//favicon.ico" alt="alt text" title="relative"></p>

Maybe it is as simple as not inverting rtrim here:
https://github.com/markedjs/marked/blob/master/lib/marked.js#L1417

To Reproduce
This code sandbox should show the issue. Check the console
https://codesandbox.io/s/9ql03o5114

I was able to reproduce this in both 0.5.0 and 0.6.2.

Expected behavior
I expect html output to look like this:

<p><img src="/derp/favicon.ico" alt="alt text" title="relative"></p>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions