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

How to use the out of box rendered result of pre versions on v13. #3373

Closed
Koooooo-7 opened this issue Jul 18, 2024 · 2 comments
Closed

How to use the out of box rendered result of pre versions on v13. #3373

Koooooo-7 opened this issue Jul 18, 2024 · 2 comments
Labels

Comments

@Koooooo-7
Copy link

Koooooo-7 commented Jul 18, 2024

Sorry for delete the issue template since it seems no a suitable place to put in.

Currently, we are doing the v13 adaption from v12.0.2 to v13.0.2.
AFAK, in the v13 changes the renderer to pass the Token directly.
Hence there is no sweet default rendered result to use now. such as the list.
Before the v13, we could use the body directly and it already resolved the list items.

  (renderer.list = (body, ordered, start) => { 
    // body with resolved list items
}

It has auto resolved in marked.

    body += this.listitem({
              type: 'list_item',
              raw: itemBody,
              text: itemBody,
              task,
              checked: !!checked,
              loose,
              tokens: item.tokens
            });
          }

But now, it only has the raw content and we have to render the list items in the renderer.list manually, although it is literally the same behavior as the default renderer.

(renderer.list = function (token) {
    const ordered = token.ordered;
    const start = token.start;
    // manually get the body now
    let body = '';
    for (let j = 0; j < token.items.length; j++) {
      const item = token.items[j];
      body += this.listitem?.(item);
    }
  // now , the body is back
  if (.../.test(body)){
   
}

I found there has a useNewRenderer config for compatibility but it seems gonna be removed in #3342
Is there other way to gain the body same to the versions before v13 without copying the default renderer behaviors?

Thx a lot!

@Koooooo-7 Koooooo-7 changed the title How to use the out of box rendered result of pre-version on v13. How to use the out of box rendered result of pre versions on v13. Jul 18, 2024
@UziTech
Copy link
Member

UziTech commented Jul 19, 2024

short answer, no.

In v13 we moved the logic to render the body from the parser to the renderer functions so users have more control over what data is received in the renderers.

The new renderer style is an opt-in so extensions have time to update. In v14 the old renderers will be removed completely.

@Koooooo-7
Copy link
Author

Koooooo-7 commented Jul 19, 2024

short answer, no.

In v13 we moved the logic to render the body from the parser to the renderer functions so users have more control over what data is received in the renderers.

The new renderer style is an opt-in so extensions have time to update. In v14 the old renderers will be removed completely.

I see.
So in v13+, it gonna bring more flexibilities to let user fully controls the Tokens as a pure Visitor and remove the old renderers. If I wanna the behavior (output) align to old versions, I do need do the implementation by myself in v13 and further versions.

Btw, the old renderer functions act as post processor is useful tho.

Thx!

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

No branches or pull requests

2 participants