markedjs / marked

A markdown parser and compiler. Built for speed.
https://marked.js.org
Other
32.32k stars 3.36k forks source link

table function in renderer not outputting valid token #3350

Closed alsoicode closed 1 week ago

alsoicode commented 1 week ago

Marked version:

13.0.1

Describe the bug

When providing a custom renderer to override the table output, the token value passed to the function does not contain header or rows data.

To Reproduce Steps to reproduce the behavior:

Add a custom renderer:

const renderer = {
  table(token: Tokens.Table): string {
    return `
      <table class="table table-striped">
      <thead>${ token.header }</thead>
      <tbody>${ token.rows }</tbody>
      </table>
    `;
  }
 };

marked.use({ renderer });

When provided with sample data:

| Key | Value |\n| ---- | ----- |\n| A | 1 |\n| B | 2 |\n| C | 3 |

The value of token is:

<tr>
<th>Key</th>
<th>Value</th>
</tr>

No other properties on the token object are populated and the value is a string, not an object.

Expected behavior

A token object would have been returned, not a string.

UziTech commented 1 week ago

See https://marked.js.org/using_pro#renderer

You have to use marked.use({ useNewRenderer: true, renderer }); for v13 to use new token renderers.