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

Update USING_PRO.md #3492

Merged
merged 4 commits into from
Oct 20, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions docs/USING_ADVANCED.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,31 @@ const marked = new Marked([options, extension, ...]);
|:--------|:-------|:----------------------------------------------------------------------|
| options |`object`|The same arguments that can be passed to [`marked.use`](/using_pro#use)|

Another case is, if you want to rerun function everytime they open a file, or you want to make marked.run() non-state, you can create a new instance of Marked to ensure options and extensions are locally scoped.
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't seem like this is saying anything more than the documentation above. That the user should use Marked instance if they want extensions to be locally scoped.

I think the example should emphasize that marked.use(...) should not be used in a loop or function. It should only be used directly after new Marked is created or marked is imported


```js
import { Marked } from 'marked';
const marked = new Marked();
// Override function
const walkTokens = (token) => {
if (token.type === 'heading') {
token.depth += 1;
}
};

marked.use({ walkTokens });

// Run marked
console.log(marked.parse('# heading 2\n\n## heading 3'));
```

**Output:**

```html
<h2 id="heading-2">heading 2</h2>
<h3 id="heading-3">heading 3</h3>
```

## The `parse` function

```js
Expand Down