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

feat: add Marked instance #2831

Merged
merged 13 commits into from
Jun 10, 2023
Merged

feat: add Marked instance #2831

merged 13 commits into from
Jun 10, 2023

Conversation

UziTech
Copy link
Member

@UziTech UziTech commented Jun 5, 2023

Description

Add import { Marked } from 'marked' to get an instance of marked that will not change global options when options are changed or extensions are added.

import { Marked } from 'marked';
const marked = new Marked(options); // or new marked.Instance(options)
marked.use(extension);

marked.parse(markdown);

This initial parameters are passed to use so you can add options or extensions.

const marked = new Marked(
  options,
  extension1,
  extension2
)

// same as

const marked = new Marked();
marked.use(
  options,
  extension1,
  extension2
);

import { marked } from 'marked' still works the way it always has by updating global options.

Contributor

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR); or,
  • no tests required for this PR.
  • If submitting new feature, it has been documented in the appropriate places.

Committer

In most cases, this should be a different person than the contributor.

@vercel
Copy link

vercel bot commented Jun 5, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
marked-website ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 8, 2023 8:14pm

docs/USING_ADVANCED.md Outdated Show resolved Hide resolved

```js
import { Marked } from 'marked';
const marked = new Marked([...useArgs]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be an array? The tests make it seems like its an object, not array.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor can take any number of options objects just like the use function. The square brackets mean it is optional. I know it is a weird way of writing that but that is how we indicate optional arguments in other parts of the docs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated it to be more informative

docs/USING_ADVANCED.md Outdated Show resolved Hide resolved
Copy link
Contributor

@calculuschild calculuschild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve after @styfle 's points get addressed.

Co-authored-by: Steven <steven@ceriously.com>
Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks! 🎉

Perhaps we can move toward a future were we deprecate and remove the old marked that mutates global state in favor of this new class instance 👍

@UziTech UziTech merged commit 353e13b into markedjs:master Jun 10, 2023
github-actions bot pushed a commit that referenced this pull request Jun 10, 2023
# [5.1.0](v5.0.5...v5.1.0) (2023-06-10)

### Bug Fixes

* Simplify unicode punctuation ([#2841](#2841)) ([f19fe76](f19fe76))

### Features

* add Marked instance ([#2831](#2831)) ([353e13b](353e13b))
@vorant94
Copy link

when is it expected to get 5.1.0 version of @types/marked to use instance-based marked in typescript?

sebastinez added a commit to radicle-dev/radicle-interface that referenced this pull request Jul 17, 2023
Based on a new addition to marked, this commits replaces the imported
marked namespaces with a Marked class, that doesn't change when
`marked.use` introduces new options or extensions.

Also changes the naming slighty to use `markdown` as module, so it
sounds more generic.

Reference: markedjs/marked#2831

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
sebastinez added a commit to radicle-dev/radicle-interface that referenced this pull request Jul 17, 2023
Based on a new addition to marked, this commits replaces the imported
marked namespaces with a Marked class, that doesn't change when
`marked.use` introduces new options or extensions.

Also changes the naming slighty to use `markdown` as module, so it
sounds more generic.

Reference: markedjs/marked#2831

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
sebastinez added a commit to radicle-dev/radicle-interface that referenced this pull request Jul 17, 2023
Based on a new addition to marked, this commits replaces the imported
marked namespaces with a Marked class, that doesn't change when
`marked.use` introduces new options or extensions.

Also changes the naming slighty to use `markdown` as module, so it
sounds more generic.

Reference: markedjs/marked#2831

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
@UziTech UziTech deleted the instance branch August 26, 2023 03:23
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

Successfully merging this pull request may close these issues.

Setting options interferes with other "require"-calls to marked.
4 participants