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

Added support for embedding fragments with <!-- [fragment] --> syntax #830

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/embed-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Sometimes you don't want to embed a whole file. Maybe because you need just a fe
```

In your code file you need to surround the fragment between `/// [demo]` lines (before and after the fragment).
Alternatively you can use `### [demo]`.
Alternatively you can use `### [demo]` or `<!-- [demo] -->`.

Example:

Expand Down
5 changes: 2 additions & 3 deletions src/core/render/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ function walkFetchEmbed({ embedTokens, compile, fetch }, cb) {
} else if (token.embed.type === 'code') {
if (token.embed.fragment) {
const fragment = token.embed.fragment;
const pattern = new RegExp(
`(?:###|\\/\\/\\/)\\s*\\[${fragment}\\]([\\s\\S]*)(?:###|\\/\\/\\/)\\s*\\[${fragment}\\]`
);
const marker = `(?:(?:(?:###|\\/\\/\\/)\\s*\\[${fragment}\\])|(?:<!--\\s*\\[${fragment}\\]\\s*-->))`;
const pattern = new RegExp(`${marker}([\\s\\S]*)${marker}`);
text = stripIndent((text.match(pattern) || [])[1] || '').trim();
}

Expand Down