inkpen 0.9.1 → 0.9.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82ea78d50df5410aabd191ea25e49c9ab48af1eef675730800c9da56da7334e3
4
- data.tar.gz: 8548b3d724fb90ffe29425f21d05262456668ddb3a1de61dd294167b0df1bbc5
3
+ metadata.gz: 92089e260ac3068e3e269e864d4ec9f0294447bbb4e28764f02f5c722debc155
4
+ data.tar.gz: 1b824dd56c5ccd3f1c448cf841ea53db2660617f14a6b4fe5a41ee9b20f15f7e
5
5
  SHA512:
6
- metadata.gz: bf1b3f8eeff1b7473d36404621c9786447a8dec4298838c4257f666ba3249f0f6000999d39dc8c0876ee0017422d9f18799e57376e0f5ff71e998f756cf635a7
7
- data.tar.gz: '09ae1684455de6530e3deb50f75c36a853ff8067640c1b9ade012089c2a8595e1f49869e04b5aaeb86d03c327fb8d01e9e74850a32dc6d928b92f43a2c21e129'
6
+ metadata.gz: 5d6ceb94d0867ab0b0a5194f6a1468454c1ef8b6782b94cd62ce469a15667ca04ad3c764681130c1e148cc823ef0b8cdd770a0822a01ffb402be632300869ce0
7
+ data.tar.gz: 9420e9694ce248bec30176e60e26a3521749a1e7b5463ba14423a58b87df6b18b40a82b82ff5ab9aa1f9146637f8330e32f1abb309744ca89d09346deaa28e89
@@ -200,6 +200,7 @@ const EXTENSION_LOADERS = {
200
200
  // surface. Not part of the public gem API; the controller is the only
201
201
  // production consumer.
202
202
  export const __EXTENSION_LOADER_NAMES__ = Object.keys(EXTENSION_LOADERS)
203
+ export const __loadEditorModulesForTest = loadEditorModules
203
204
 
204
205
  async function loadEditorModules(enabledExtensions = []) {
205
206
  const enabledSet = new Set(enabledExtensions)
@@ -291,11 +291,11 @@ function serializeInlineContent(node) {
291
291
  const iterate = (items) => {
292
292
  if (Array.isArray(items)) {
293
293
  for (const item of items) {
294
- result += serializeTextWithMarks(item)
294
+ result += serializeInlineNode(item)
295
295
  }
296
296
  } else if (typeof items.forEach === "function") {
297
297
  items.forEach(item => {
298
- result += serializeTextWithMarks(item)
298
+ result += serializeInlineNode(item)
299
299
  })
300
300
  }
301
301
  }
@@ -304,6 +304,16 @@ function serializeInlineContent(node) {
304
304
  return result
305
305
  }
306
306
 
307
+ function serializeInlineNode(node) {
308
+ if (!node) return ""
309
+
310
+ const type = node.type?.name || node.type
311
+ if (type === "text") return serializeTextWithMarks(node)
312
+ if (type === "hardBreak") return "\n"
313
+
314
+ return serializeNode(node).trim()
315
+ }
316
+
307
317
  /**
308
318
  * Serialize text node with marks
309
319
  */
@@ -316,8 +326,24 @@ function serializeTextWithMarks(node) {
316
326
  return text
317
327
  }
318
328
 
319
- // Apply marks in order (innermost first)
320
- for (const mark of node.marks) {
329
+ const markName = mark => mark.type?.name || mark.type
330
+ const hasBold = node.marks.some(mark => ["bold", "strong"].includes(markName(mark)))
331
+ const hasItalic = node.marks.some(mark => ["italic", "em"].includes(markName(mark)))
332
+
333
+ if (hasBold && hasItalic) {
334
+ text = `***${text}***`
335
+ } else if (hasBold) {
336
+ text = MARK_SERIALIZERS.bold(text)
337
+ } else if (hasItalic) {
338
+ text = MARK_SERIALIZERS.italic(text)
339
+ }
340
+
341
+ const remainingMarks = node.marks.filter(mark => {
342
+ const name = markName(mark)
343
+ return !["bold", "strong", "italic", "em"].includes(name)
344
+ })
345
+
346
+ for (const mark of remainingMarks) {
321
347
  const serializer = MARK_SERIALIZERS[mark.type?.name || mark.type]
322
348
  if (serializer) {
323
349
  text = serializer(text, mark)
@@ -425,7 +451,8 @@ function serializeBlockquote(node, options) {
425
451
  */
426
452
  function serializeCodeBlock(node) {
427
453
  const language = node.attrs?.language || ""
428
- return "```" + language + "\n" + node.textContent + "\n```"
454
+ const content = (node.textContent || "").replace(/\n$/, "")
455
+ return "```" + language + "\n" + content + "\n```"
429
456
  }
430
457
 
431
458
  /**
@@ -470,7 +497,7 @@ function serializeTable(node, options) {
470
497
  const rowChildren = row.content?.content || row.content || []
471
498
 
472
499
  iterate(rowChildren, (cell, cellIndex) => {
473
- const content = serializeInlineContent(cell).trim() || " "
500
+ const content = serializeTableCell(cell, options)
474
501
  cells.push(content)
475
502
 
476
503
  // Track alignment from first row cells
@@ -500,6 +527,15 @@ function serializeTable(node, options) {
500
527
  return rows.join("\n") + "\n"
501
528
  }
502
529
 
530
+ function serializeTableCell(cell, options) {
531
+ const content = serializeChildren(cell, options)
532
+ .trim()
533
+ .replace(/\n+/g, "<br>")
534
+ .replace(/\s*\|\s*/g, "\\|")
535
+
536
+ return content || " "
537
+ }
538
+
503
539
  /**
504
540
  * Serialize callout to GFM-style alert
505
541
  */