Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {
- JupyterFrontEnd,
- JupyterFrontEndPlugin,
- } from '@jupyterlab/application';
- import {
- IEditorLanguageRegistry,
- IEditorThemeRegistry,
- jupyterHighlightStyle
- } from '@jupyterlab/codemirror'
- import {
- LanguageSupport,
- LRLanguage,
- syntaxHighlighting,
- // HighlightStyle,
- // defaultHighlightStyle
- } from '@codemirror/language';
- import { EditorView } from '@codemirror/view';
- // import { tags as t } from '@lezer/highlight';
- import { buildParser } from '@lezer/generator';
- /**
- * Initialization data for the unicodelab-ts extension.
- */
- export const algorithm_plugin: JupyterFrontEndPlugin<void> = {
- id: 'unicodelab-ts:algorithm',
- autoStart: true,
- // provides: snippetToken, // For providing services
- requires: [IEditorLanguageRegistry, IEditorThemeRegistry],
- optional: [],
- activate: (
- app: JupyterFrontEnd,
- lang_registry: IEditorLanguageRegistry,
- theme_registry: IEditorThemeRegistry
- ) => {
- theme_registry.addTheme({
- name: 'algorithm',
- displayName: 'Algorithm',
- theme: [
- EditorView.baseTheme({}),
- syntaxHighlighting(jupyterHighlightStyle), // Not recognized
- // syntaxHighlighting(defaultHighlightStyle), // Not recognized
- /*
- syntaxHighlighting(HighlightStyle.define([
- {tag: t.propertyName, color: "#fc6"},
- {tag: t.number, color: "#f5d", fontStyle: "italic"},
- {tag: t.string, color: "#f0e", fontStyle: "bold"}
- ]))
- */
- ]
- });
- lang_registry.addLanguage({
- name: 'algorithm',
- displayName: 'Algorithm',
- mime: 'text/algorithm',
- extensions: ["algorithm"],
- support: new LanguageSupport(
- LRLanguage.define({
- parser: buildParser(`
- @top File { (Identifier | Number | String)+ }
- @skip { space }
- @tokens {
- space { @whitespace+ }
- Identifier { $[A-Za-z_]+ }
- Number { $[0-9]+ }
- String { '"' !["]* '"' }
- }
- @external propSource algorithmHighlight from "./highlight.ts"
- `)
- })
- )
- });
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement