Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe the PR
This PR sets up a system to clean up how we implement demos/examples in our docs.
unplugin-vue-components
to clean up the import statements in both the demos and the *.md files.unplugin-vue-components
to auto-register the demo components in markdown files, which removes the need to do any fancy footwork with adding import statements to the *.md files for those components.Take a look at
breadcrumb.md
for an example of how this has cleaned up the markdown.At this point, I believe the system is unambiguously better than it is currently. It's still set up so that we can incrementally move over to the new system and still use the old system if there are snippets that are small enough that we don't think it's necessary to have an external demo file.
I'm open to feedback on naming conventions/file structure for the demo files, but aside from that I believe this is ready to commit.
Background Info
I'm pretty frustrated with how the demos/examples in our docs work. There are two full copies of the code, one of which is split between the place where the demo is and the main
script
block and neither gets autoformatted correctly. I've looked at a number ofmarkdown-it
plugins but none seem to be well used or supported and I couldn't get any to work. The closest one I found was https://github.com/hairyf/markdown-it-vitepress-demo - I think it would do what I want if it worked, but it doesn't.That sent me down the path of looking at what vitepress supports. They do support pulling a code snippet from a SFC file.
That solves the duplicate code + code formatting issue nicely. It does have the downside of having a bunch of little demo files floating around, but all of the solutions I've found do that.
It's also more verbose than I'd like.
I dug into vitepress' snippet plugin and found it pretty readable. I pulled that apart and rewrote their rule to let me do something like this:
It also still supports all of the line hightling, etc. that the vitepress snippet plugin does and doesn't interfere with the original plugin (it just has to run first, which it does).
I'm pretty happy with this solution. I'd like to take the time to see if I can get rid of the explicit import of the component and then I'd like to move forward with it. It has the advantage that it peacefully coexists with the existing system so I can convert over docs as I go through them for the parity pass.
Questions for @VividLemon:
fence
render rule, but would rather not if you're all right with things as they are. This is also something that we can play with going forward if we go down this path, doesn't have to be solved on the initial round.Small replication
N/A
PR checklist
What kind of change does this PR introduce? (check at least one)
fix(...)
feat(...)
fix(...)
docs(...)
The PR fulfills these requirements:
CHANGELOG
is generated from these messages, and determines the next version type. Pull requests that do not follow conventional commits or do not have an override will be denied