Skip to content

Enable fragment for non-code #1973

Description

@brandonchinn178

Feature request

It seems like the "Embed code fragments" feature only works for code, but it would be nice to generalize it to include rendered Markdown.

What problem does this feature solve?

I would like to generate a single file with a bunch of snippets like:

/// [chunk1]
<p>Chunk 1</p>
/// [chunk1]
/// [chunk2]
<p>Chunk 2</p>
/// [chunk2]

And then in the relevant page, be able to do

[chunk](./chunks.md':include :fragment=chunk1')

What does the proposed API look like?

See above

How should this be implemented in your opinion?

Break out this block into a function resolveFragment(token, text: string) => string

if(token.embed.fragment){
constfragment=token.embed.fragment;
constpattern=newRegExp(
`(?:###|\\/\\/\\/)\\s*\\[${fragment}\\]([\\s\\S]*)(?:###|\\/\\/\\/)\\s*\\[${fragment}\\]`
);
text=stripIndent((text.match(pattern)||[])[1]||'').trim();
}

Call the function in every conditional block immediately before passing text to embedToken

Are you willing to work on this yourself?

Sure

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions