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
4 changes: 2 additions & 2 deletions docs/INDEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ DOMPurify.sanitize(marked.parse(`<img src="x" onerror="alert('not happening')">`
**⚠️ Input: special ZERO WIDTH unicode characters (for example `\uFEFF`) might interfere with parsing. Some text editors add them at the start of the file (see: [#2139](https://github.com/markedjs/marked/issues/2139)).**

```js
// remove the most common zerowidth characters from the start of the file
// remove the most common zerowidth characters from the start of the file
marked.parse(
contents.replace(/^[\u200B\u200C\u200D\u200E\u200F\uFEFF]/,"")
)
Expand Down Expand Up @@ -121,7 +121,7 @@ By supporting the above Markdown flavors, it's possible that Marked can help you

<h2 id="tools">List of Tools Using Marked</h2>

We actively support the usability of Marked in super-fast markdown transformation, some of Tools using `Marked` for single-page creations are
We actively support the usability of Marked in super-fast markdown transformation, some of Tools using `Marked` for single-page creations are

| Tools | Description |
| :----------------------------------------------------------------- | :------------------------------------------------------------------------ |
Expand Down
20 changes: 20 additions & 0 deletions docs/USING_ADVANCED.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
## Marked instance

By default marked stores options and extensions in the global scope. In node js when you import marked into two scripts and change the options in one script the options will be changed in the other script.

You can create an instance of marked to keep options and extensions locally scoped.

```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

```

```js
import { marked } from 'marked';
const myMarked = new marked.Instance([...useArgs]);
```

|Argument |Type |Notes |
|:------------------------|:------|:----------------------------------------------------------------------|
|[useArgs](/using_pro#use)|`Array`|The same arguments that can be passed to [`marked.use`](/using_pro#use)|

## The `parse` function

```js
Expand Down
Loading