-
-
Notifications
You must be signed in to change notification settings - Fork 726
feat: variable binding #1266
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
Merged
Merged
feat: variable binding #1266
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/runtime/markdown-parser/remark-mdc/micromark-extension/tokenize-binding.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import type { Effects, State, Code, TokenizeContext } from 'micromark-util-types' | ||
| import { Codes } from './constants' | ||
|
|
||
| function attempClose (this: TokenizeContext, effects: Effects, ok: State, nok: State) { | ||
| return start | ||
|
|
||
| function start (code: Code) { | ||
| if (code !== Codes.closingCurlyBracket) { | ||
| return nok(code) | ||
| } | ||
| effects.exit('bindingContent') | ||
| effects.enter('bindingFence') | ||
| effects.consume(code) | ||
| return secondBracket | ||
| } | ||
|
|
||
| function secondBracket (code: Code) { | ||
| if (code !== Codes.closingCurlyBracket) { | ||
| return nok(code) | ||
| } | ||
| effects.consume(code) | ||
| effects.exit('bindingFence') | ||
|
|
||
| return ok | ||
| } | ||
| } | ||
|
|
||
| function tokenize (this: TokenizeContext, effects: Effects, ok: State, nok: State) { | ||
| return start | ||
|
|
||
| function start (code: Code): void | State { | ||
| if (code !== Codes.openingCurlyBracket) { | ||
| throw new Error('expected `{`') | ||
| } | ||
|
|
||
| effects.enter('bindingFence') | ||
| effects.consume(code) | ||
| return secondBracket | ||
| } | ||
|
|
||
| function secondBracket (code: Code): void | State { | ||
| if (code !== Codes.openingCurlyBracket) { | ||
| return nok(code) | ||
| } | ||
| effects.consume(code) | ||
| effects.exit('bindingFence') | ||
| effects.enter('bindingContent') | ||
|
|
||
| return content | ||
| } | ||
|
|
||
| function content (code: Code): void | State { | ||
| if (code === Codes.closingCurlyBracket) { | ||
| return effects.attempt({ tokenize: attempClose, partial: true }, close, (code) => { | ||
| effects.consume(code) | ||
| return content | ||
| })(code) | ||
| } | ||
|
|
||
| effects.consume(code) | ||
| return content | ||
| } | ||
|
|
||
| function close (code: Code): void | State { | ||
| return ok(code) | ||
| } | ||
| } | ||
|
|
||
| export default { | ||
| tokenize | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { describe, test, expect } from 'vitest' | ||
| import { $fetch } from '@nuxt/test-utils' | ||
|
|
||
| const content = `--- | ||
| title: MDC | ||
| cover: https://nuxtjs.org/design-kit/colored-logo.svg | ||
| --- | ||
| :img{:src="cover"} | ||
|
|
||
| # {{ $doc.title }} | ||
|
|
||
| MDC stands for _**M**ark**D**own **C**omponents_. | ||
|
|
||
| This syntax supercharges regular Markdown to write documents interacting deeply with any Vue component from your \`components/content/\` directory or provided by a module. | ||
|
|
||
| ## Next steps | ||
| - [Install Nuxt Content](/get-started) | ||
| - [Explore the MDC syntax](/guide/writing/mdc) | ||
|
|
||
|
|
||
| You are visiting document: {{ $doc._id }}. | ||
| Current route is: {{ $route.path }} | ||
|
|
||
|
|
||
| ::alert | ||
| --- | ||
| type: success | ||
| --- | ||
| This is an alert for {{ type }} | ||
| :: | ||
|
|
||
| ::alert{type="danger"} | ||
| This is an alert for {{ type }} | ||
| :: | ||
|
|
||
| ` | ||
|
|
||
| export const testMarkdownRenderer = () => { | ||
| describe('renderer:markdown', () => { | ||
| test('bindings', async () => { | ||
| const rendered = await $fetch('/parse', { | ||
| params: { | ||
| content | ||
| } | ||
| }) | ||
|
|
||
| expect(rendered).toContain('<img src="https://nuxtjs.org/design-kit/colored-logo.svg" alt>') | ||
|
|
||
| expect(rendered).toContain('<h1 id><!--[-->MDC<!--]--></h1>') | ||
| expect(rendered).toContain('You are visiting document: content:index.md.') | ||
| expect(rendered).toContain('Current route is: /parse') | ||
| expect(rendered).toContain('This is an alert for success') | ||
| expect(rendered).toContain('This is an alert for danger') | ||
| }) | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <template> | ||
| <div> | ||
| <MarkdownRenderer :value="data" /> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script setup> | ||
| const { content } = useRoute().query | ||
| const { data } = await useAsyncData(content, async () => { | ||
| return await $fetch('/api/parse', { | ||
| method: 'POST', | ||
| cors: true, | ||
| body: { | ||
| id: 'content:index.md', | ||
| content | ||
| } | ||
| }) | ||
| }) | ||
| </script> |
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.
Uh oh!
There was an error while loading. Please reload this page.