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

Support for chunked rendering #3315

Closed
calculuschild opened this issue Jun 7, 2024 · 1 comment · Fixed by #3424
Closed

Support for chunked rendering #3315

calculuschild opened this issue Jun 7, 2024 · 1 comment · Fixed by #3424
Labels

Comments

@calculuschild
Copy link
Contributor

calculuschild commented Jun 7, 2024

What pain point are you perceiving?.
Following the PR proposed in Marked-GFM-Headings: markedjs/marked-gfm-heading-id#543, there is a notion of Marked sometimes being used in a "chunked" manner, i.e., parsing individual pages out of a longer document. This can be handy for live-editing services for example, where realtime updating of the rendered output may become slow for very large documents, instead re-parsing only the current page for speed.

Chunking can be done external to marked, by manually handling, say, an array of markdown source chunks and an array of output HTML chunks and updating each array entry as needed. However, difficulties arise when knowledge of the complete document is needed, for example for reflinks, where a link defined in a later chunk may be referenced in a prior one. The PR in Marked-GfM-Headings has a similar intent of ensuring globally-unique header IDs across chunks.

Describe the solution you'd like
I don't know exactly how this would work (or if it is already possible), but I'm picturing some kind of method of marking certain data as persistent across chunks, with some knowledge of which chunk it came from so it can be updated as needed. Marked would also need some way to communicate which chunk is currently being rendered.

For example: the lexer.tokens.links object would need an option to be made persistent across chunks, and perhaps label each link entry with a chunk ID so if that same chunk is re-rendered (perhaps a reflink is removed), it can be properly updated for the global list.

It would be nice to have a set template for this type of object so extensions, etc. can have a common interface for cross-chunk support.

@UziTech
Copy link
Member

UziTech commented Jun 9, 2024

Maybe we could add a hook that can change the Lexer before it is used.

let links;

processLexer(lexer) {
  lexer.tokens.links = links;
  return lexer;
}
processAllTokens(tokens) {
  links = tokens.links;;
}

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

Successfully merging a pull request may close this issue.

2 participants