Advertisement
Guest User

Updated algorithm.ts

a guest
Jun 17th, 2024
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. import {
  2. JupyterFrontEnd,
  3. JupyterFrontEndPlugin,
  4. } from '@jupyterlab/application';
  5.  
  6. import {
  7. IEditorLanguageRegistry,
  8. IEditorThemeRegistry,
  9. jupyterHighlightStyle
  10. } from '@jupyterlab/codemirror'
  11.  
  12. import {
  13. LanguageSupport,
  14. LRLanguage,
  15. syntaxHighlighting,
  16. // HighlightStyle,
  17. // defaultHighlightStyle
  18. } from '@codemirror/language';
  19.  
  20. import { EditorView } from '@codemirror/view';
  21.  
  22. // import { tags as t } from '@lezer/highlight';
  23.  
  24. import { buildParser } from '@lezer/generator';
  25.  
  26. /**
  27. * Initialization data for the unicodelab-ts extension.
  28. */
  29. export const algorithm_plugin: JupyterFrontEndPlugin<void> = {
  30. id: 'unicodelab-ts:algorithm',
  31. autoStart: true,
  32. // provides: snippetToken, // For providing services
  33. requires: [IEditorLanguageRegistry, IEditorThemeRegistry],
  34. optional: [],
  35. activate: (
  36. app: JupyterFrontEnd,
  37. lang_registry: IEditorLanguageRegistry,
  38. theme_registry: IEditorThemeRegistry
  39. ) => {
  40.  
  41. theme_registry.addTheme({
  42. name: 'algorithm',
  43. displayName: 'Algorithm',
  44. theme: [
  45. EditorView.baseTheme({}),
  46. syntaxHighlighting(jupyterHighlightStyle), // Not recognized
  47.  
  48. // syntaxHighlighting(defaultHighlightStyle), // Not recognized
  49.  
  50. /*
  51. syntaxHighlighting(HighlightStyle.define([
  52. {tag: t.propertyName, color: "#fc6"},
  53. {tag: t.number, color: "#f5d", fontStyle: "italic"},
  54. {tag: t.string, color: "#f0e", fontStyle: "bold"}
  55. ]))
  56. */
  57. ]
  58. });
  59.  
  60. lang_registry.addLanguage({
  61. name: 'algorithm',
  62. displayName: 'Algorithm',
  63. mime: 'text/algorithm',
  64. extensions: ["algorithm"],
  65. support: new LanguageSupport(
  66. LRLanguage.define({
  67. parser: buildParser(`
  68. @top File { (Identifier | Number | String)+ }
  69.  
  70. @skip { space }
  71.  
  72. @tokens {
  73. space { @whitespace+ }
  74. Identifier { $[A-Za-z_]+ }
  75. Number { $[0-9]+ }
  76. String { '"' !["]* '"' }
  77. }
  78.  
  79. @external propSource algorithmHighlight from "./highlight.ts"
  80. `)
  81. })
  82. )
  83. });
  84. }
  85. };
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement