diff --git a/extensions/markdown-language-features/package.json b/extensions/markdown-language-features/package.json
index d8232ce2219..5f8c24cd63a 100644
--- a/extensions/markdown-language-features/package.json
+++ b/extensions/markdown-language-features/package.json
@@ -135,6 +135,11 @@
"title": "%markdown.openImage.title%",
"category": "Markdown"
},
+ {
+ "command": "_markdown.openFrontMatterSettings",
+ "title": "%markdown.openFrontMatterSettings.title%",
+ "category": "Markdown"
+ },
{
"command": "markdown.showPreview",
"title": "%markdown.preview.title%",
@@ -221,6 +226,10 @@
{
"command": "_markdown.openImage",
"when": "(webviewId == 'markdown.preview' || webviewId == 'vscode.markdown.preview.editor') && webviewSection == 'localImage'"
+ },
+ {
+ "command": "_markdown.openFrontMatterSettings",
+ "when": "(webviewId == 'markdown.preview' || webviewId == 'vscode.markdown.preview.editor') && webviewSection == 'frontMatter'"
}
],
"editor/title": [
diff --git a/extensions/markdown-language-features/package.nls.json b/extensions/markdown-language-features/package.nls.json
index b4ac4c7f58a..b0cf17afe74 100644
--- a/extensions/markdown-language-features/package.nls.json
+++ b/extensions/markdown-language-features/package.nls.json
@@ -7,6 +7,7 @@
"configuration.advanced": "Advanced",
"markdown.copyImage.title": "Copy Image",
"markdown.openImage.title": "Open Image",
+ "markdown.openFrontMatterSettings.title": "Configure Front Matter Visibility",
"markdown.preview.breaks.desc": "Sets how line-breaks are rendered in the Markdown preview. Setting it to `true` creates a `
` for newlines inside paragraphs.",
"markdown.preview.linkify": "Convert URL-like text to links in the Markdown preview.",
"markdown.preview.typographer": "Enable some language-neutral replacement and quotes beautification in the Markdown preview.",
diff --git a/extensions/markdown-language-features/src/commands/index.ts b/extensions/markdown-language-features/src/commands/index.ts
index 0652d4e5705..0be5d6e5aba 100644
--- a/extensions/markdown-language-features/src/commands/index.ts
+++ b/extensions/markdown-language-features/src/commands/index.ts
@@ -20,6 +20,7 @@ import { ShowPreviewSecuritySelectorCommand } from './showPreviewSecuritySelecto
import { ShowSourceCommand } from './showSource';
import { ToggleLockCommand } from './toggleLock';
import { OpenImageCommand } from './openImage';
+import { OpenFrontMatterSettingsCommand } from './openFrontMatterSettings';
export function registerMarkdownCommands(
commandManager: CommandManager,
@@ -32,6 +33,7 @@ export function registerMarkdownCommands(
commandManager.register(new OpenImageCommand(previewManager));
commandManager.register(new CopyImageCommand(previewManager));
+ commandManager.register(new OpenFrontMatterSettingsCommand());
commandManager.register(new ShowPreviewCommand(previewManager, telemetryReporter));
commandManager.register(new ShowPreviewToSideCommand(previewManager, telemetryReporter));
commandManager.register(new ShowLockedPreviewToSideCommand(previewManager, telemetryReporter));
diff --git a/extensions/markdown-language-features/src/commands/openFrontMatterSettings.ts b/extensions/markdown-language-features/src/commands/openFrontMatterSettings.ts
new file mode 100644
index 00000000000..62821a17095
--- /dev/null
+++ b/extensions/markdown-language-features/src/commands/openFrontMatterSettings.ts
@@ -0,0 +1,15 @@
+/*---------------------------------------------------------------------------------------------
+ * Copyright (c) Microsoft Corporation. All rights reserved.
+ * Licensed under the MIT License. See License.txt in the project root for license information.
+ *--------------------------------------------------------------------------------------------*/
+
+import * as vscode from 'vscode';
+import { Command } from '../commandManager';
+
+export class OpenFrontMatterSettingsCommand implements Command {
+ public readonly id = '_markdown.openFrontMatterSettings';
+
+ public async execute() {
+ await vscode.commands.executeCommand('workbench.action.openSettings', '@id:markdown.preview.frontMatter');
+ }
+}
diff --git a/extensions/markdown-language-features/src/extensions/yamlPreamble/yamlPreamble.ts b/extensions/markdown-language-features/src/extensions/yamlPreamble/yamlPreamble.ts
index 417386e232e..b7e519ef68f 100644
--- a/extensions/markdown-language-features/src/extensions/yamlPreamble/yamlPreamble.ts
+++ b/extensions/markdown-language-features/src/extensions/yamlPreamble/yamlPreamble.ts
@@ -13,6 +13,7 @@ export type FrontMatterRenderStyle = 'hide' | 'codeBlock' | 'table';
const FRONT_MATTER_TOKEN = 'front_matter';
const MARKER = '---';
+const FRONT_MATTER_CONTEXT = JSON.stringify({ webviewSection: 'frontMatter' });
interface IFrontMatterMeta {
readonly content: string;
@@ -131,10 +132,10 @@ function renderAsCodeBlock(meta: IFrontMatterMeta, options: MarkdownIt.Options):
}
}
if (highlighted?.startsWith('
${body}
\n`;
+ return `${body}
\n`;
}
function renderAsTable(meta: IFrontMatterMeta): string {
@@ -148,12 +149,17 @@ function renderAsTable(meta: IFrontMatterMeta): string {
const rows = result.entries.map(([key, value]) =>
`| ${escapeHtml(key)} | ${formatValueHtml(value)} |
`
).join('');
- return `\n`;
+ return `\n`;
}
function renderError(message: string): string {
const label = vscode.l10n.t('Failed to parse front matter');
- return `${escapeHtml(label)}${escapeHtml(message)} \n`;
+ return `${escapeHtml(label)}${escapeHtml(message)} \n`;
+}
+
+function frontMatterAttributes(): string {
+ const label = escapeHtml(vscode.l10n.t('Frontmatter'));
+ return `title="${label}" data-vscode-context='${escapeHtml(FRONT_MATTER_CONTEXT)}'`;
}
interface IParseResult {
diff --git a/extensions/markdown-language-features/src/test/engine.test.ts b/extensions/markdown-language-features/src/test/engine.test.ts
index b9f980e19fe..e2a0b47c9db 100644
--- a/extensions/markdown-language-features/src/test/engine.test.ts
+++ b/extensions/markdown-language-features/src/test/engine.test.ts
@@ -91,7 +91,7 @@ suite('markdown.engine', () => {
const engine = createNewMarkdownEngine();
assert.strictEqual(
(await engine.render(input)).html,
- '\n'
+ '\n'
+ 'World
\n'
);
});