html-code-editor.ts

33 lines | 1.128 kB Blame History Raw Download
import { CodeEditor } from "./code-editor";
import * as monaco from 'monaco-editor';
import initHtml from '!!raw-loader!./injects/editor-init.html';

export class HtmlCodeEditor extends CodeEditor {
    setInitInput(): string {
        var base = super.setInitInput();
        if (!base) {
            return initHtml;
        }
        else {
            return base;
        }
    }

    setInitSettings(): void {
        monaco.languages.registerCompletionItemProvider("html", {
            provideCompletionItems: (model, position, context, token) => {
                return {
                    suggestions: [
                        {
                            label: 'jqueryCDN',
                            kind: monaco.languages.CompletionItemKind.Snippet,
                            insertText: "<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js'></script>",
                            range: <any>null,
                            insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet
                        }
                    ]
                }
            }
        });
    }
}