-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: inline text attributes with
[]{}
syntax (#471)
* feat: inline text attributes with `[]{}` syntax * docs: add text attributes syntax * Update docs/content/2.writing/2.syntax.md Co-authored-by: Sébastien Chopin <[email protected]> * fix: cleanup & typo Co-authored-by: Sébastien Chopin <[email protected]>
- Loading branch information
Showing
7 changed files
with
114 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 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
13 changes: 10 additions & 3 deletions
13
src/core/parser/markdown/directive/micromark-directive/index.ts
This file contains 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 |
---|---|---|
@@ -1,17 +1,24 @@ | ||
// https://github.com/micromark/micromark-extension-directive/blob/main/lib/syntax.js | ||
|
||
import directiveSpan from './tokenize-directive-span' | ||
import directiveInline from './tokenize-directive-inline' | ||
import directiveContainer from './tokenize-directive-container' | ||
import directiveContainerIndented from './tokenize-directive-container-indented' | ||
import { Codes } from './constants' | ||
|
||
export default function directive() { | ||
return { | ||
text: { 58: directiveInline }, | ||
flow: { 58: [directiveContainer, directiveInline] }, | ||
text: { | ||
[Codes.colon]: directiveInline, | ||
[Codes.openingSquareBracket]: [directiveSpan] | ||
}, | ||
flow: { | ||
[Codes.colon]: [directiveContainer, directiveInline] | ||
}, | ||
flowInitial: { | ||
'-2': directiveContainerIndented, | ||
'-1': directiveContainerIndented, | ||
32: directiveContainerIndented | ||
[Codes.space]: directiveContainerIndented | ||
} | ||
} | ||
} |
This file contains 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 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
66 changes: 66 additions & 0 deletions
66
src/core/parser/markdown/directive/micromark-directive/tokenize-directive-span.ts
This file contains 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,66 @@ | ||
import { Effects, Okay, NotOkay } from 'micromark/dist/shared-types' | ||
import { Codes } from './constants' | ||
import createAttributes from './factory-attributes' | ||
import createLabel from './factory-label' | ||
|
||
const label: any = { tokenize: tokenizeLabel, partial: true } | ||
const attributes: any = { tokenize: tokenizeAttributes, partial: true } | ||
|
||
function tokenize(effects: Effects, ok: Okay, nok: NotOkay) { | ||
return start | ||
|
||
function start(code: number) { | ||
if (code !== Codes.openingSquareBracket) { | ||
throw new Error('expected `[`') | ||
} | ||
|
||
effects.enter('directiveTextSpan') | ||
return effects.attempt(label, afterLabel, nok)(code) | ||
} | ||
|
||
function afterLabel(code: number) { | ||
// Check for attributes after label | ||
if (code === Codes.openingCurlyBracket) { | ||
return effects.attempt(attributes, exit, nok)(code) | ||
} | ||
return nok(code) | ||
} | ||
|
||
function exit(code: number) { | ||
effects.exit('directiveTextSpan') | ||
return ok(code) | ||
} | ||
} | ||
|
||
/** | ||
* Labels starts with `[` and ends with `]` | ||
*/ | ||
function tokenizeLabel(effects: Effects, ok: Okay, nok: NotOkay) { | ||
return createLabel(effects, ok, nok, 'directiveTextLabel', 'directiveTextLabelMarker', 'directiveTextLabelString') | ||
} | ||
|
||
/** | ||
* Attributes starts with `{` and ends with `}` | ||
*/ | ||
function tokenizeAttributes(effects: Effects, ok: Okay, nok: NotOkay) { | ||
return createAttributes( | ||
effects, | ||
ok, | ||
nok, | ||
'directiveTextAttributes', | ||
'directiveTextAttributesMarker', | ||
'directiveTextAttribute', | ||
'directiveTextAttributeId', | ||
'directiveTextAttributeClass', | ||
'directiveTextAttributeName', | ||
'directiveTextAttributeInitializerMarker', | ||
'directiveTextAttributeValueLiteral', | ||
'directiveTextAttributeValue', | ||
'directiveTextAttributeValueMarker', | ||
'directiveTextAttributeValueData' | ||
) | ||
} | ||
|
||
export default { | ||
tokenize | ||
} |
This file contains 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
c7cb42b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nuxtjs-with-docus – ./
nuxtjs.docus.com
nuxtjs-with-docus-git-dev-nuxtlabs.vercel.app
nuxtjs-with-docus-nuxtlabs.vercel.app
nuxtjs-with-docus.vercel.app