Skip to content

Commit aca328b

Browse files
committed
Add button directives
1 parent dfce550 commit aca328b

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "elastic-docs-v3-utilities",
33
"displayName": "Elastic Docs Utilities",
44
"description": "Utilities for Elastic Docs authoring",
5-
"version": "0.12.5",
5+
"version": "0.12.6",
66
"publisher": "Elastic",
77
"repository": {
88
"type": "git",

src/directiveDiagnosticProvider.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export class DirectiveDiagnosticProvider {
193193
return blocks;
194194
}
195195

196-
private validateDirectiveBlock(block: DirectiveBlock, _document: vscode.TextDocument): vscode.Diagnostic[] {
196+
private validateDirectiveBlock(block: DirectiveBlock, document: vscode.TextDocument): vscode.Diagnostic[] {
197197
const diagnostics: vscode.Diagnostic[] = [];
198198

199199
outputChannel.appendLine(`[Elastic Docs] Validating block '${block.name}' (${block.openingColons} colons) - Has closing: ${!!block.closing}`);
@@ -248,7 +248,32 @@ export class DirectiveDiagnosticProvider {
248248
}
249249
}
250250

251-
// 6. Check for malformed opening (missing braces)
251+
// 6. Validate button directive content (must be a markdown link)
252+
if (block.name === 'button' && block.contentLines.length > 0) {
253+
const contentLines = block.contentLines.map(lineNum => document.lineAt(lineNum).text);
254+
const content = contentLines.join('\n').trim();
255+
const markdownLinkPattern = /^\[([^\]]+)\]\(([^)]+)\)$/;
256+
257+
if (!markdownLinkPattern.test(content)) {
258+
// Create a range covering all content lines
259+
const firstContentLine = block.contentLines[0];
260+
const lastContentLine = block.contentLines[block.contentLines.length - 1];
261+
const firstLine = document.lineAt(firstContentLine);
262+
const lastLine = document.lineAt(lastContentLine);
263+
const contentRange = new vscode.Range(
264+
new vscode.Position(firstContentLine, 0),
265+
new vscode.Position(lastContentLine, lastLine.text.length)
266+
);
267+
268+
diagnostics.push(new vscode.Diagnostic(
269+
contentRange,
270+
"Button directive content must be a markdown link in the format [text](url)",
271+
vscode.DiagnosticSeverity.Error
272+
));
273+
}
274+
}
275+
276+
// 7. Check for malformed opening (missing braces)
252277
if (block.isMalformed) {
253278
if (block.missingClosingBrace) {
254279
diagnostics.push(new vscode.Diagnostic(

src/directives.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,20 @@ export const DIRECTIVES: readonly DirectiveDefinition[] = [
152152
template: ':::{math}\n:label: equation-label\nE = mc^2\n:::',
153153
description: 'Render mathematical expressions using LaTeX syntax. Mathematical expressions are rendered client-side using KaTeX for fast, accurate display.'
154154
},
155+
{
156+
name: 'button',
157+
hasArgument: false,
158+
parameters: ['type', 'align'],
159+
template: ':::{button}\n[Button Text](/link)\n:::',
160+
description: 'Styled link element for calls to action in documentation.'
161+
},
162+
{
163+
name: 'button-group',
164+
hasArgument: false,
165+
parameters: ['align'],
166+
template: '::::{button-group}\n:::{button}\n[Button Text](/link)\n:::\n::::',
167+
description: 'Group multiple buttons in a row.'
168+
},
155169
];
156170

157171
export const PARAMETER_VALUES: { [key: string]: string[] } = {
@@ -162,5 +176,7 @@ export const PARAMETER_VALUES: { [key: string]: string[] } = {
162176
'height': ['100px', '200px', '300px', '400px', '500px'],
163177
'alt': ['Image description', 'Screenshot', 'Diagram', 'Icon'],
164178
'separator': [',', ';', '|', 'tab'],
165-
'caption': ['Table caption']
179+
'caption': ['Table caption'],
180+
'type': ['primary', 'secondary'],
181+
'align': ['left', 'center', 'right']
166182
};

0 commit comments

Comments
 (0)