Skip to content

Allow extension to activate in MDX files#759

Merged
yzhang-gh merged 3 commits into
yzhang-gh:masterfrom
thomaskoppelaar:master
Jul 23, 2020
Merged

Allow extension to activate in MDX files#759
yzhang-gh merged 3 commits into
yzhang-gh:masterfrom
thomaskoppelaar:master

Conversation

@thomaskoppelaar

Copy link
Copy Markdown
Contributor

Allows for the extension to work within MDX files.

Caveat: The "Print current page to HTML" command won't properly convert MDX into HTML; It will treat the document as markdown.

@thomaskoppelaar

Copy link
Copy Markdown
Contributor Author

I don't speak Japanese nor Chinese, so those translations will need to be edited (they're currently English).

@thomaskoppelaar

Copy link
Copy Markdown
Contributor Author

I'm also unsure as to why the first test fails on the CI, I've run the tests locally to check if they still work + I've not modified anything specific to that function.

@yzhang-gh

Copy link
Copy Markdown
Owner

I don't speak Japanese nor Chinese, so those translations will need to be edited (they're currently English).

No worries. We can rely on other users who would like to help 🤣.

I'm also unsure as to why the first test fails on the CI, I've run the tests locally to check if they still work + I've not modified anything specific to that function.

Sometimes it fails because of "time-out".

Many thanks!

@yzhang-gh yzhang-gh merged commit 10e0777 into yzhang-gh:master Jul 23, 2020

@Lemmingh Lemmingh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid injectTo is only valid under the grammars contribution point, which is designed to extend an existing grammar in a specific scope. And it only works when injectionSelector is declared properly in the TM grammar.

See also https://github.com/microsoft/vscode/blob/85d983391a3c1ff65db6746b8c6994ec0833b3d8/src/vs/workbench/services/textMate/common/TMGrammars.ts


Link #758

Comment thread package.json
Comment on lines +94 to +231
"when": "editorTextFocus && !editorReadonly",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.editing.toggleItalic",
"key": "ctrl+i",
"mac": "cmd+i",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown"
"when": "editorTextFocus && !editorReadonly",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.editing.toggleStrikethrough",
"key": "alt+s",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !isMac"
"when": "editorTextFocus && !editorReadonly && !isMac",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.editing.toggleHeadingUp",
"key": "ctrl+shift+]",
"mac": "ctrl+shift+]",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown"
"when": "editorTextFocus && !editorReadonly",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.editing.toggleHeadingDown",
"key": "ctrl+shift+[",
"mac": "ctrl+shift+[",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown"
"when": "editorTextFocus && !editorReadonly",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.editing.toggleMath",
"key": "ctrl+m",
"mac": "cmd+m",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown"
"when": "editorTextFocus && !editorReadonly",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.onEnterKey",
"key": "enter",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible && vim.mode != 'Normal' && vim.mode != 'Visual' && vim.mode != 'VisualBlock' && vim.mode != 'VisualLine' && vim.mode != 'SearchInProgressMode' && vim.mode != 'CommandlineInProgress' && vim.mode != 'Replace' && vim.mode != 'EasyMotionMode' && vim.mode != 'EasyMotionInputMode' && vim.mode != 'SurroundInputMode'"
"when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible && vim.mode != 'Normal' && vim.mode != 'Visual' && vim.mode != 'VisualBlock' && vim.mode != 'VisualLine' && vim.mode != 'SearchInProgressMode' && vim.mode != 'CommandlineInProgress' && vim.mode != 'Replace' && vim.mode != 'EasyMotionMode' && vim.mode != 'EasyMotionInputMode' && vim.mode != 'SurroundInputMode'",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.onCtrlEnterKey",
"key": "ctrl+enter",
"mac": "cmd+enter",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible"
"when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.onShiftEnterKey",
"key": "shift+enter",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible"
"when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.onTabKey",
"key": "tab",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible && !editorTabMovesFocus && !inSnippetMode && !hasSnippetCompletions && !hasOtherSuggestions"
"when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible && !editorTabMovesFocus && !inSnippetMode && !hasSnippetCompletions && !hasOtherSuggestions",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.onShiftTabKey",
"key": "shift+tab",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible && !editorTabMovesFocus && !inSnippetMode && !hasSnippetCompletions && !hasOtherSuggestions"
"when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible && !editorTabMovesFocus && !inSnippetMode && !hasSnippetCompletions && !hasOtherSuggestions",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.onBackspaceKey",
"key": "backspace",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible && vim.mode != 'Normal' && vim.mode != 'Visual' && vim.mode != 'VisualBlock' && vim.mode != 'VisualLine' && vim.mode != 'SearchInProgressMode' && vim.mode != 'CommandlineInProgress' && vim.mode != 'Replace' && vim.mode != 'EasyMotionMode' && vim.mode != 'EasyMotionInputMode' && vim.mode != 'SurroundInputMode'"
"when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible && vim.mode != 'Normal' && vim.mode != 'Visual' && vim.mode != 'VisualBlock' && vim.mode != 'VisualLine' && vim.mode != 'SearchInProgressMode' && vim.mode != 'CommandlineInProgress' && vim.mode != 'Replace' && vim.mode != 'EasyMotionMode' && vim.mode != 'EasyMotionInputMode' && vim.mode != 'SurroundInputMode'",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.onMoveLineUp",
"key": "alt+up",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible"
"when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.onMoveLineDown",
"key": "alt+down",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible"
"when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.onCopyLineUp",
"key": "shift+alt+up",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible"
"when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.onCopyLineDown",
"key": "shift+alt+down",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible"
"when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.onIndentLines",
"key": "ctrl+]",
"mac": "cmd+]",
"when": "editorTextFocus && editorLangId == markdown && !suggestWidgetVisible"
"when": "editorTextFocus && !suggestWidgetVisible",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.onOutdentLines",
"key": "ctrl+[",
"mac": "cmd+[",
"when": "editorTextFocus && editorLangId == markdown && !suggestWidgetVisible"
"when": "editorTextFocus && !suggestWidgetVisible",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.checkTaskList",
"key": "alt+c",
"when": "editorTextFocus && editorLangId == markdown"
"when": "editorTextFocus",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.togglePreview",
"key": "ctrl+shift+v",
"mac": "cmd+shift+v",
"when": "!terminalFocus"
"when": "!terminalFocus",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.togglePreviewToSide",
"key": "ctrl+k v",
"mac": "cmd+k v",
"when": "!terminalFocus"
"when": "!terminalFocus",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.editing.paste",
"key": "ctrl+v",
"mac": "cmd+v",
"when": "editorTextFocus && editorLangId == markdown && editorHasSelection"
"when": "editorTextFocus && editorHasSelection",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread package.json
Comment on lines +425 to +434
"text.html.markdown",
"text.html.markdown.jsx"
]
},
{
"scopeName": "markdown.math_inline",
"path": "./syntaxes/math_inline.markdown.tmLanguage.json",
"injectTo": [
"text.html.markdown"
"text.html.markdown",
"text.html.markdown.jsx"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be nothing about LaTeX in JSX. Is it correct to inject them to text.html.markdown.jsx scope?

Comment thread package.json
Comment on lines +440 to +443
"injectTo": [
"text.html.markdown",
"text.html.markdown.jsx"
]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot understand this change.


{
    "scopeName": "text.katex",
    "path": "./syntaxes/katex.tmLanguage.json"
}

was intended to simply import the TM grammar, because math_display.markdown.tmLanguage.json and math_inline.markdown.tmLanguage.json reference text.katex scope.

I think there should be no need to inject it into any scope.

Comment thread src/util.ts

/** Scheme `File` or `Untitled` */
export const mdDocSelector = [{ language: 'markdown', scheme: 'file' }, { language: 'markdown', scheme: 'untitled' }];
export const mdDocSelector = [{ language: 'markdown', scheme: 'file' }, { language: 'markdown', scheme: 'untitled' }, { language: 'mdx', scheme: 'file' }, { language: 'mdx', scheme: 'file' }];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why twice?

@yzhang-gh

Copy link
Copy Markdown
Owner

I'm afraid injectTo is only valid under the grammars contribution point, which is designed to extend an existing grammar in a specific scope. And it only works when injectionSelector is declared properly in the TM grammar.

@Lemmingh Thanks for the important information! I thought embedded language support had been implemented 😅 (see microsoft/vscode#1751) so I didn't check.

@thomaskoppelaar I have to revert this PR as this extension now activates in all documents (e.g. json). Probably we can have a better solution later.

@Lemmingh

Copy link
Copy Markdown
Collaborator

embedded language support

Yeah. The universal solution doesn't exist yet. And I'm not optimistic about it, given the complexity of designing a universal way to declare matching pattern and algorithm, and related mechanisms.

However, "hardcoded" embedded language support have been available for a long time. The VS Code team encourages extensions to adopt it with examples for both declarative and programmatic language features.

Opinions from Matt Bierner:
https://twitter.com/mattbierner/status/1017118184699133952
microsoft/vscode#71888 (comment)

@thomaskoppelaar

Copy link
Copy Markdown
Contributor Author

@Lemmingh thank you for the feedback and clarification! Like you said, I misunderstood the way injectTo works.

@Lemmingh Lemmingh linked an issue Dec 22, 2020 that may be closed by this pull request
@Lemmingh Lemmingh added the Res: Invalid This does not seem right, or contain any valid or useful information. It's discarded. label Jan 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Res: Invalid This does not seem right, or contain any valid or useful information. It's discarded.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggestion: Allow extension to work within MDX files

3 participants