Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dealing with changing baseUrls #129

Closed
georggrab opened this issue Sep 27, 2023 · 2 comments
Closed

Dealing with changing baseUrls #129

georggrab opened this issue Sep 27, 2023 · 2 comments

Comments

@georggrab
Copy link

Hi guys,

first of all, thanks for marked, it's awesome.
I'm in the process of upgrading a personal app from "marked": "^1.2.8",, and it's easy sailing, except for the thing where the baseUrl option was removed from the main parsing function (markedjs/marked#2936).

My app has changing baseUrls depending on the document I'm trying to parse. With the previous atomic formulation marked(doc, {baseUrl: theBaseUrlOfDoc}), this was no problem, but I have some issues incorporating the new way of doing things, which I guess amounts to marked.use(baseUrl(theBaseUrlOfDoc)) followed by marked.parse(doc). It's like the new baseUrl is not applied properly and multiple (updating) calls marked.use are not supported.

Can you point me in the right direction with regards to upgrading this usecase to your changed plugin-based API? Any hints greatly appreciated. For now, I'm stuck upgrading to ^7 which doesn't have this breaking change.

Cheers, Georg

@UziTech
Copy link
Member

UziTech commented Sep 28, 2023

You can create a Marked instance when you create a new baseUrl

import { Marked } from 'marked';
import {baseUrl} from "marked-base-url";

for (const doc of docs) {
  const marked = new Marked(baseUrl(doc.baseUrl));
  const html = marked.parse(doc.markdown);
}

@georggrab
Copy link
Author

Welp, that solves it of course! I was ignorant of the fact that Marked instances were a thing.
Thanks a lot, @UziTech !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants