pablo-abc / svelte-markdown

Markdown parser to svelte components
MIT License
360 stars 50 forks source link

feat: support rendering from pre-processed tokens #53

Closed 0E9B061F closed 2 years ago

0E9B061F commented 2 years ago

Adds support for passing an array of tokens as the source option. This allows the user to generate and transform tokens freely before rendering. It also obviates the need for walkTokens support (#39). Users needing this feature can lex the tokens themselves.

Any array given as source is assumed to be an array of tokens. If the source is not an array it is assumed to be a string and is treated normally.

A simple test is included.

0E9B061F commented 2 years ago

This would also allow users to use different markdown parsers, at least in theory, supposing the tokens are in the same format, or can be coerced to be. Possibly even parsers for different markup languages (I'm contemplating creating a small language with peggy and rendering its tokens using svelte-markdown, if this feature is added).

pablo-abc commented 2 years ago

This actually looks great! Allows for extra flexibility without compromising on bundle size (or the original API)!

Could you also update the types on types/index.d.ts? It'd be perfect that way.

0E9B061F commented 2 years ago

I gave it a shot but I'm not very familiar with typescript. You should double check that.

0E9B061F commented 2 years ago

Added documentation of the feature to the readme, too.

0E9B061F commented 2 years ago

No problem! Glad to help.