@quarto/jupyterlab-quarto 0.1.44 → 0.1.45
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.
- package/lib/__tests__/index.spec.d.ts +6 -0
- package/lib/__tests__/index.spec.js +61 -0
- package/lib/__tests__/index.spec.js.map +1 -0
- package/lib/__tests__/myextension.spec.d.ts +6 -0
- package/lib/__tests__/myextension.spec.js +11 -0
- package/lib/__tests__/myextension.spec.js.map +1 -0
- package/lib/ast/ast.d.ts +3 -0
- package/lib/ast/ast.js +39 -0
- package/lib/ast/ast.js.map +1 -0
- package/lib/const.d.ts +5 -0
- package/lib/const.js +12 -0
- package/lib/const.js.map +1 -0
- package/lib/hooks/codemirror.d.ts +4 -0
- package/lib/hooks/codemirror.js +52 -0
- package/lib/hooks/codemirror.js.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +60 -0
- package/lib/index.js.map +1 -0
- package/lib/manager.d.ts +8 -0
- package/lib/manager.js +117 -0
- package/lib/manager.js.map +1 -0
- package/lib/plugins/callouts.d.ts +3 -0
- package/lib/plugins/callouts.js +209 -0
- package/lib/plugins/callouts.js.map +1 -0
- package/lib/plugins/cites.d.ts +3 -0
- package/lib/plugins/cites.js +148 -0
- package/lib/plugins/cites.js.map +1 -0
- package/lib/plugins/decorator.d.ts +3 -0
- package/lib/plugins/decorator.js +59 -0
- package/lib/plugins/decorator.js.map +1 -0
- package/lib/plugins/divs.d.ts +6 -0
- package/lib/plugins/divs.js +100 -0
- package/lib/plugins/divs.js.map +1 -0
- package/lib/plugins/figure-divs.d.ts +3 -0
- package/lib/plugins/figure-divs.js +53 -0
- package/lib/plugins/figure-divs.js.map +1 -0
- package/lib/plugins/figures.d.ts +17 -0
- package/lib/plugins/figures.js +99 -0
- package/lib/plugins/figures.js.map +1 -0
- package/lib/plugins/gridtables/common/gridtables/GetCells.d.ts +8 -0
- package/lib/plugins/gridtables/common/gridtables/GetCells.js +45 -0
- package/lib/plugins/gridtables/common/gridtables/GetCells.js.map +1 -0
- package/lib/plugins/gridtables/common/gridtables/GetColumnWidths.d.ts +8 -0
- package/lib/plugins/gridtables/common/gridtables/GetColumnWidths.js +27 -0
- package/lib/plugins/gridtables/common/gridtables/GetColumnWidths.js.map +1 -0
- package/lib/plugins/gridtables/common/markdown-it/ColumnAlignments.d.ts +8 -0
- package/lib/plugins/gridtables/common/markdown-it/ColumnAlignments.js +13 -0
- package/lib/plugins/gridtables/common/markdown-it/ColumnAlignments.js.map +1 -0
- package/lib/plugins/gridtables/common/markdown-it/EmitTable.d.ts +5 -0
- package/lib/plugins/gridtables/common/markdown-it/EmitTable.js +67 -0
- package/lib/plugins/gridtables/common/markdown-it/EmitTable.js.map +1 -0
- package/lib/plugins/gridtables/common/markdown-it/GetCharCodeAtStartOfLine.d.ts +9 -0
- package/lib/plugins/gridtables/common/markdown-it/GetCharCodeAtStartOfLine.js +19 -0
- package/lib/plugins/gridtables/common/markdown-it/GetCharCodeAtStartOfLine.js.map +1 -0
- package/lib/plugins/gridtables/common/markdown-it/GetLine.d.ts +3 -0
- package/lib/plugins/gridtables/common/markdown-it/GetLine.js +10 -0
- package/lib/plugins/gridtables/common/markdown-it/GetLine.js.map +1 -0
- package/lib/plugins/gridtables/common/markdown-it/ParseTable.d.ts +4 -0
- package/lib/plugins/gridtables/common/markdown-it/ParseTable.js +162 -0
- package/lib/plugins/gridtables/common/markdown-it/ParseTable.js.map +1 -0
- package/lib/plugins/gridtables/common/markdown-it/ParseTableResult.d.ts +13 -0
- package/lib/plugins/gridtables/common/markdown-it/ParseTableResult.js +18 -0
- package/lib/plugins/gridtables/common/markdown-it/ParseTableResult.js.map +1 -0
- package/lib/plugins/gridtables/index.d.ts +2 -0
- package/lib/plugins/gridtables/index.js +11 -0
- package/lib/plugins/gridtables/index.js.map +1 -0
- package/lib/plugins/gridtables/interfaces/markdown-it/IState.d.ts +11 -0
- package/lib/plugins/gridtables/interfaces/markdown-it/IState.js +6 -0
- package/lib/plugins/gridtables/interfaces/markdown-it/IState.js.map +1 -0
- package/lib/plugins/gridtables/interfaces/markdown-it/IToken.d.ts +7 -0
- package/lib/plugins/gridtables/interfaces/markdown-it/IToken.js +6 -0
- package/lib/plugins/gridtables/interfaces/markdown-it/IToken.js.map +1 -0
- package/lib/plugins/gridtables/interfaces/markdown-it/TRuleFunction.d.ts +4 -0
- package/lib/plugins/gridtables/interfaces/markdown-it/TRuleFunction.js +6 -0
- package/lib/plugins/gridtables/interfaces/markdown-it/TRuleFunction.js.map +1 -0
- package/lib/plugins/gridtables/rules/gridtable.d.ts +4 -0
- package/lib/plugins/gridtables/rules/gridtable.js +26 -0
- package/lib/plugins/gridtables/rules/gridtable.js.map +1 -0
- package/lib/plugins/math.d.ts +5 -0
- package/lib/plugins/math.js +177 -0
- package/lib/plugins/math.js.map +1 -0
- package/lib/plugins/mermaid/index.d.ts +5 -0
- package/lib/plugins/mermaid/index.js +55 -0
- package/lib/plugins/mermaid/index.js.map +1 -0
- package/lib/plugins/shortcodes.d.ts +4 -0
- package/lib/plugins/shortcodes.js +33 -0
- package/lib/plugins/shortcodes.js.map +1 -0
- package/lib/plugins/spans.d.ts +3 -0
- package/lib/plugins/spans.js +39 -0
- package/lib/plugins/spans.js.map +1 -0
- package/lib/plugins/table-captions.d.ts +3 -0
- package/lib/plugins/table-captions.js +69 -0
- package/lib/plugins/table-captions.js.map +1 -0
- package/lib/plugins/utils/html.d.ts +12 -0
- package/lib/plugins/utils/html.js +46 -0
- package/lib/plugins/utils/html.js.map +1 -0
- package/lib/plugins/utils/markdownit.d.ts +16 -0
- package/lib/plugins/utils/markdownit.js +45 -0
- package/lib/plugins/utils/markdownit.js.map +1 -0
- package/lib/plugins/utils/tok.d.ts +8 -0
- package/lib/plugins/utils/tok.js +14 -0
- package/lib/plugins/utils/tok.js.map +1 -0
- package/lib/plugins/yaml.d.ts +3 -0
- package/lib/plugins/yaml.js +320 -0
- package/lib/plugins/yaml.js.map +1 -0
- package/lib/providers/attrs.d.ts +2 -0
- package/lib/providers/attrs.js +16 -0
- package/lib/providers/attrs.js.map +1 -0
- package/lib/providers/callouts.d.ts +2 -0
- package/lib/providers/callouts.js +16 -0
- package/lib/providers/callouts.js.map +1 -0
- package/lib/providers/cites.d.ts +2 -0
- package/lib/providers/cites.js +16 -0
- package/lib/providers/cites.js.map +1 -0
- package/lib/providers/decorator.d.ts +2 -0
- package/lib/providers/decorator.js +16 -0
- package/lib/providers/decorator.js.map +1 -0
- package/lib/providers/deflist.d.ts +2 -0
- package/lib/providers/deflist.js +16 -0
- package/lib/providers/deflist.js.map +1 -0
- package/lib/providers/divs.d.ts +2 -0
- package/lib/providers/divs.js +28 -0
- package/lib/providers/divs.js.map +1 -0
- package/lib/providers/figure-divs.d.ts +2 -0
- package/lib/providers/figure-divs.js +16 -0
- package/lib/providers/figure-divs.js.map +1 -0
- package/lib/providers/figures.d.ts +2 -0
- package/lib/providers/figures.js +16 -0
- package/lib/providers/figures.js.map +1 -0
- package/lib/providers/footnotes.d.ts +2 -0
- package/lib/providers/footnotes.js +16 -0
- package/lib/providers/footnotes.js.map +1 -0
- package/lib/providers/gridtables.d.ts +2 -0
- package/lib/providers/gridtables.js +16 -0
- package/lib/providers/gridtables.js.map +1 -0
- package/lib/providers/math.d.ts +2 -0
- package/lib/providers/math.js +105 -0
- package/lib/providers/math.js.map +1 -0
- package/lib/providers/mermaid.d.ts +2 -0
- package/lib/providers/mermaid.js +16 -0
- package/lib/providers/mermaid.js.map +1 -0
- package/lib/providers/provider.d.ts +4 -0
- package/lib/providers/provider.js +13 -0
- package/lib/providers/provider.js.map +1 -0
- package/lib/providers/shortcodes.d.ts +2 -0
- package/lib/providers/shortcodes.js +16 -0
- package/lib/providers/shortcodes.js.map +1 -0
- package/lib/providers/spans.d.ts +2 -0
- package/lib/providers/spans.js +16 -0
- package/lib/providers/spans.js.map +1 -0
- package/lib/providers/sub.d.ts +2 -0
- package/lib/providers/sub.js +16 -0
- package/lib/providers/sub.js.map +1 -0
- package/lib/providers/sup.d.ts +2 -0
- package/lib/providers/sup.js +16 -0
- package/lib/providers/sup.js.map +1 -0
- package/lib/providers/table-captions.d.ts +2 -0
- package/lib/providers/table-captions.js +16 -0
- package/lib/providers/table-captions.js.map +1 -0
- package/lib/providers/tasklists.d.ts +2 -0
- package/lib/providers/tasklists.js +16 -0
- package/lib/providers/tasklists.js.map +1 -0
- package/lib/providers/yaml.d.ts +2 -0
- package/lib/providers/yaml.js +16 -0
- package/lib/providers/yaml.js.map +1 -0
- package/lib/types.d.ts +44 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/lib/widgets.d.ts +15 -0
- package/lib/widgets.js +58 -0
- package/lib/widgets.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
* @jest-environment-options {"url": "https://jestjs.io/"}
|
|
4
|
+
*/
|
|
5
|
+
import { describe, test, expect } from '@jest/globals';
|
|
6
|
+
import MarkdownIt from 'markdown-it';
|
|
7
|
+
import sub from 'markdown-it-sub';
|
|
8
|
+
import sup from 'markdown-it-sup';
|
|
9
|
+
import deflist from 'markdown-it-deflist';
|
|
10
|
+
import figures from 'markdown-it-implicit-figures';
|
|
11
|
+
import footnotes from 'markdown-it-footnote';
|
|
12
|
+
import tasklists from 'markdown-it-task-lists';
|
|
13
|
+
import mermaid from '../plugins/mermaid';
|
|
14
|
+
import attrs from 'markdown-it-attrs';
|
|
15
|
+
import gridtables from '../plugins/gridtables';
|
|
16
|
+
import { citationPlugin as cites } from '../plugins/cites';
|
|
17
|
+
import { calloutPlugin as callouts } from '../plugins/callouts';
|
|
18
|
+
import { divPlugin as divs } from '../plugins/divs';
|
|
19
|
+
import { shortcodePlugin as shortcodes } from '../plugins/shortcodes';
|
|
20
|
+
// Provides resolved MarkdownIt options using the passed in options, the plugin
|
|
21
|
+
// options, and default options.
|
|
22
|
+
const resolveOptions = (options) => {
|
|
23
|
+
// Build options table
|
|
24
|
+
let allOptions = {
|
|
25
|
+
html: true,
|
|
26
|
+
linkify: true,
|
|
27
|
+
typographer: true,
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
...allOptions,
|
|
31
|
+
...options
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
const makeMd = () => {
|
|
35
|
+
// no current plugin uses this parameter
|
|
36
|
+
const options = resolveOptions({});
|
|
37
|
+
let md = new MarkdownIt('default', options)
|
|
38
|
+
.use(sub)
|
|
39
|
+
.use(sup)
|
|
40
|
+
.use(deflist)
|
|
41
|
+
.use(figures, { figcaption: true })
|
|
42
|
+
.use(footnotes)
|
|
43
|
+
.use(tasklists)
|
|
44
|
+
.use(cites)
|
|
45
|
+
.use(mermaid)
|
|
46
|
+
.use(callouts)
|
|
47
|
+
.use(attrs)
|
|
48
|
+
.use(divs)
|
|
49
|
+
.use(gridtables)
|
|
50
|
+
.use(shortcodes);
|
|
51
|
+
return md;
|
|
52
|
+
};
|
|
53
|
+
describe('basic parse', () => {
|
|
54
|
+
test('simple shortcode parser', () => {
|
|
55
|
+
const str = '{{< shortcode >}}';
|
|
56
|
+
const result = '<p><span class="shortcode">{{< shortcode >}}</span></p>\n';
|
|
57
|
+
const md = makeMd();
|
|
58
|
+
expect(md.render(str)).toBe(result);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=index.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.spec.js","sourceRoot":"","sources":["../../src/__tests__/index.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAC,MAAM,eAAe,CAAC;AACrD,OAAO,UAAuB,MAAM,aAAa,CAAC;AAGlD,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAClC,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAClC,OAAO,OAAO,MAAM,qBAAqB,CAAC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CAAC;SACb,GAAG,CAAC,KAAK,CAAC;SACV,GAAG,CAAC,IAAI,CAAC;SACT,GAAG,CAAC,UAAU,CAAC;SACf,GAAG,CAAC,UAAU,CAAC,CAAC;IACnB,OAAO,EAAE,CAAC;AACZ,CAAC,CAAA;AAED,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,IAAI,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACnC,MAAM,GAAG,GAAG,mBAAmB,CAAC;QAChC,MAAM,MAAM,GAAG,iEAAiE,CAAA;QAChF,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;QACpB,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
* @jest-environment-options {"url": "https://jestjs.io/"}
|
|
4
|
+
*/
|
|
5
|
+
import { describe, it, expect } from '@jest/globals';
|
|
6
|
+
describe('myextension', () => {
|
|
7
|
+
it('should be tested', () => {
|
|
8
|
+
expect(1 + 1).toEqual(2);
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=myextension.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"myextension.spec.js","sourceRoot":"","sources":["../../src/__tests__/myextension.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAErD,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,EAAE,CAAC,kBAAkB,EAAE,GAAG,EAAE;QAC1B,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/lib/ast/ast.d.ts
ADDED
package/lib/ast/ast.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export const toAst = (toks) => {
|
|
2
|
+
let pos = 0;
|
|
3
|
+
const inner = () => {
|
|
4
|
+
if (pos >= toks.length)
|
|
5
|
+
return;
|
|
6
|
+
const tok = toks[pos];
|
|
7
|
+
if (tok.type.endsWith('_open')) {
|
|
8
|
+
++pos;
|
|
9
|
+
const children = [];
|
|
10
|
+
while (toks[pos].type !== tok.type.replace('_open', '_close')) {
|
|
11
|
+
children.push(inner());
|
|
12
|
+
}
|
|
13
|
+
++pos;
|
|
14
|
+
return {
|
|
15
|
+
...tok,
|
|
16
|
+
type: tok.type.replace('_open', ''),
|
|
17
|
+
children: children
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if (tok.type === 'inline' && tok.children) {
|
|
21
|
+
const children = toAst(tok.children);
|
|
22
|
+
++pos;
|
|
23
|
+
return {
|
|
24
|
+
...tok,
|
|
25
|
+
children
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
++pos;
|
|
29
|
+
return tok;
|
|
30
|
+
};
|
|
31
|
+
const result = [];
|
|
32
|
+
while (pos < toks.length) {
|
|
33
|
+
const node = inner();
|
|
34
|
+
if (node)
|
|
35
|
+
result.push(node);
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=ast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.js","sourceRoot":"","sources":["../../src/ast/ast.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,IAAa,EAAE,EAAE;IACnC,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,MAAM,KAAK,GAAG,GAAG,EAAE;QACf,IAAI,GAAG,IAAI,IAAI,CAAC,MAAM;YAAE,OAAO;QAC/B,MAAM,GAAG,GAAG,IAAI,CAA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
|
+
import { Token } from '@lumino/coreutils';
|
|
8
|
+
// The namespace for this project
|
|
9
|
+
export const kPackageNamespace = 'jupyterlab-quarto';
|
|
10
|
+
// The MarkdownIt manager token.
|
|
11
|
+
export const kMarkdownItMgr = new Token(kPackageNamespace);
|
|
12
|
+
//# sourceMappingURL=const.js.map
|
package/lib/const.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"const.js","sourceRoot":"","sources":["../src/const.ts"],"names":[],"mappings":"AAAA;;;;;EAKE;AACF,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAI1C,iCAAiC;AACjC,MAAM,CAAC,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAErD,gCAAgC;AAChC,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,KAAK,CAAoB,iBAAiB,CAAC,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* hooks.ts
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2020-2023 Posit Software, PBC
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
import { Mode } from '@jupyterlab/codemirror';
|
|
8
|
+
export function codeMirrorPreloadHook() {
|
|
9
|
+
// TODO: Properly deal with {r}, {{r}} style expressions
|
|
10
|
+
const fenced = new RegExp(/^`{3}([^\s]+)/g);
|
|
11
|
+
return {
|
|
12
|
+
run: async (source) => {
|
|
13
|
+
const newModes = new Map();
|
|
14
|
+
let match;
|
|
15
|
+
while ((match = fenced.exec(source))) {
|
|
16
|
+
if (!newModes.has(match[1])) {
|
|
17
|
+
newModes.set(match[1], Mode.ensure(match[1]));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (newModes.size) {
|
|
21
|
+
Promise.all(newModes.values()).catch(console.warn);
|
|
22
|
+
}
|
|
23
|
+
return source;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export const codeMirrorHighlight = (str, lang) => {
|
|
28
|
+
if (!lang) {
|
|
29
|
+
return ''; // use external default escaping
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const spec = Mode.findBest(lang);
|
|
33
|
+
if (!spec) {
|
|
34
|
+
console.warn(`No CodeMirror mode: ${lang}`);
|
|
35
|
+
return '';
|
|
36
|
+
}
|
|
37
|
+
const el = document.createElement('div');
|
|
38
|
+
try {
|
|
39
|
+
Mode.run(str, spec.mime, el);
|
|
40
|
+
return el.innerHTML;
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
console.warn(`Failed to highlight ${lang} code`, err);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
console.warn(`No CodeMirror mode: ${lang}`);
|
|
48
|
+
console.warn(`Require CodeMirror mode error: ${err}`);
|
|
49
|
+
}
|
|
50
|
+
return '';
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=codemirror.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codemirror.js","sourceRoot":"","sources":["../../src/hooks/codemirror.ts"],"names":[],"mappings":"AAAA;;;;;EAKE;AAGF,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAE9C,MAAM,UAAU,qBAAqB;IACnC,wDAAwD;IACxD,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAE5C,OAAO;QACL,GAAG,EAAE,KAAK,EAAC,MAAM,EAAC,EAAE;YAClB,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC;YACjD,IAAI,KAA8B,CAAC;YACnC,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE;gBACpC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;oBAC3B,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,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rontEndPlugin } from '@jupyterlab/application';
|
|
2
|
+
import { MarkdownItManager } from './types';
|
|
3
|
+
import '../style/index.css';
|
|
4
|
+
declare const _default: (JupyterFrontEndPlugin<void, JupyterFrontEnd.IShell, "desktop" | "mobile"> | JupyterFrontEndPlugin<MarkdownItManager, JupyterFrontEnd.IShell, "desktop" | "mobile">)[];
|
|
5
|
+
export default _default;
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { mermaid } from './providers/mermaid';
|
|
2
|
+
import { kMarkdownItMgr, kPackageNamespace } from './const';
|
|
3
|
+
import { footnotes } from './providers/footnotes';
|
|
4
|
+
import '../style/index.css';
|
|
5
|
+
import { markdownItManager } from './manager';
|
|
6
|
+
import { divs } from './providers/divs';
|
|
7
|
+
import { deflist } from './providers/deflist';
|
|
8
|
+
import { gridtables } from './providers/gridtables';
|
|
9
|
+
import { sub } from './providers/sub';
|
|
10
|
+
import { sup } from './providers/sup';
|
|
11
|
+
import { tasklists } from './providers/tasklists';
|
|
12
|
+
import { cites } from './providers/cites';
|
|
13
|
+
import { attrs } from './providers/attrs';
|
|
14
|
+
import { callouts } from './providers/callouts';
|
|
15
|
+
import { decorator } from './providers/decorator';
|
|
16
|
+
import { yaml } from './providers/yaml';
|
|
17
|
+
import { math } from './providers/math';
|
|
18
|
+
import { figures } from './providers/figures';
|
|
19
|
+
import { figureDivs } from './providers/figure-divs';
|
|
20
|
+
import { tableCaptions } from './providers/table-captions';
|
|
21
|
+
import { spans } from './providers/spans';
|
|
22
|
+
import { shortcodes } from './providers/shortcodes';
|
|
23
|
+
const plugin = {
|
|
24
|
+
id: `${kPackageNamespace}:plugin`,
|
|
25
|
+
autoStart: true,
|
|
26
|
+
provides: kMarkdownItMgr,
|
|
27
|
+
activate: (_app) => {
|
|
28
|
+
console.log('JupyterLab extension jupyterlab-quarto is activated!');
|
|
29
|
+
// Create a markdown rendering manager
|
|
30
|
+
return markdownItManager();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
// Markdown It Extensions which provide base Pandoc behavior
|
|
34
|
+
const kPandocExtensions = [
|
|
35
|
+
footnotes,
|
|
36
|
+
spans,
|
|
37
|
+
attrs,
|
|
38
|
+
deflist,
|
|
39
|
+
figures,
|
|
40
|
+
gridtables,
|
|
41
|
+
sub,
|
|
42
|
+
sup,
|
|
43
|
+
tasklists,
|
|
44
|
+
divs,
|
|
45
|
+
math
|
|
46
|
+
];
|
|
47
|
+
// Markdown It Extensions which provide Quarto specific behavior
|
|
48
|
+
const kQuartoExtensions = [
|
|
49
|
+
figureDivs,
|
|
50
|
+
tableCaptions,
|
|
51
|
+
cites,
|
|
52
|
+
mermaid,
|
|
53
|
+
callouts,
|
|
54
|
+
decorator,
|
|
55
|
+
yaml,
|
|
56
|
+
shortcodes
|
|
57
|
+
];
|
|
58
|
+
// The extensions that should be enabled for Jupyter
|
|
59
|
+
export default [plugin, ...kPandocExtensions, ...kQuartoExtensions];
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,OAAO,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OA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J,UAAU;CACX,CAAC;AAGF,oDAAoD;AACpD,eAAe,CAAC,MAAM,EAAE,GAAG,iBAAiB,EAAE,GAAG,iBAAiB,CAAE,CAAC"}
|
package/lib/manager.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Options } from 'markdown-it';
|
|
2
|
+
import { RenderedMarkdown } from './widgets';
|
|
3
|
+
import { MarkdownItPluginProvider, Renderer } from './types';
|
|
4
|
+
export declare function markdownItManager(): {
|
|
5
|
+
registerPlugin(provider: MarkdownItPluginProvider): void;
|
|
6
|
+
getRenderer(widget: RenderedMarkdown, options?: Options): Promise<Renderer>;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=manager.d.ts.map
|
package/lib/manager.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* manager.ts
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2020-2023 Posit Software, PBC
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
import { markdownRendererFactory } from '@jupyterlab/rendermime';
|
|
8
|
+
import { CodeMirrorEditor } from '@jupyterlab/codemirror';
|
|
9
|
+
import MarkdownIt from 'markdown-it';
|
|
10
|
+
import { RenderedMarkdown } from './widgets';
|
|
11
|
+
import { codeMirrorHighlight, codeMirrorPreloadHook } from './hooks/codemirror';
|
|
12
|
+
// Provides resolved MarkdownIt options using the passed in options, the plugin
|
|
13
|
+
// options, and default options.
|
|
14
|
+
const resolveOptions = (widget, options, providers) => {
|
|
15
|
+
// Build options table
|
|
16
|
+
let allOptions = {
|
|
17
|
+
html: true,
|
|
18
|
+
linkify: true,
|
|
19
|
+
typographer: true,
|
|
20
|
+
langPrefix: `cm-s-${CodeMirrorEditor.defaultConfig.theme} language-`,
|
|
21
|
+
highlight: codeMirrorHighlight
|
|
22
|
+
};
|
|
23
|
+
for (const plugin of providers) {
|
|
24
|
+
if (plugin.options) {
|
|
25
|
+
try {
|
|
26
|
+
// Add options for this plugin
|
|
27
|
+
allOptions = { ...allOptions, ...plugin.options(widget) };
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
console.warn(`Failed to get options from markdown-it plugin ${plugin.id}`, err);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
...allOptions,
|
|
36
|
+
...options
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export function markdownItManager() {
|
|
40
|
+
// The plugin providers
|
|
41
|
+
const pluginProviders = new Map();
|
|
42
|
+
// The IMarkdownItManager
|
|
43
|
+
const manager = {
|
|
44
|
+
registerPlugin(provider) {
|
|
45
|
+
pluginProviders.set(provider.id, provider);
|
|
46
|
+
},
|
|
47
|
+
async getRenderer(widget, options = {}) {
|
|
48
|
+
var _a, _b, _c, _d;
|
|
49
|
+
// Fetch the list of providers
|
|
50
|
+
const providers = [...pluginProviders.values()];
|
|
51
|
+
providers.sort(sortRanked);
|
|
52
|
+
// Create MarkdownIt instance
|
|
53
|
+
const allOptions = resolveOptions(widget, options, providers);
|
|
54
|
+
let md = new MarkdownIt('default', allOptions);
|
|
55
|
+
// Lifecycle hooks
|
|
56
|
+
const preParseHooks = [];
|
|
57
|
+
const postRenderHooks = [];
|
|
58
|
+
// add mode pre-loading hook if using default highlighter
|
|
59
|
+
if (codeMirrorHighlight === allOptions.highlight) {
|
|
60
|
+
preParseHooks.push(codeMirrorPreloadHook());
|
|
61
|
+
}
|
|
62
|
+
// Build MarkdownIt and load lifecycle hooks
|
|
63
|
+
for (const provider of providers) {
|
|
64
|
+
try {
|
|
65
|
+
// Load MarkdownIt plugin
|
|
66
|
+
const [plugin, ...pluginOptions] = await provider.plugin();
|
|
67
|
+
// Build MarkdownIt instance
|
|
68
|
+
md = md.use(plugin, ...pluginOptions);
|
|
69
|
+
// Build table of lifecycle hooks
|
|
70
|
+
if (((_a = provider.hooks) === null || _a === void 0 ? void 0 : _a.preParse) !== undefined) {
|
|
71
|
+
preParseHooks.push((_b = provider.hooks) === null || _b === void 0 ? void 0 : _b.preParse);
|
|
72
|
+
}
|
|
73
|
+
if (((_c = provider.hooks) === null || _c === void 0 ? void 0 : _c.postRender) !== undefined) {
|
|
74
|
+
postRenderHooks.push((_d = provider.hooks) === null || _d === void 0 ? void 0 : _d.postRender);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
console.warn(`Failed to load/use markdown-it plugin ${provider.id}`, err);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Sort hooks by rank
|
|
82
|
+
preParseHooks.sort(sortRanked);
|
|
83
|
+
postRenderHooks.sort(sortRanked);
|
|
84
|
+
return {
|
|
85
|
+
// Parse and render Markdown
|
|
86
|
+
render: (content) => {
|
|
87
|
+
return md.render(content);
|
|
88
|
+
},
|
|
89
|
+
// Run hooks serially
|
|
90
|
+
preParse: async (content) => {
|
|
91
|
+
for (const hook of preParseHooks) {
|
|
92
|
+
content = await hook.run(content);
|
|
93
|
+
}
|
|
94
|
+
return content;
|
|
95
|
+
},
|
|
96
|
+
// Run hooks serially
|
|
97
|
+
postRender: async (node) => {
|
|
98
|
+
for (const hook of postRenderHooks) {
|
|
99
|
+
await hook.run(node);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
// Register the Renderer
|
|
106
|
+
markdownRendererFactory.createRenderer = (options) => {
|
|
107
|
+
return new RenderedMarkdown(options, manager);
|
|
108
|
+
};
|
|
109
|
+
return manager;
|
|
110
|
+
}
|
|
111
|
+
// Sorts by rank, using 100 if no default is provided.
|
|
112
|
+
const kDefaultRank = 100;
|
|
113
|
+
const sortRanked = (left, right) => {
|
|
114
|
+
var _a, _b;
|
|
115
|
+
return ((_a = left.rank) !== null && _a !== void 0 ? _a : kDefaultRank) - ((_b = right.rank) !== null && _b !== void 0 ? _b : kDefaultRank);
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingUR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IACjD,OAAO,CAAC,MAAA,IAAI,CAAC,IAAI,mCAAI,YAAY,CAAC,GAAG,CAAC,MAAA,KAAK,CAAC,IAAI,mCAAI,YAAY,CAAC,CAAC;AACpE,CAAC,CAAA"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import Token from "markdown-it/lib/token";
|
|
2
|
+
import { addClass, readAttrValue } from "./utils/markdownit";
|
|
3
|
+
import { kTokDivClose, kTokDivOpen } from "./divs";
|
|
4
|
+
const kTokCalloutOpen = "quarto_callout_open";
|
|
5
|
+
const kTokCalloutClose = "quarto_callout_close";
|
|
6
|
+
const kTokCalloutTitleOpen = "quarto_callout_title_open";
|
|
7
|
+
const kTokCalloutTitleClose = "quarto_callout_title_close";
|
|
8
|
+
const kTokCalloutContentOpen = "quarto_callout_content_open";
|
|
9
|
+
const kTokCalloutContentClose = "quarto_callout_content_close";
|
|
10
|
+
const kCalloutPrefix = "callout-";
|
|
11
|
+
const kCalloutRuleName = "quarto-callouts";
|
|
12
|
+
export const calloutPlugin = (md) => {
|
|
13
|
+
// Handle pandoc-style divs
|
|
14
|
+
md.core.ruler.push(kCalloutRuleName, (state) => {
|
|
15
|
+
const noteStartCallout = (callout, depth) => {
|
|
16
|
+
if (calloutDepth == -1) {
|
|
17
|
+
calloutDepth = depth;
|
|
18
|
+
}
|
|
19
|
+
state.env['quarto-active-callout'] = callout;
|
|
20
|
+
};
|
|
21
|
+
const noteCloseCallout = () => {
|
|
22
|
+
calloutDepth = -1;
|
|
23
|
+
state.env['quarto-active-callout'] = undefined;
|
|
24
|
+
};
|
|
25
|
+
const activeCallout = () => {
|
|
26
|
+
return state.env['quarto-active-callout'];
|
|
27
|
+
};
|
|
28
|
+
const isCloseCallout = (depth) => {
|
|
29
|
+
return calloutDepth === depth;
|
|
30
|
+
};
|
|
31
|
+
const titleOpenTok = (title) => {
|
|
32
|
+
const token = new Token(kTokCalloutTitleOpen, "", 1);
|
|
33
|
+
token.tag = "div";
|
|
34
|
+
token.attrs = [["class", "callout-header"]];
|
|
35
|
+
if (title) {
|
|
36
|
+
token.attrs.push(["title", title]);
|
|
37
|
+
}
|
|
38
|
+
return token;
|
|
39
|
+
};
|
|
40
|
+
const titleCloseTok = () => {
|
|
41
|
+
const token = new Token(kTokCalloutTitleClose, "", -1);
|
|
42
|
+
token.tag = "div";
|
|
43
|
+
return token;
|
|
44
|
+
};
|
|
45
|
+
const contentOpenTok = () => {
|
|
46
|
+
const token = new Token(kTokCalloutContentOpen, "", 1);
|
|
47
|
+
token.tag = "div";
|
|
48
|
+
token.attrs = [["class", "callout-body-container callout-body"]];
|
|
49
|
+
return token;
|
|
50
|
+
};
|
|
51
|
+
const contentCloseTok = () => {
|
|
52
|
+
const token = new Token(kTokCalloutContentClose, "", -1);
|
|
53
|
+
token.tag = "div";
|
|
54
|
+
return token;
|
|
55
|
+
};
|
|
56
|
+
const outTokens = [];
|
|
57
|
+
let calloutDepth = -1;
|
|
58
|
+
let divDepth = 0;
|
|
59
|
+
// just started callout - process title
|
|
60
|
+
// finished processing title - process content
|
|
61
|
+
let calloutState = "scanning";
|
|
62
|
+
for (const token of state.tokens) {
|
|
63
|
+
switch (calloutState) {
|
|
64
|
+
case "add-title":
|
|
65
|
+
if (token.type === "heading_open") {
|
|
66
|
+
outTokens.push(titleOpenTok());
|
|
67
|
+
calloutState = "capturing-title";
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
const callout = activeCallout();
|
|
71
|
+
outTokens.push(titleOpenTok(callout.title));
|
|
72
|
+
outTokens.push(titleCloseTok());
|
|
73
|
+
calloutState = "add-body";
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
case "capturing-title":
|
|
77
|
+
if (token.type === "heading_close") {
|
|
78
|
+
outTokens.push(titleCloseTok());
|
|
79
|
+
calloutState = "add-body";
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
outTokens.push(token);
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
case "add-body":
|
|
86
|
+
outTokens.push(contentOpenTok());
|
|
87
|
+
outTokens.push(token);
|
|
88
|
+
calloutState = "capturing-body";
|
|
89
|
+
break;
|
|
90
|
+
case "scanning":
|
|
91
|
+
default:
|
|
92
|
+
if (token.type === kTokDivOpen) {
|
|
93
|
+
divDepth++;
|
|
94
|
+
const callout = parseCallout(token.attrs);
|
|
95
|
+
if (callout) {
|
|
96
|
+
noteStartCallout(callout, divDepth);
|
|
97
|
+
calloutState = "add-title";
|
|
98
|
+
const openCallout = new Token(kTokCalloutOpen, "", 1);
|
|
99
|
+
openCallout.attrs = openCallout.attrs || [];
|
|
100
|
+
openCallout.meta = callout;
|
|
101
|
+
outTokens.push(openCallout);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
outTokens.push(token);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else if (token.type === kTokDivClose) {
|
|
108
|
+
if (isCloseCallout(divDepth)) {
|
|
109
|
+
outTokens.push(contentCloseTok());
|
|
110
|
+
outTokens.push(new Token(kTokCalloutClose, "", -1));
|
|
111
|
+
noteCloseCallout();
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
outTokens.push(token);
|
|
115
|
+
}
|
|
116
|
+
divDepth--;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
outTokens.push(token);
|
|
120
|
+
}
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
state.tokens = outTokens;
|
|
125
|
+
return false;
|
|
126
|
+
});
|
|
127
|
+
md.renderer.rules[kTokCalloutOpen] = renderStartCallout;
|
|
128
|
+
md.renderer.rules[kTokCalloutClose] = renderEndCallout;
|
|
129
|
+
md.renderer.rules[kTokCalloutTitleOpen] = renderStartCalloutTitle;
|
|
130
|
+
md.renderer.rules[kTokCalloutTitleClose] = renderEndCalloutTitle;
|
|
131
|
+
};
|
|
132
|
+
// Render pandoc-style divs
|
|
133
|
+
function renderStartCallout(tokens, idx, _options, _env, self) {
|
|
134
|
+
const token = tokens[idx];
|
|
135
|
+
const callout = token.meta;
|
|
136
|
+
// Add classes decorating as callout
|
|
137
|
+
token.attrs = addClass(`callout ${callout.clz}`, token.attrs);
|
|
138
|
+
// Add class that reflects the style
|
|
139
|
+
token.attrs = addClass(appearanceClass(callout.appearance), token.attrs);
|
|
140
|
+
return `<div ${self.renderAttrs(token)}>`;
|
|
141
|
+
}
|
|
142
|
+
// Render pandoc-style divs
|
|
143
|
+
function renderEndCallout() {
|
|
144
|
+
return `</div>`;
|
|
145
|
+
}
|
|
146
|
+
function renderStartCalloutTitle(tokens, idx) {
|
|
147
|
+
const token = tokens[idx];
|
|
148
|
+
const title = readAttrValue("title", token.attrs) || "";
|
|
149
|
+
const startContent = `
|
|
150
|
+
<div class="callout-header">
|
|
151
|
+
<div class="callout-icon-container">
|
|
152
|
+
<i class="callout-icon"></i>
|
|
153
|
+
</div>
|
|
154
|
+
<div class="callout-title-container">${title}
|
|
155
|
+
`;
|
|
156
|
+
return startContent;
|
|
157
|
+
}
|
|
158
|
+
function renderEndCalloutTitle() {
|
|
159
|
+
return `</div>\n</div>`;
|
|
160
|
+
}
|
|
161
|
+
const calloutAppearance = (val) => {
|
|
162
|
+
if (val) {
|
|
163
|
+
switch (val) {
|
|
164
|
+
case "minimal":
|
|
165
|
+
return "minimal";
|
|
166
|
+
case "simple":
|
|
167
|
+
return "simple";
|
|
168
|
+
case "default":
|
|
169
|
+
default:
|
|
170
|
+
return "default";
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
return "default";
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
const parseCallout = (attrs) => {
|
|
178
|
+
if (attrs === null) {
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
const classAttr = attrs.find((attr) => { return attr[0] === "class"; });
|
|
182
|
+
if (!classAttr) {
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
const classes = classAttr[1].split(" ");
|
|
186
|
+
const calloutClass = classes.find((clz) => {
|
|
187
|
+
return clz.startsWith('callout-');
|
|
188
|
+
});
|
|
189
|
+
if (calloutClass) {
|
|
190
|
+
const type = calloutClass.replace(kCalloutPrefix, "");
|
|
191
|
+
const title = readAttrValue("title", attrs) || type.slice(0, 1).toUpperCase() + type.slice(1);
|
|
192
|
+
;
|
|
193
|
+
const appearance = calloutAppearance(readAttrValue("appearance", attrs));
|
|
194
|
+
return {
|
|
195
|
+
type: type || "note",
|
|
196
|
+
clz: calloutClass,
|
|
197
|
+
title,
|
|
198
|
+
appearance
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
const appearanceClass = (appearance) => {
|
|
206
|
+
const style = appearance || "default";
|
|
207
|
+
return `callout-style-${style}`;
|
|
208
|
+
};
|
|
209
|
+
//# sourceMappingURL=callouts.js.map
|