@inshapardaz/likhari-converters 0.1.17 → 0.1.18-dev.126
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/dist/html/parse.d.ts.map +1 -1
- package/dist/html/parse.js +21 -0
- package/dist/html/serialize.d.ts.map +1 -1
- package/dist/html/serialize.js +8 -0
- package/dist/markdown/parse.d.ts.map +1 -1
- package/dist/markdown/parse.js +7 -0
- package/dist/markdown/serialize.d.ts.map +1 -1
- package/dist/markdown/serialize.js +8 -0
- package/dist/plain-text/index.d.ts.map +1 -1
- package/dist/plain-text/index.js +9 -0
- package/package.json +1 -1
package/dist/html/parse.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/html/parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAiCjD,kEAAkE;AAClE,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAIlD;AAED,wEAAwE;AACxE,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKvD;
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/html/parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAiCjD,kEAAkE;AAClE,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAIlD;AAED,wEAAwE;AACxE,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKvD;AA4UD,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,qBAAqB,CAMvF"}
|
package/dist/html/parse.js
CHANGED
|
@@ -251,6 +251,25 @@ function convertLayout(container) {
|
|
|
251
251
|
const templateColumns = container.style.gridTemplateColumns || `repeat(${Math.max(items.length, 2)}, 1fr)`;
|
|
252
252
|
return elementBase('layout-container', items.length > 0 ? items : [elementBase('layout-item', [paragraph()])], { templateColumns });
|
|
253
253
|
}
|
|
254
|
+
const POETRY_LAYOUTS = new Set(['single', 'two-column']);
|
|
255
|
+
const POETRY_ALIGNS = new Set(['justify', 'left', 'right', 'start']);
|
|
256
|
+
function convertPoetry(el) {
|
|
257
|
+
const rawLayout = el.getAttribute('data-likhari-poetry-layout') ?? 'single';
|
|
258
|
+
const layout = POETRY_LAYOUTS.has(rawLayout) ? rawLayout : 'single';
|
|
259
|
+
const rawAlign = el.getAttribute('data-likhari-poetry-align') ?? 'justify';
|
|
260
|
+
const align = POETRY_ALIGNS.has(rawAlign) ? rawAlign : 'justify';
|
|
261
|
+
if (layout === 'two-column') {
|
|
262
|
+
const containerEl = Array.from(el.children).find((c) => c.hasAttribute('data-likhari-layout-container'));
|
|
263
|
+
const container = containerEl
|
|
264
|
+
? convertLayout(containerEl)
|
|
265
|
+
: elementBase('layout-container', [elementBase('layout-item', [paragraph()]), elementBase('layout-item', [paragraph()])], {
|
|
266
|
+
templateColumns: 'repeat(2, 1fr)',
|
|
267
|
+
});
|
|
268
|
+
return elementBase('poetry-couplet', [container], { layout, align });
|
|
269
|
+
}
|
|
270
|
+
const children = flowBlocks(el);
|
|
271
|
+
return elementBase('poetry-couplet', children.length > 0 ? children : [paragraph(), paragraph()], { layout, align });
|
|
272
|
+
}
|
|
254
273
|
function convertFootnoteList(el) {
|
|
255
274
|
const items = [];
|
|
256
275
|
Array.from(el.children).forEach((child) => {
|
|
@@ -341,6 +360,8 @@ function convertBlock(el) {
|
|
|
341
360
|
return [{ type: 'page-break', version: 1 }];
|
|
342
361
|
if (el.hasAttribute('data-likhari-layout-container'))
|
|
343
362
|
return [convertLayout(el)];
|
|
363
|
+
if (el.hasAttribute('data-likhari-poetry-layout'))
|
|
364
|
+
return [convertPoetry(el)];
|
|
344
365
|
return flowBlocks(el);
|
|
345
366
|
case 'figcaption':
|
|
346
367
|
return [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../src/html/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAEkG,KAAK,KAAK,EAClH,MAAM,sBAAsB,CAAC;AAE9B,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD;
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../src/html/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAEkG,KAAK,KAAK,EAClH,MAAM,sBAAsB,CAAC;AAE9B,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD;AAuID,wBAAgB,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,EAAE,gBAAgB,GAAG,MAAM,CA+CtE;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,qBAAqB,EAAE,GAAG,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAI1F"}
|
package/dist/html/serialize.js
CHANGED
|
@@ -115,6 +115,12 @@ function layoutToHtml(node, ctx) {
|
|
|
115
115
|
.join('');
|
|
116
116
|
return `<div data-likhari-layout-container style="display: grid; grid-template-columns: ${escapeAttr(templateColumns)}">${columns}</div>`;
|
|
117
117
|
}
|
|
118
|
+
function poetryToHtml(node, ctx) {
|
|
119
|
+
const layout = node.layout === 'two-column' ? 'two-column' : 'single';
|
|
120
|
+
const align = typeof node.align === 'string' ? node.align : 'justify';
|
|
121
|
+
const inner = (node.children ?? []).map((child) => nodeToHtml(child, ctx)).join('');
|
|
122
|
+
return `<div data-likhari-poetry-layout="${layout}" data-likhari-poetry-align="${align}" style="text-align: ${escapeAttr(align)}">${inner}</div>`;
|
|
123
|
+
}
|
|
118
124
|
function imageToHtml(node, ctx) {
|
|
119
125
|
const rawSrc = String(node.src ?? '');
|
|
120
126
|
const src = ctx?.resolveImageUrl ? ctx.resolveImageUrl(rawSrc) : rawSrc;
|
|
@@ -167,6 +173,8 @@ export function nodeToHtml(node, ctx) {
|
|
|
167
173
|
return footnoteReferenceToHtml(node);
|
|
168
174
|
case 'footnote-list':
|
|
169
175
|
return footnoteListToHtml(node, ctx);
|
|
176
|
+
case 'poetry-couplet':
|
|
177
|
+
return poetryToHtml(node, ctx);
|
|
170
178
|
default:
|
|
171
179
|
// Unknown node (e.g. a future feature): keep its content, drop the wrapper.
|
|
172
180
|
return inlineChildren(node, ctx);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/markdown/parse.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/markdown/parse.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAwTjD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,qBAAqB,CAO3F"}
|
package/dist/markdown/parse.js
CHANGED
|
@@ -237,6 +237,13 @@ function blocks(nodes, extra = {}) {
|
|
|
237
237
|
out.push(elementBase('layout-container', columns, { templateColumns: `repeat(${columns.length}, 1fr)` }));
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
|
+
else if (node.name === 'poetry') {
|
|
241
|
+
const attrs = node.attributes ?? {};
|
|
242
|
+
const layout = attrs.layout === 'two-column' ? 'two-column' : 'single';
|
|
243
|
+
const align = ALIGNMENTS.has(attrs.align ?? '') ? attrs.align : 'justify';
|
|
244
|
+
const children = blocks(node.children ?? []);
|
|
245
|
+
out.push(elementBase('poetry-couplet', children.length > 0 ? children : [paragraph(), paragraph()], { layout, align }));
|
|
246
|
+
}
|
|
240
247
|
else {
|
|
241
248
|
// Unknown containers (including a stray "column" outside "columns")
|
|
242
249
|
// are transparent: their content is kept.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../src/markdown/serialize.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAKjD,OAAO,EAAa,KAAK,KAAK,EAAe,MAAM,SAAS,CAAC;AAyC7D,2GAA2G;AAC3G,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAUjD;AAqHD,wFAAwF;AACxF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,IAAI,CAMhE;
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../src/markdown/serialize.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAKjD,OAAO,EAAa,KAAK,KAAK,EAAe,MAAM,SAAS,CAAC;AAyC7D,2GAA2G;AAC3G,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAUjD;AAqHD,wFAAwF;AACxF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,IAAI,CAMhE;AAoID,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,qBAAqB,EAAE,GAAG,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAI9F"}
|
|
@@ -246,6 +246,12 @@ function layoutToMd(node, ctx) {
|
|
|
246
246
|
const columns = items.map((item) => directive('containerDirective', 'column', {}, (item.children ?? []).flatMap((child) => blockToMd(child, ctx))));
|
|
247
247
|
return directive('containerDirective', 'columns', { count: String(items.length) }, columns);
|
|
248
248
|
}
|
|
249
|
+
function poetryToMd(node, ctx) {
|
|
250
|
+
const layout = node.layout === 'two-column' ? 'two-column' : 'single';
|
|
251
|
+
const align = typeof node.align === 'string' ? node.align : 'justify';
|
|
252
|
+
const inner = (node.children ?? []).flatMap((child) => blockToMd(child, ctx));
|
|
253
|
+
return directive('containerDirective', 'poetry', { layout, align }, inner);
|
|
254
|
+
}
|
|
249
255
|
function tableToMd(node, ctx) {
|
|
250
256
|
const rows = (node.children ?? []).map((row) => ({
|
|
251
257
|
type: 'tableRow',
|
|
@@ -289,6 +295,8 @@ function blockToMd(node, ctx) {
|
|
|
289
295
|
return [tableToMd(node, ctx)];
|
|
290
296
|
case 'layout-container':
|
|
291
297
|
return [layoutToMd(node, ctx)];
|
|
298
|
+
case 'poetry-couplet':
|
|
299
|
+
return [poetryToMd(node, ctx)];
|
|
292
300
|
case 'footnote-list':
|
|
293
301
|
return (node.children ?? []).map((item) => ({
|
|
294
302
|
type: 'footnoteDefinition',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plain-text/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plain-text/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAuFhD,eAAO,MAAM,kBAAkB,EAAE,eAsDhC,CAAC"}
|
package/dist/plain-text/index.js
CHANGED
|
@@ -27,6 +27,15 @@ function nodeToText(node, order, listItemIndex = 0) {
|
|
|
27
27
|
const id = String(node.footnoteId ?? '');
|
|
28
28
|
return `[${order.get(id) ?? '?'}]`;
|
|
29
29
|
}
|
|
30
|
+
// Linearized per the fidelity matrix ("Poetry layout variants ⚠️ linearized"):
|
|
31
|
+
// the two misras, one per line, regardless of single/two-column layout —
|
|
32
|
+
// the columns primitive a two-column couplet is built on otherwise has no
|
|
33
|
+
// per-node case and would fall through to running the lines together.
|
|
34
|
+
if (node.type === 'poetry-couplet') {
|
|
35
|
+
const children = withChildren.children ?? [];
|
|
36
|
+
const misraHolders = children[0]?.type === 'layout-container' ? (children[0].children ?? []) : children;
|
|
37
|
+
return misraHolders.map((child) => nodeToText(child, order)).join('\n');
|
|
38
|
+
}
|
|
30
39
|
if (node.type === 'list' && withChildren.children) {
|
|
31
40
|
const listType = node.listType ?? 'bullet';
|
|
32
41
|
return withChildren.children
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inshapardaz/likhari-converters",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18-dev.126",
|
|
4
4
|
"description": "Format transformers (Markdown/HTML/plain-text/Lexical JSON) against the canonical Lexical EditorState, isolated from UI.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|