Skip to content

feat: Send token objects to renderers - #3291

Merged
UziTech merged 14 commits into
markedjs:masterfrom
UziTech:renderer-obj
Jun 12, 2024
Merged

UziTech merged 14 commits into
markedjs:masterfrom
UziTech:renderer-obj

Conversation

@UziTech

@UziTech UziTech commented May 15, 2024 •

Copy link
Copy Markdown
Member

Marked version: v12.0.2

Description

  • Send token objects to renderers and move logic to parse tokens from the parser to the renderers.
  • Add parser as a property on the Renderer object
  • Add space renderer that returns empty string by default
  • Send block text tokens to the text renderer
  • Add header and align properties to TableCell token
  • Add TableRow token
  • Add Checkbox token

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

vercel Bot commented May 15, 2024 •

Copy link
Copy Markdown

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 11, 2024 2:07pm

@UziTech
UziTech marked this pull request as ready for review May 16, 2024 06:11
Comment thread docs/USING_PRO.md
align: 'center' || 'left' || 'right'
}
```
The Tokens.* properties can be found [here](https://github.com/markedjs/marked/blob/master/src/Tokens.ts).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
The Tokens.* properties can be found [here](https://github.com/markedjs/marked/blob/master/src/Tokens.ts).
The *Tokens.* properties can be found [here](https://github.com/markedjs/marked/blob/master/src/Tokens.ts).

Is this missing an asterisk to make it italic?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No the star is meant to mean any type in the Tokens namespace. Like Tokens.Code etc.

Comment thread docs/USING_PRO.md
Comment thread src/Renderer.ts
*/
export class _Renderer {
options: MarkedOptions;
parser!: _Parser; // set by the parser

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we set this in the constructor instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No because the Renderer is instantiated before the Parser any time a renderer extension is used. The tokenizer has the same problem with the lexer being set this way.

This problem mostly exists since the Lexer and Parser can be used in a static way marked.lexer(options)

Maybe we can require instance in the future

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we can require instance in the future

That sounds good to me 👍

@UziTech

UziTech commented May 18, 2024

Copy link
Copy Markdown
Member Author

There seems to be a problem with the docs for this change since we use the current marked but a version of marked-highlight that does not support this new renderer parameters.

I think I am going to have to find a way for both to be available for this to work so we can transition extensions.

@UziTech

UziTech commented Jun 10, 2024

Copy link
Copy Markdown
Member Author

I created a temporary option useNewRenderer so extensions can opt in to the new function signature. This should allow most renderer extensions to work without changing ("most" because there are some edge cases that we can't mock).

This temporary option will be removed in a future major version which will break renderer extensions that have not updated to accepting an object.

Logiclayer1111 pushed a commit to Logiclayer1111/marked that referenced this pull request Apr 20, 2026
# [13.0.0](markedjs/marked@v12.0.2...v13.0.0) (2024-06-12)

### Bug Fixes

* blockquote code continuation ([#3264](markedjs/marked#3264)) ([05749a6](markedjs/marked@05749a6))

### Features

* Send token objects to renderers ([#3291](markedjs/marked#3291)) ([6533726](markedjs/marked@6533726))

### BREAKING CHANGES

* extensions that change marked renderers will need to be updated and use new option `useNewRenderer`
* add space token after blockquote and hr if there are multiple newlines
@coderabbitai coderabbitai Bot mentioned this pull request Jun 3, 2026
11 tasks

This branch was successfully deployed

1 active deployment
Preview — b26f7c52 Deployed Jun 11, 2024 by vercel[bot]
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.

Pass token to renderer methods ?

2 participants