@oml/markdown 0.14.17 → 0.16.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 (38) hide show
  1. package/out/md/md-frontmatter.d.ts +1 -1
  2. package/out/md/md-frontmatter.js +6 -11
  3. package/out/md/md-frontmatter.js.map +1 -1
  4. package/out/md/md-runtime.js +26 -7
  5. package/out/md/md-runtime.js.map +1 -1
  6. package/out/md/md-types.d.ts +2 -2
  7. package/out/renderers/table-renderer.js +12 -4
  8. package/out/renderers/table-renderer.js.map +1 -1
  9. package/out/static/browser-runtime.bundle.js +718 -14
  10. package/out/static/browser-runtime.bundle.js.map +3 -3
  11. package/out/static/browser-runtime.js +748 -1
  12. package/out/static/browser-runtime.js.map +1 -1
  13. package/out/static/runtime-assets.d.ts +1 -1
  14. package/out/static/runtime-assets.js +3 -0
  15. package/out/static/runtime-assets.js.map +1 -1
  16. package/out/template/binder.js +156 -32
  17. package/out/template/binder.js.map +1 -1
  18. package/out/template/compose.d.ts +1 -2
  19. package/out/template/compose.js +7 -41
  20. package/out/template/compose.js.map +1 -1
  21. package/out/template/definition.js +0 -11
  22. package/out/template/definition.js.map +1 -1
  23. package/out/template/engine.js +1 -1
  24. package/out/template/engine.js.map +1 -1
  25. package/out/template/types.d.ts +0 -2
  26. package/package.json +2 -2
  27. package/src/md/md-frontmatter.ts +6 -11
  28. package/src/md/md-runtime.ts +29 -7
  29. package/src/md/md-types.ts +2 -2
  30. package/src/renderers/table-renderer.ts +13 -4
  31. package/src/static/browser-runtime.ts +803 -1
  32. package/src/static/markdown-webview.css +88 -1
  33. package/src/static/runtime-assets.ts +3 -0
  34. package/src/template/binder.ts +165 -35
  35. package/src/template/compose.ts +8 -45
  36. package/src/template/definition.ts +0 -12
  37. package/src/template/engine.ts +1 -1
  38. package/src/template/types.ts +0 -9
@@ -1,11 +1,9 @@
1
1
  export type TemplateValue = string | number | boolean | null | string[] | Record<string, unknown>;
2
2
  export type TemplateParameterType = 'iri' | 'string' | 'number' | 'boolean' | 'iri[]' | 'json';
3
- export type TemplateBindingSource = 'context.member' | 'context.ontology' | 'context.modelUri' | `context.selection[${number}]` | 'context.selection[*]' | 'user';
4
3
  export interface TemplateParameterDefinition {
5
4
  id: string;
6
5
  type: TemplateParameterType;
7
6
  required?: boolean;
8
- from?: TemplateBindingSource;
9
7
  defaultValue?: TemplateValue;
10
8
  description?: string;
11
9
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oml/markdown",
3
3
  "description": "Markdown runtime and execution contracts for OML",
4
- "version": "0.14.17",
4
+ "version": "0.16.0",
5
5
  "type": "module",
6
6
  "engines": {
7
7
  "node": ">=20.10.0",
@@ -56,7 +56,7 @@
56
56
  "dependencies": {
57
57
  "@antv/x6": "^3.1.6",
58
58
  "@dagrejs/dagre": "^2.0.4",
59
- "@oml/owl": "0.14.17",
59
+ "@oml/owl": "0.16.0",
60
60
  "chart.js": "^4.4.0",
61
61
  "markdown-it": "^14.1.1",
62
62
  "reflect-metadata": "^0.2.2",
@@ -22,7 +22,7 @@ export function extractLeadingFrontMatter(markdown: string): MarkdownFrontMatter
22
22
  const yamlData = parseYamlMap(yamlBody);
23
23
  return {
24
24
  raw: yamlMatch[1],
25
- contextOntologyIri: extractContextIriFromData(yamlData) ?? extractContextIri(yamlMatch[1]),
25
+ ontology: extractOntologyFromData(yamlData) ?? extractOntology(yamlMatch[1]),
26
26
  data: yamlData,
27
27
  };
28
28
  }
@@ -30,29 +30,24 @@ export function extractLeadingFrontMatter(markdown: string): MarkdownFrontMatter
30
30
  if (tomlMatch) {
31
31
  return {
32
32
  raw: tomlMatch[1],
33
- contextOntologyIri: extractContextIri(tomlMatch[1])
33
+ ontology: extractOntology(tomlMatch[1])
34
34
  };
35
35
  }
36
36
  return undefined;
37
37
  }
38
38
 
39
- export function extractContextIri(frontMatterRaw: string): string | undefined {
40
- const match = /^ontologyIri\s*:\s*(.+)$/m.exec(frontMatterRaw)
41
- ?? /^ontology\s*:\s*(.+)$/m.exec(frontMatterRaw);
39
+ export function extractOntology(frontMatterRaw: string): string | undefined {
40
+ const match = /^ontology\s*:\s*(.+)$/m.exec(frontMatterRaw);
42
41
  if (!match) {
43
42
  return undefined;
44
43
  }
45
44
  return match[1].trim().replace(/^['"]|['"]$/g, '');
46
45
  }
47
46
 
48
- function extractContextIriFromData(data: Record<string, unknown> | undefined): string | undefined {
47
+ function extractOntologyFromData(data: Record<string, unknown> | undefined): string | undefined {
49
48
  if (!data) {
50
49
  return undefined;
51
50
  }
52
- const value = typeof data.ontologyIri === 'string'
53
- ? data.ontologyIri
54
- : typeof data.ontology === 'string'
55
- ? data.ontology
56
- : undefined;
51
+ const value = typeof data.ontology === 'string' ? data.ontology : undefined;
57
52
  return typeof value === 'string' ? value : undefined;
58
53
  }
@@ -7,6 +7,8 @@ import { extractLeadingFrontMatter, stripLeadingFrontMatter } from './md-frontma
7
7
  import { MarkdownHandlerRegistry } from './md-registry.js';
8
8
  import { parseYamlMap } from './md-yaml.js';
9
9
  import type { ParsedCodeBlock, PreparedCodeBlock, PreparedMarkdownDocument } from './md-types.js';
10
+ import { interpolateTemplateBody } from '../template/engine.js';
11
+ import type { TemplateValue } from '../template/types.js';
10
12
 
11
13
  export class MarkdownPreviewRuntime {
12
14
  private readonly renderer: MarkdownIt;
@@ -18,20 +20,32 @@ export class MarkdownPreviewRuntime {
18
20
  typographer: false,
19
21
  });
20
22
  this.renderer.inline.ruler.before('link', 'wiki-link', wikilinkRule);
23
+ this.renderer.renderer.rules.fence = (tokens, idx): string => {
24
+ const token = tokens[idx];
25
+ const language = parseLanguage(token.info);
26
+ const parsed = parseBlockOptions(token.content);
27
+ const blockId = buildBlockId(language, parsed.content);
28
+ const langAttr = language ? ` class="language-${escAttr(language)}"` : '';
29
+ const escaped = escContent(token.content);
30
+ return `<pre data-oml-block-id="${escAttr(blockId)}"><code${langAttr}>${escaped}</code></pre>\n`;
31
+ };
21
32
  }
22
33
 
23
34
  prepare(markdown: string): PreparedMarkdownDocument {
24
35
  const frontMatter = extractLeadingFrontMatter(markdown);
25
36
  const stripped = stripLeadingFrontMatter(markdown);
26
- const codeBlocks = this.parseCodeBlocks(stripped);
37
+ const body = frontMatter?.data && Object.keys(frontMatter.data).length > 0
38
+ ? interpolateTemplateBody(stripped, frontMatter.data as Record<string, TemplateValue>)
39
+ : stripped;
40
+ const codeBlocks = this.parseCodeBlocks(body);
27
41
  const executableBlocks = this.resolveExecutableBlocks(codeBlocks);
28
- const renderedHtml = this.renderer.render(stripped);
42
+ const renderedHtml = this.renderer.render(body);
29
43
 
30
44
  return {
31
- markdown: stripped,
45
+ markdown: body,
32
46
  renderedHtml,
33
47
  frontMatter,
34
- contextOntologyIri: frontMatter?.contextOntologyIri,
48
+ ontology: frontMatter?.ontology,
35
49
  codeBlocks,
36
50
  executableBlocks
37
51
  };
@@ -51,7 +65,7 @@ export class MarkdownPreviewRuntime {
51
65
  const lineEnd = token.map?.[1] ?? lineStart;
52
66
  const parsed = parseBlockOptions(token.content);
53
67
  blocks.push({
54
- id: buildBlockId(lineStart, lineEnd, language, parsed.content),
68
+ id: buildBlockId(language, parsed.content),
55
69
  language,
56
70
  meta,
57
71
  content: parsed.content,
@@ -115,6 +129,14 @@ const wikilinkRule: RuleInline = (state, silent): boolean => {
115
129
  return true;
116
130
  };
117
131
 
132
+ function escAttr(str: string): string {
133
+ return str.replace(/&/g, '&amp;').replace(/"/g, '&quot;');
134
+ }
135
+
136
+ function escContent(str: string): string {
137
+ return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
138
+ }
139
+
118
140
  function parseBlockOptions(content: string): { content: string; options?: Record<string, unknown> } {
119
141
  const normalized = content.replace(/^\uFEFF/, '');
120
142
  const match = /^(---\s*\r?\n[\s\S]*?\r?\n---\s*\r?\n?)([\s\S]*)$/.exec(normalized);
@@ -151,8 +173,8 @@ function parseMeta(info: string): string | undefined {
151
173
  return trimmed.slice(index + 1).trim() || undefined;
152
174
  }
153
175
 
154
- function buildBlockId(lineStart: number, lineEnd: number, language: string, content: string): string {
155
- return `block-${lineStart}-${lineEnd}-${hash32(`${language}|${content}`)}`;
176
+ function buildBlockId(language: string, content: string): string {
177
+ return `block-${language}-${hash32(`${language}|${content}`)}`;
156
178
  }
157
179
 
158
180
  function hash32(input: string): string {
@@ -12,7 +12,7 @@ export interface ParsedCodeBlock {
12
12
 
13
13
  export interface MarkdownFrontMatter {
14
14
  raw: string;
15
- contextOntologyIri?: string;
15
+ ontology?: string;
16
16
  data?: Record<string, unknown>;
17
17
  }
18
18
 
@@ -25,7 +25,7 @@ export interface PreparedMarkdownDocument {
25
25
  markdown: string;
26
26
  renderedHtml: string;
27
27
  frontMatter?: MarkdownFrontMatter;
28
- contextOntologyIri?: string;
28
+ ontology?: string;
29
29
  codeBlocks: ParsedCodeBlock[];
30
30
  executableBlocks: PreparedCodeBlock[];
31
31
  }
@@ -49,6 +49,14 @@ type TableRendererWindow = Window & typeof globalThis & {
49
49
  __omlSetPersistedTableUiState?: (blockId: string, state: PersistedTableUiState) => void;
50
50
  };
51
51
 
52
+ function buildTableUiStateKey(blockId: string | undefined): string | undefined {
53
+ if (typeof blockId !== 'string' || blockId.length === 0) {
54
+ return undefined;
55
+ }
56
+ const pageKey = `${window.location.origin}${window.location.pathname}`;
57
+ return `${pageKey}::${blockId}`;
58
+ }
59
+
52
60
  export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
53
61
  protected readonly tableKinds: ReadonlyArray<TableBlockKind> = ['table'];
54
62
 
@@ -165,8 +173,9 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
165
173
  const fullyExpandedTreeRows = isTree && treeModel
166
174
  ? this.flattenAllTreeRows(treeModel)
167
175
  : undefined;
168
- const persistedState = blockId
169
- ? (window as TableRendererWindow).__omlGetPersistedTableUiState?.(blockId)
176
+ const tableUiStateKey = buildTableUiStateKey(blockId);
177
+ const persistedState = tableUiStateKey
178
+ ? (window as TableRendererWindow).__omlGetPersistedTableUiState?.(tableUiStateKey)
170
179
  : undefined;
171
180
 
172
181
  const state = {
@@ -182,10 +191,10 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
182
191
  };
183
192
 
184
193
  const persistUiState = () => {
185
- if (!blockId) {
194
+ if (!tableUiStateKey) {
186
195
  return;
187
196
  }
188
- (window as TableRendererWindow).__omlSetPersistedTableUiState?.(blockId, {
197
+ (window as TableRendererWindow).__omlSetPersistedTableUiState?.(tableUiStateKey, {
189
198
  search: state.search,
190
199
  pageSize: state.pageSize,
191
200
  page: state.page,