Skip to content

Enable fragment for non-code #1973

@brandonchinn178

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) {
const fragment = token.embed.fragment;
const pattern = new RegExp(
`(?:###|\\/\\/\\/)\\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

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