Skip to content

How to render table to process later? #3409

Answered by ivanjaros
ivanjaros asked this question in Q&A
Discussion options

You must be logged in to vote

OK, I figured it out:

  const tableTransformer = {
    table(...rows) {
      let header = rows.shift()
      return `<script rel="table" type="application/json">{"header":${header.slice(0, -1)},"rows":[${rows.join(",").slice(0, -1)}]}</script>`
    },
    tablerow(token) {
      return '['+token.slice(0, -1)+'],'
    },
    tablecell(token, flags) {
      // there is also flags.header boolean, but we always assume first row is header
      // and we are not rendering the <td>/<th> tags in here, so we can ignore it.
      return JSON.stringify({cell: token, align: flags.align}) + ","
    }
  }

  md.use({ renderer: tableTransformer})

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@ivanjaros
Comment options

@ivanjaros
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by ivanjaros
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants