dsh-lifecard 0.2.2 → 0.4.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.
package/lib/core.js CHANGED
@@ -598,10 +598,27 @@ export function splitSections(body) {
598
598
  return out.map((s) => ({ title: s.title, body: s.body.join('\n').replace(/^\n+|\n+$/g, '') }))
599
599
  }
600
600
 
601
- /** 取某小节正文;没有就返回空串。 */
601
+ /**
602
+ * 取某小节正文;没有就返回空串。
603
+ *
604
+ * **同名小节要全取,不能只取第一份。**
605
+ *
606
+ * 人写东西不是围着我们的格式转的:早上写一段「今天最值得讲的一件事」,
607
+ * 晚上想起一句,很自然会再起一个同名标题接着写。以前这里用 `find` 只取
608
+ * 第一份,第二份在整份重写时被静默删掉,人只会觉得「我写的怎么没了」。
609
+ * 标题尾随多个空格(`## 下一步 `)会被规整成同名——同样得并起来。
610
+ *
611
+ * 用空行连接:正文小节是段落,空行是段落间的自然分隔;一行一条的小节
612
+ * 由 `parseList` 按行切,空行本来就会被跳过。
613
+ */
602
614
  export function sectionBody(sections, title) {
603
- const found = sections.find((s) => s.title === title)
604
- return found === undefined ? '' : found.body
615
+ const list = Array.isArray(sections) ? sections : []
616
+ const bodies = list
617
+ .filter((s) => s.title === title)
618
+ .map((s) => String(s.body ?? '').trim())
619
+ .filter((body) => body !== '')
620
+ if (bodies.length === 0) return ''
621
+ return bodies.join('\n\n')
605
622
  }
606
623
 
607
624
  /**
@@ -1035,6 +1052,9 @@ export function safeId(raw) {
1035
1052
  const s = String(raw ?? '').trim()
1036
1053
  if (s === '') return 'unnamed'
1037
1054
  return s
1055
+ // 控制字符(含 NUL)一律抹掉:它们会原样跟着路径走,Node 那一侧只会
1056
+ // ENOENT/EINVAL,排查起来像见鬼。
1057
+ .replace(/[\u0000-\u001f\u007f]/g, '')
1038
1058
  .replace(/[\\/:*?"<>|#%\s]+/g, '-')
1039
1059
  .replace(/^-+|-+$/g, '')
1040
1060
  .replace(/-{2,}/g, '-')