@difizen/libro-toc 0.0.2-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/es/cell-toc-provider.d.ts +9 -0
  4. package/es/cell-toc-provider.d.ts.map +1 -0
  5. package/es/cell-toc-provider.js +46 -0
  6. package/es/index.d.ts +6 -0
  7. package/es/index.d.ts.map +1 -0
  8. package/es/index.js +5 -0
  9. package/es/index.less +66 -0
  10. package/es/libro-toc-color-registry.d.ts +6 -0
  11. package/es/libro-toc-color-registry.d.ts.map +1 -0
  12. package/es/libro-toc-color-registry.js +46 -0
  13. package/es/module.d.ts +14 -0
  14. package/es/module.d.ts.map +1 -0
  15. package/es/module.js +40 -0
  16. package/es/provider/html.d.ts +39 -0
  17. package/es/provider/html.d.ts.map +1 -0
  18. package/es/provider/html.js +54 -0
  19. package/es/provider/markdown-toc-provider.d.ts +11 -0
  20. package/es/provider/markdown-toc-provider.d.ts.map +1 -0
  21. package/es/provider/markdown-toc-provider.js +43 -0
  22. package/es/provider/markdown.d.ts +23 -0
  23. package/es/provider/markdown.d.ts.map +1 -0
  24. package/es/provider/markdown.js +142 -0
  25. package/es/provider/output-toc-provider.d.ts +10 -0
  26. package/es/provider/output-toc-provider.d.ts.map +1 -0
  27. package/es/provider/output-toc-provider.js +67 -0
  28. package/es/toc-collapse-service.d.ts +10 -0
  29. package/es/toc-collapse-service.d.ts.map +1 -0
  30. package/es/toc-collapse-service.js +141 -0
  31. package/es/toc-configuration.d.ts +7 -0
  32. package/es/toc-configuration.d.ts.map +1 -0
  33. package/es/toc-configuration.js +34 -0
  34. package/es/toc-contribution.d.ts +11 -0
  35. package/es/toc-contribution.d.ts.map +1 -0
  36. package/es/toc-contribution.js +63 -0
  37. package/es/toc-manager.d.ts +10 -0
  38. package/es/toc-manager.d.ts.map +1 -0
  39. package/es/toc-manager.js +32 -0
  40. package/es/toc-protocol.d.ts +107 -0
  41. package/es/toc-protocol.d.ts.map +1 -0
  42. package/es/toc-protocol.js +35 -0
  43. package/es/toc-provider.d.ts +37 -0
  44. package/es/toc-provider.d.ts.map +1 -0
  45. package/es/toc-provider.js +181 -0
  46. package/es/toc-view.d.ts +33 -0
  47. package/es/toc-view.d.ts.map +1 -0
  48. package/es/toc-view.js +245 -0
  49. package/package.json +62 -0
  50. package/src/cell-toc-provider.ts +31 -0
  51. package/src/index.less +66 -0
  52. package/src/index.ts +5 -0
  53. package/src/libro-toc-color-registry.ts +27 -0
  54. package/src/module.ts +58 -0
  55. package/src/provider/html.ts +61 -0
  56. package/src/provider/markdown-toc-provider.ts +34 -0
  57. package/src/provider/markdown.ts +182 -0
  58. package/src/provider/output-toc-provider.ts +53 -0
  59. package/src/toc-collapse-service.ts +96 -0
  60. package/src/toc-configuration.ts +22 -0
  61. package/src/toc-contribution.ts +34 -0
  62. package/src/toc-manager.ts +27 -0
  63. package/src/toc-protocol.ts +130 -0
  64. package/src/toc-provider.ts +154 -0
  65. package/src/toc-view.tsx +225 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present Difizen Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # libro shared model
@@ -0,0 +1,9 @@
1
+ import type { CellView } from '@difizen/libro-core';
2
+ import type { Contribution } from '@difizen/mana-app';
3
+ import { CellTOCProviderContribution } from './toc-protocol.js';
4
+ export declare class LibroCellTOCProvider {
5
+ protected providerContribution: Contribution.Provider<CellTOCProviderContribution>;
6
+ createCellTOCProvider(cell: CellView): import("./toc-protocol.js").CellTOCProvider | undefined;
7
+ protected findCellTOCProviderContribution(cell: CellView): CellTOCProviderContribution | undefined;
8
+ }
9
+ //# sourceMappingURL=cell-toc-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cell-toc-provider.d.ts","sourceRoot":"","sources":["../src/cell-toc-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAItD,OAAO,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AAEhE,qBACa,oBAAoB;IAE/B,SAAS,CAAC,oBAAoB,EAAE,YAAY,CAAC,QAAQ,CAAC,2BAA2B,CAAC,CAAC;IAEnF,qBAAqB,CAAC,IAAI,EAAE,QAAQ;IAQpC,SAAS,CAAC,+BAA+B,CACvC,IAAI,EAAE,QAAQ,GACb,2BAA2B,GAAG,SAAS;CAQ3C"}
@@ -0,0 +1,46 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ var _dec, _dec2, _class, _class2, _descriptor;
3
+ function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
4
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
6
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
8
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
9
+ function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
10
+ function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
11
+ import { Priority } from '@difizen/mana-app';
12
+ import { contrib, singleton } from '@difizen/mana-app';
13
+ import { CellTOCProviderContribution } from "./toc-protocol.js";
14
+ export var LibroCellTOCProvider = (_dec = singleton(), _dec2 = contrib(CellTOCProviderContribution), _dec(_class = (_class2 = /*#__PURE__*/function () {
15
+ function LibroCellTOCProvider() {
16
+ _classCallCheck(this, LibroCellTOCProvider);
17
+ _initializerDefineProperty(this, "providerContribution", _descriptor, this);
18
+ }
19
+ _createClass(LibroCellTOCProvider, [{
20
+ key: "createCellTOCProvider",
21
+ value: function createCellTOCProvider(cell) {
22
+ var ctrb = this.findCellTOCProviderContribution(cell);
23
+ if (ctrb) {
24
+ return ctrb.factory(cell);
25
+ }
26
+ return;
27
+ }
28
+ }, {
29
+ key: "findCellTOCProviderContribution",
30
+ value: function findCellTOCProviderContribution(cell) {
31
+ var prioritized = Priority.sortSync(this.providerContribution.getContributions(), function (contribution) {
32
+ return contribution.canHandle(cell);
33
+ });
34
+ var sorted = prioritized.map(function (c) {
35
+ return c.value;
36
+ });
37
+ return sorted[0];
38
+ }
39
+ }]);
40
+ return LibroCellTOCProvider;
41
+ }(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "providerContribution", [_dec2], {
42
+ configurable: true,
43
+ enumerable: true,
44
+ writable: true,
45
+ initializer: null
46
+ })), _class2)) || _class);
package/es/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from './module.js';
2
+ export * from './toc-configuration.js';
3
+ export * from './toc-protocol.js';
4
+ export * from './toc-view.js';
5
+ export * from './toc-contribution.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC"}
package/es/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from "./module.js";
2
+ export * from "./toc-configuration.js";
3
+ export * from "./toc-protocol.js";
4
+ export * from "./toc-view.js";
5
+ export * from "./toc-contribution.js";
package/es/index.less ADDED
@@ -0,0 +1,66 @@
1
+ .libro-markdown-container {
2
+ width: 100%;
3
+ height: 100%;
4
+ height: 16px;
5
+ min-height: 16px;
6
+ }
7
+
8
+ .markdown-toc-container {
9
+ width: 120px;
10
+ min-height: 240px;
11
+ // position: absolute;
12
+ // top: 12px;
13
+ // right: 0;
14
+ // bottom: 0;
15
+ padding-top: 12px;
16
+ overflow-y: auto;
17
+
18
+ .markdown-toc-container-title {
19
+ box-sizing: border-box;
20
+ height: 24px;
21
+ margin-bottom: 16px;
22
+ color: var(--mana-libro-toc-title-color);
23
+ font-weight: 600;
24
+ font-size: 16px;
25
+ line-height: 24px;
26
+ letter-spacing: 0;
27
+ text-align: left;
28
+
29
+ .anticon-eye-invisible,
30
+ .anticon-eye {
31
+ padding-left: 4px;
32
+ cursor: pointer;
33
+ }
34
+ }
35
+
36
+ .markdown-toc-container-anchor {
37
+ position: relative;
38
+ display: block;
39
+ box-sizing: border-box;
40
+ width: 100%;
41
+ padding: 4px 0;
42
+ overflow: hidden;
43
+ color: var(--mana-libro-toc-text-color);
44
+ font-weight: 400;
45
+ font-size: 14px;
46
+ line-height: 16px;
47
+ white-space: nowrap;
48
+ text-align: left;
49
+ text-overflow: ellipsis;
50
+ border-left: 2px solid transparent;
51
+ cursor: pointer;
52
+
53
+ &.active {
54
+ font-weight: 600;
55
+ border-left: 2px solid rgba(5, 140, 224, 99.9%);
56
+ }
57
+
58
+ &:hover {
59
+ background-color: var(--mana-libro-toc-hover-color);
60
+ }
61
+
62
+ .libro-toc-collapsed {
63
+ margin-right: 4px;
64
+ }
65
+ }
66
+ }
@@ -0,0 +1,6 @@
1
+ import type { ColorRegistry } from '@difizen/mana-app';
2
+ import { ColorContribution } from '@difizen/mana-app';
3
+ export declare class LibroTocColorRegistry implements ColorContribution {
4
+ registerColors(colors: ColorRegistry): void;
5
+ }
6
+ //# sourceMappingURL=libro-toc-color-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libro-toc-color-registry.d.ts","sourceRoot":"","sources":["../src/libro-toc-color-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAS,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAG7D,qBACa,qBAAsB,YAAW,iBAAiB;IAC7D,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI;CAoB5C"}
@@ -0,0 +1,46 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ var _dec, _class;
3
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
5
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
+ import { Color, ColorContribution } from '@difizen/mana-app';
9
+ import { singleton } from '@difizen/mana-app';
10
+ export var LibroTocColorRegistry = (_dec = singleton({
11
+ contrib: ColorContribution
12
+ }), _dec(_class = /*#__PURE__*/function () {
13
+ function LibroTocColorRegistry() {
14
+ _classCallCheck(this, LibroTocColorRegistry);
15
+ }
16
+ _createClass(LibroTocColorRegistry, [{
17
+ key: "registerColors",
18
+ value: function registerColors(colors) {
19
+ colors.register(
20
+ // #region antd variable
21
+ {
22
+ id: 'libro.toc.title.color',
23
+ defaults: {
24
+ dark: '#EDEEEF',
25
+ light: Color.rgba(0, 0, 0, 0.85)
26
+ },
27
+ description: ''
28
+ }, {
29
+ id: 'libro.toc.text.color',
30
+ defaults: {
31
+ dark: '#E3E4E6',
32
+ light: Color.rgba(0, 10, 26, 0.68)
33
+ },
34
+ description: ''
35
+ }, {
36
+ id: 'libro.toc.hover.color',
37
+ defaults: {
38
+ dark: '#515359',
39
+ light: Color.rgba(206, 211, 211, 0.422)
40
+ },
41
+ description: ''
42
+ });
43
+ }
44
+ }]);
45
+ return LibroTocColorRegistry;
46
+ }()) || _class);
package/es/module.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { ManaModule } from '@difizen/mana-app';
2
+ /**
3
+ * 不带output支持
4
+ */
5
+ export declare const LibroBaseTOCModule: ManaModule;
6
+ /**
7
+ * 标准的notebook TOC
8
+ */
9
+ export declare const LibroTOCModule: ManaModule;
10
+ /**
11
+ * toc在内容区右侧
12
+ */
13
+ export declare const LibroTOCOnContentModule: ManaModule;
14
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAc/C;;GAEG;AACH,eAAO,MAAM,kBAAkB,YAyBJ,CAAC;AAC5B;;GAEG;AACH,eAAO,MAAM,cAAc,YAE2B,CAAC;AAEvD;;GAEG;AACH,eAAO,MAAM,uBAAuB,YAEnC,CAAC"}
package/es/module.js ADDED
@@ -0,0 +1,40 @@
1
+ import { MarkdownModule } from '@difizen/libro-markdown';
2
+ import { LibroRenderMimeModule } from '@difizen/libro-rendermime';
3
+ import { ManaModule } from '@difizen/mana-app';
4
+ import { LibroCellTOCProvider } from "./cell-toc-provider.js";
5
+ import { LibroTocColorRegistry } from "./libro-toc-color-registry.js";
6
+ import { MarkDownCellTOCProvider } from "./provider/markdown-toc-provider.js";
7
+ import { OutputTOCProvider } from "./provider/output-toc-provider.js";
8
+ import { TOCCollapseService } from "./toc-collapse-service.js";
9
+ import { TOCSettingContribution } from "./toc-configuration.js";
10
+ import { LibroTocSlotContribution } from "./toc-contribution.js";
11
+ import { LibroTOCManager } from "./toc-manager.js";
12
+ import { CellTOCProviderContribution, TOCProviderOption } from "./toc-protocol.js";
13
+ import { LibroTOCProvider, LibroTOCProviderFactory } from "./toc-provider.js";
14
+ import { TOCView } from "./toc-view.js";
15
+
16
+ /**
17
+ * 不带output支持
18
+ */
19
+ export var LibroBaseTOCModule = ManaModule.create().contribution(CellTOCProviderContribution).register(TOCSettingContribution, TOCView, LibroTOCProvider, {
20
+ token: LibroTOCProviderFactory,
21
+ useFactory: function useFactory(ctx) {
22
+ return function (option) {
23
+ var child = ctx.container.createChild();
24
+ child.register({
25
+ token: TOCProviderOption,
26
+ useValue: option
27
+ });
28
+ return child.get(LibroTOCProvider);
29
+ };
30
+ }
31
+ }, LibroTOCManager, LibroCellTOCProvider, MarkDownCellTOCProvider, TOCCollapseService, LibroTocColorRegistry).dependOn(MarkdownModule);
32
+ /**
33
+ * 标准的notebook TOC
34
+ */
35
+ export var LibroTOCModule = ManaModule.create().register(OutputTOCProvider).dependOn(LibroBaseTOCModule, LibroRenderMimeModule);
36
+
37
+ /**
38
+ * toc在内容区右侧
39
+ */
40
+ export var LibroTOCOnContentModule = ManaModule.create().register(LibroTocSlotContribution);
@@ -0,0 +1,39 @@
1
+ import type { IHeading } from '../toc-protocol.js';
2
+ import { HeadingType } from '../toc-protocol.js';
3
+ /**
4
+ * HTML heading
5
+ */
6
+ export interface IHTMLHeading extends IHeading {
7
+ /**
8
+ * HTML id
9
+ */
10
+ id?: string | null;
11
+ }
12
+ /**
13
+ * Parse a HTML string for headings.
14
+ *
15
+ * ### Notes
16
+ * The html string is not sanitized - use with caution
17
+ *
18
+ * @param html HTML string to parse
19
+ * @param force Whether to ignore HTML headings with class jp-toc-ignore and tocSkip or not
20
+ * @returns Extracted headings
21
+ */
22
+ export declare function getHTMLHeadings(html: string, type?: HeadingType): IHTMLHeading[];
23
+ export declare const HTMLMimeType = "text/html";
24
+ /**
25
+ * Returns whether a MIME type corresponds to either HTML.
26
+ *
27
+ * @param mime - MIME type string
28
+ * @returns boolean indicating whether a provided MIME type corresponds to either HTML
29
+ *
30
+ * @example
31
+ * const bool = isHTML('text/html');
32
+ * // returns true
33
+ *
34
+ * @example
35
+ * const bool = isHTML('text/plain');
36
+ * // returns false
37
+ */
38
+ export declare function isHTML(mime: string): boolean;
39
+ //# sourceMappingURL=html.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/provider/html.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,YAAa,SAAQ,QAAQ;IAC5C;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AACD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,YAAY,EAAE,CAkBhF;AAED,eAAO,MAAM,YAAY,cAAc,CAAC;AAExC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE5C"}
@@ -0,0 +1,54 @@
1
+ import { HeadingType } from "../toc-protocol.js";
2
+
3
+ /**
4
+ * HTML heading
5
+ */
6
+
7
+ /**
8
+ * Parse a HTML string for headings.
9
+ *
10
+ * ### Notes
11
+ * The html string is not sanitized - use with caution
12
+ *
13
+ * @param html HTML string to parse
14
+ * @param force Whether to ignore HTML headings with class jp-toc-ignore and tocSkip or not
15
+ * @returns Extracted headings
16
+ */
17
+ export function getHTMLHeadings(html, type) {
18
+ var container = document.createElement('div');
19
+ container.innerHTML = html;
20
+ var headings = new Array();
21
+ var headers = Array.from(container.querySelectorAll('h1, h2, h3, h4, h5, h6'));
22
+ for (var _i = 0, _headers = headers; _i < _headers.length; _i++) {
23
+ var _h$textContent;
24
+ var h = _headers[_i];
25
+ var level = parseInt(h.tagName[1], 10);
26
+ headings.push({
27
+ text: (_h$textContent = h.textContent) !== null && _h$textContent !== void 0 ? _h$textContent : '',
28
+ level: level,
29
+ id: h === null || h === void 0 ? void 0 : h.getAttribute('id'),
30
+ skip: h.classList.contains('jp-toc-ignore') || h.classList.contains('tocSkip'),
31
+ type: type !== null && type !== void 0 ? type : HeadingType.HTML
32
+ });
33
+ }
34
+ return headings;
35
+ }
36
+ export var HTMLMimeType = 'text/html';
37
+
38
+ /**
39
+ * Returns whether a MIME type corresponds to either HTML.
40
+ *
41
+ * @param mime - MIME type string
42
+ * @returns boolean indicating whether a provided MIME type corresponds to either HTML
43
+ *
44
+ * @example
45
+ * const bool = isHTML('text/html');
46
+ * // returns true
47
+ *
48
+ * @example
49
+ * const bool = isHTML('text/plain');
50
+ * // returns false
51
+ */
52
+ export function isHTML(mime) {
53
+ return mime === HTMLMimeType;
54
+ }
@@ -0,0 +1,11 @@
1
+ import type { CellView } from '@difizen/libro-core';
2
+ import { MarkdownParser } from '@difizen/libro-markdown';
3
+ import type { CellTOCProvider } from '../toc-protocol.js';
4
+ import { CellTOCProviderContribution } from '../toc-protocol.js';
5
+ export declare class MarkDownCellTOCProvider implements CellTOCProviderContribution {
6
+ protected readonly markdownParser: MarkdownParser;
7
+ constructor(markdownParser: MarkdownParser);
8
+ canHandle(cell: CellView): 0 | 100;
9
+ factory(cell: CellView): CellTOCProvider;
10
+ }
11
+ //# sourceMappingURL=markdown-toc-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown-toc-provider.d.ts","sourceRoot":"","sources":["../../src/provider/markdown-toc-provider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAe,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAI9E,qBACa,uBAAwB,YAAW,2BAA2B;IACzE,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;gBACd,cAAc,EAAE,cAAc;IAIlE,SAAS,CAAC,IAAI,EAAE,QAAQ;IAGxB,OAAO,CAAC,IAAI,EAAE,QAAQ,GAAG,eAAe;CAazC"}
@@ -0,0 +1,43 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ var _dec, _class;
3
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
5
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
+ import { LibroMarkdownCellModel } from '@difizen/libro-core';
9
+ import { MarkdownParser } from '@difizen/libro-markdown';
10
+ import { inject, singleton, watch } from '@difizen/mana-app';
11
+ import { HeadingType, CellTOCProviderContribution } from "../toc-protocol.js";
12
+ import { getHTMLHeadings } from "./html.js";
13
+ export var MarkDownCellTOCProvider = (_dec = singleton({
14
+ contrib: [CellTOCProviderContribution]
15
+ }), _dec(_class = /*#__PURE__*/function () {
16
+ function MarkDownCellTOCProvider(markdownParser) {
17
+ _classCallCheck(this, MarkDownCellTOCProvider);
18
+ this.markdownParser = markdownParser;
19
+ }
20
+ MarkDownCellTOCProvider = inject(MarkdownParser)(MarkDownCellTOCProvider, undefined, 0) || MarkDownCellTOCProvider;
21
+ _createClass(MarkDownCellTOCProvider, [{
22
+ key: "canHandle",
23
+ value: function canHandle(cell) {
24
+ return LibroMarkdownCellModel.is(cell.model) ? 100 : 0;
25
+ }
26
+ }, {
27
+ key: "factory",
28
+ value: function factory(cell) {
29
+ var _this = this;
30
+ return {
31
+ getHeadings: function getHeadings() {
32
+ return getHTMLHeadings(_this.markdownParser.render(cell.model.value, {
33
+ cellId: cell.model.id
34
+ }), HeadingType.Markdown);
35
+ },
36
+ updateWatcher: function updateWatcher(update) {
37
+ return watch(cell.model, 'value', update);
38
+ }
39
+ };
40
+ }
41
+ }]);
42
+ return MarkDownCellTOCProvider;
43
+ }()) || _class);
@@ -0,0 +1,23 @@
1
+ import type { IHeading } from '../toc-protocol.js';
2
+ /**
3
+ * Markdown heading
4
+ */
5
+ export interface IMarkdownHeading extends IHeading {
6
+ /**
7
+ * Heading line
8
+ */
9
+ line: number;
10
+ }
11
+ /**
12
+ * Parses the provided string and returns a list of headings.
13
+ *
14
+ * @param text - Input text
15
+ * @returns List of headings
16
+ */
17
+ export declare function getHeadings(text: string): IMarkdownHeading[];
18
+ /**
19
+ * Whether a MIME type corresponds to a Markdown flavor.
20
+ */
21
+ export declare function isMarkdown(mime: string): boolean;
22
+ export declare const MarkdownMimeType = "text/markdown";
23
+ //# sourceMappingURL=markdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/provider/markdown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAyBnD;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,QAAQ;IAChD;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAsD5D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAOhD;AA0ED,eAAO,MAAM,gBAAgB,kBAAkB,CAAC"}
@@ -0,0 +1,142 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
+ import { HeadingType } from "../toc-protocol.js";
8
+
9
+ /**
10
+ * Markdown heading
11
+ */
12
+
13
+ /**
14
+ * Parses the provided string and returns a list of headings.
15
+ *
16
+ * @param text - Input text
17
+ * @returns List of headings
18
+ */
19
+ export function getHeadings(text) {
20
+ // Split the text into lines:
21
+ var lines = text.split('\n');
22
+
23
+ // Iterate over the lines to get the header level and text for each line:
24
+ var headings = new Array();
25
+ var isCodeBlock;
26
+ var lineIdx = 0;
27
+
28
+ // Don't check for Markdown headings if in a YAML frontmatter block.
29
+ // We can only start a frontmatter block on the first line of the file.
30
+ // At other positions in a markdown file, '---' represents a horizontal rule.
31
+ if (lines[lineIdx] === '---') {
32
+ // Search for another '---' and treat that as the end of the frontmatter.
33
+ // If we don't find one, treat the file as containing no frontmatter.
34
+ for (var frontmatterEndLineIdx = lineIdx + 1; frontmatterEndLineIdx < lines.length; frontmatterEndLineIdx++) {
35
+ if (lines[frontmatterEndLineIdx] === '---') {
36
+ lineIdx = frontmatterEndLineIdx + 1;
37
+ break;
38
+ }
39
+ }
40
+ }
41
+ for (; lineIdx < lines.length; lineIdx++) {
42
+ var line = lines[lineIdx];
43
+ if (line === '') {
44
+ // Bail early
45
+ continue;
46
+ }
47
+
48
+ // Don't check for Markdown headings if in a code block
49
+ if (line.startsWith('```')) {
50
+ isCodeBlock = !isCodeBlock;
51
+ }
52
+ if (isCodeBlock) {
53
+ continue;
54
+ }
55
+ var heading = parseHeading(line, lines[lineIdx + 1]); // append the next line to capture alternative style Markdown headings
56
+
57
+ if (heading) {
58
+ headings.push(_objectSpread(_objectSpread({}, heading), {}, {
59
+ line: lineIdx,
60
+ type: HeadingType.Markdown
61
+ }));
62
+ }
63
+ }
64
+ return headings;
65
+ }
66
+
67
+ /**
68
+ * Whether a MIME type corresponds to a Markdown flavor.
69
+ */
70
+ export function isMarkdown(mime) {
71
+ return ['text/x-ipythongfm', 'text/x-markdown', 'text/x-gfm', 'text/markdown'].includes(mime);
72
+ }
73
+
74
+ /**
75
+ * Ignore title with html tag with a class name equal to `jp-toc-ignore` or `tocSkip`
76
+ */
77
+ var skipHeading = /<\w+\s(.*?\s)?class="(.*?\s)?(jp-toc-ignore|tocSkip)(\s.*?)?"(\s.*?)?>/;
78
+
79
+ /**
80
+ * Parses a heading, if one exists, from a provided string.
81
+ * @param line - Line to parse
82
+ * @param nextLine - The line after the one to parse
83
+ * @returns heading info
84
+ *
85
+ * @example
86
+ * ### Foo
87
+ * const out = parseHeading('### Foo\n');
88
+ * // returns {'text': 'Foo', 'level': 3}
89
+ *
90
+ * @example
91
+ * const out = parseHeading('Foo\n===\n');
92
+ * // returns {'text': 'Foo', 'level': 1}
93
+ *
94
+ * @example
95
+ * <h4>Foo</h4>
96
+ * const out = parseHeading('<h4>Foo</h4>\n');
97
+ * // returns {'text': 'Foo', 'level': 4}
98
+ *
99
+ * @example
100
+ * const out = parseHeading('Foo');
101
+ * // returns null
102
+ */
103
+ function parseHeading(line, nextLine) {
104
+ // Case: Markdown heading
105
+ var match = line.match(/^([#]{1,6}) (.*)/);
106
+ if (match) {
107
+ return {
108
+ text: cleanTitle(match[2]),
109
+ level: match[1].length,
110
+ raw: line,
111
+ skip: skipHeading.test(match[0])
112
+ };
113
+ }
114
+ // Case: Markdown heading (alternative style)
115
+ if (nextLine) {
116
+ match = nextLine.match(/^ {0,3}([=]{2,}|[-]{2,})\s*$/);
117
+ if (match) {
118
+ return {
119
+ text: cleanTitle(line),
120
+ level: match[1][0] === '=' ? 1 : 2,
121
+ raw: [line, nextLine].join('\n'),
122
+ skip: skipHeading.test(line)
123
+ };
124
+ }
125
+ }
126
+ // Case: HTML heading (WARNING: this is not particularly robust, as HTML headings can span multiple lines)
127
+ match = line.match(/<h([1-6]).*>(.*)<\/h\1>/i);
128
+ if (match) {
129
+ return {
130
+ text: match[2],
131
+ level: parseInt(match[1], 10),
132
+ skip: skipHeading.test(match[0]),
133
+ raw: line
134
+ };
135
+ }
136
+ return null;
137
+ }
138
+ function cleanTitle(heading) {
139
+ // take special care to parse Markdown links into raw text
140
+ return heading.replace(/\[(.+)\]\(.+\)/g, '$1');
141
+ }
142
+ export var MarkdownMimeType = 'text/markdown';
@@ -0,0 +1,10 @@
1
+ import type { CellView } from '@difizen/libro-core';
2
+ import { RenderMimeRegistry } from '@difizen/libro-rendermime';
3
+ import type { CellTOCProvider } from '../toc-protocol.js';
4
+ import { CellTOCProviderContribution } from '../toc-protocol.js';
5
+ export declare class OutputTOCProvider implements CellTOCProviderContribution {
6
+ renderMimeRegistry: RenderMimeRegistry;
7
+ canHandle(cell: CellView): 0 | 100;
8
+ factory(cell: CellView): CellTOCProvider;
9
+ }
10
+ //# sourceMappingURL=output-toc-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output-toc-provider.d.ts","sourceRoot":"","sources":["../../src/provider/output-toc-provider.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAI/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAKjE,qBACa,iBAAkB,YAAW,2BAA2B;IACvC,kBAAkB,EAAE,kBAAkB,CAAC;IACnE,SAAS,CAAC,IAAI,EAAE,QAAQ;IAIxB,OAAO,CAAC,IAAI,EAAE,QAAQ,GAAG,eAAe;CA+BzC"}