Skip to content

Commit 89abdbc

Browse files
authored
Merge pull request #310 from noahbuscher/playground-monaco-tsdoc-lang
[playground] Add TSDoc parsing, banner
2 parents 7e58c41 + 1a07f89 commit 89abdbc

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

playground/src/CodeEditor.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
22
import * as monacoEditor from 'monaco-editor';
3+
import * as tsdoc from '@microsoft/tsdoc';
34
import { FlexColDiv } from './FlexDivs';
45

56
export interface ITextRange {
@@ -58,6 +59,10 @@ interface IMonacoWindow extends Window {
5859
};
5960
}
6061

62+
interface IMonarchLanguageConfiguration extends monacoEditor.languages.IMonarchLanguage {
63+
keywords: string[];
64+
}
65+
6166
declare const MONACO_URL: string;
6267
const MONACO_BASE_URL: string = MONACO_URL;
6368

@@ -309,6 +314,30 @@ export class CodeEditor extends React.Component<ICodeEditorProps, ICodeEditorSta
309314
CodeEditor._initializeMonaco()
310315
.then((monaco) => {
311316
if (!this._editor && this._hostDivRef) {
317+
const tsdocLanguage: IMonarchLanguageConfiguration = {
318+
keywords: tsdoc.StandardTags.allDefinitions.map((tag: tsdoc.TSDocTagDefinition) => tag.tagName),
319+
tokenizer: {
320+
common: [[/\/\*\*/, 'comment', '@comment']],
321+
comment: [
322+
[/\*/, 'comment'],
323+
[/\\* [^\n@*]*/, 'comment'],
324+
[/(?:\/)[\n|*]*/, 'comment', '@pop'],
325+
[
326+
/@[^ \n]*/,
327+
{
328+
cases: {
329+
'@keywords': 'keyword',
330+
'@default': 'annotation'
331+
}
332+
}
333+
]
334+
]
335+
}
336+
};
337+
338+
monaco.languages.register({ id: 'tsdocLanguage' });
339+
monaco.languages.setMonarchTokensProvider('tsdocLanguage', tsdocLanguage);
340+
312341
this._editor = monaco.editor.create(this._hostDivRef, {
313342
value: this.props.value || '',
314343
language: this.props.language,

playground/src/PlaygroundView.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,32 @@ export class PlaygroundView extends React.Component<IPlaygroundViewProps, IPlayg
139139
borderColor: '#c0c0c0'
140140
};
141141

142+
const bannerStyle: React.CSSProperties = {
143+
width: '100%',
144+
padding: '8px 16px',
145+
border: '1px solid #006721',
146+
borderRadius: '3px',
147+
color: 'var(--white)',
148+
background: '#108938',
149+
marginBottom: '8px',
150+
fontSize: '14px'
151+
};
152+
142153
return (
143154
<FlexColDiv className="playground-input-box" style={{ flex: 1 }}>
144155
<div className="playground-button-bar" style={{ height: '40px', boxSizing: 'border-box' }}>
145156
{this._renderSelectSample()}
146157
{this._renderThemeSelector()}
147158
</div>
159+
<div className="playground-notice-banner" style={bannerStyle}>
160+
TSDoc does not parse Typescript. Typescript code used here is for illustrative purposes only.
161+
</div>
148162
<CodeEditor
149163
className="playground-input-text-editor"
150164
style={editorStyle}
151165
value={this.state.inputText}
152166
onChange={this._inputTextArea_onChange}
153-
language="typescript"
167+
language="tsdocLanguage"
154168
markers={markers}
155169
syntaxStyles={syntaxStyles}
156170
theme={this.state.selectedTheme}

0 commit comments

Comments
 (0)