From 0f9e308745b77ca589e5b25f415121058b9f08ee Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 10 May 2026 15:25:27 -0500 Subject: refactor(cj-org-text): rename to cj-org-text-lib for naming consistency Same naming-convention fix as the cj-cache rename. Org-safe text sanitizers extracted in Phase 3 went into modules/cj-org-text.el, should have followed the established `-lib' suffix convention. Rename modules/cj-org-text.el -> modules/cj-org-text-lib.el; update provide form, file header, and the two (require 'cj-org-text) call sites in calendar-sync and test-cj-org-text-sanitize. No behavior change. --- modules/calendar-sync.el | 2 +- modules/cj-org-text-lib.el | 58 ++++++++++++++++++++++++++++++++++++++ modules/cj-org-text.el | 58 -------------------------------------- tests/test-cj-org-text-sanitize.el | 2 +- 4 files changed, 60 insertions(+), 60 deletions(-) create mode 100644 modules/cj-org-text-lib.el delete mode 100644 modules/cj-org-text.el diff --git a/modules/calendar-sync.el b/modules/calendar-sync.el index 890dd9df..74b2e5c6 100644 --- a/modules/calendar-sync.el +++ b/modules/calendar-sync.el @@ -71,7 +71,7 @@ (require 'cl-lib) (require 'subr-x) -(require 'cj-org-text) +(require 'cj-org-text-lib) (defun calendar-sync--log-silently (format-string &rest args) "Log FORMAT-STRING with ARGS without requiring the full config." diff --git a/modules/cj-org-text-lib.el b/modules/cj-org-text-lib.el new file mode 100644 index 00000000..45b9ec2e --- /dev/null +++ b/modules/cj-org-text-lib.el @@ -0,0 +1,58 @@ +;;; cj-org-text-lib.el --- Pure helpers for sanitizing external text into Org -*- lexical-binding: t; -*- + +;; Author: Craig Jennings + +;;; Commentary: + +;; Pure string helpers for safely composing Org-mode content from +;; external text (calendar event bodies, web-clipped HTML, mail +;; subject lines, AI conversation transcripts, etc.). +;; +;; The shared concern is that text from outside sources can contain +;; characters that disturb Org structure if pasted verbatim: +;; +;; - leading `*' creates an unintended heading, +;; - newlines inside a property value spawn extra drawer lines, +;; - newlines inside a heading split it into two outline entries. +;; +;; These helpers neutralize each pattern with predictable, testable +;; replacements. They are pure (string in, string out, nil-safe) and +;; have no Org-mode dependency, so they remain useful in batch and in +;; tests without loading Org. + +;;; Code: + +(defun cj/org-sanitize-body-text (text) + "Sanitize TEXT for safe inclusion as Org body content. +Replaces leading asterisks with dashes so external lines aren't +parsed as Org headings. Handles multiple levels (`**' becomes `--'). +Returns nil for nil input." + (when text + (replace-regexp-in-string + "^\\(\\*+\\) " + (lambda (match) + (concat (make-string (length (match-string 1 match)) ?-) " ")) + text))) + +(defun cj/org-sanitize-property-value (text) + "Sanitize TEXT for safe inclusion as a single Org property value. +Collapses whitespace and newlines into single spaces and trims, so the +result fits on one line of an Org property drawer. Returns nil for +nil input." + (when text + (string-trim + (replace-regexp-in-string + "[[:space:]\n\r]+" + " " + text)))) + +(defun cj/org-sanitize-heading (text) + "Sanitize TEXT for safe inclusion as a single Org heading title. +Composes `cj/org-sanitize-body-text' (neutralizes leading stars) and +`cj/org-sanitize-property-value' (flattens to a single line). Returns +nil for nil input." + (cj/org-sanitize-property-value + (cj/org-sanitize-body-text text))) + +(provide 'cj-org-text-lib) +;;; cj-org-text-lib.el ends here diff --git a/modules/cj-org-text.el b/modules/cj-org-text.el deleted file mode 100644 index 69224573..00000000 --- a/modules/cj-org-text.el +++ /dev/null @@ -1,58 +0,0 @@ -;;; cj-org-text.el --- Pure helpers for sanitizing external text into Org -*- lexical-binding: t; -*- - -;; Author: Craig Jennings - -;;; Commentary: - -;; Pure string helpers for safely composing Org-mode content from -;; external text (calendar event bodies, web-clipped HTML, mail -;; subject lines, AI conversation transcripts, etc.). -;; -;; The shared concern is that text from outside sources can contain -;; characters that disturb Org structure if pasted verbatim: -;; -;; - leading `*' creates an unintended heading, -;; - newlines inside a property value spawn extra drawer lines, -;; - newlines inside a heading split it into two outline entries. -;; -;; These helpers neutralize each pattern with predictable, testable -;; replacements. They are pure (string in, string out, nil-safe) and -;; have no Org-mode dependency, so they remain useful in batch and in -;; tests without loading Org. - -;;; Code: - -(defun cj/org-sanitize-body-text (text) - "Sanitize TEXT for safe inclusion as Org body content. -Replaces leading asterisks with dashes so external lines aren't -parsed as Org headings. Handles multiple levels (`**' becomes `--'). -Returns nil for nil input." - (when text - (replace-regexp-in-string - "^\\(\\*+\\) " - (lambda (match) - (concat (make-string (length (match-string 1 match)) ?-) " ")) - text))) - -(defun cj/org-sanitize-property-value (text) - "Sanitize TEXT for safe inclusion as a single Org property value. -Collapses whitespace and newlines into single spaces and trims, so the -result fits on one line of an Org property drawer. Returns nil for -nil input." - (when text - (string-trim - (replace-regexp-in-string - "[[:space:]\n\r]+" - " " - text)))) - -(defun cj/org-sanitize-heading (text) - "Sanitize TEXT for safe inclusion as a single Org heading title. -Composes `cj/org-sanitize-body-text' (neutralizes leading stars) and -`cj/org-sanitize-property-value' (flattens to a single line). Returns -nil for nil input." - (cj/org-sanitize-property-value - (cj/org-sanitize-body-text text))) - -(provide 'cj-org-text) -;;; cj-org-text.el ends here diff --git a/tests/test-cj-org-text-sanitize.el b/tests/test-cj-org-text-sanitize.el index cdad9af5..4a4ef2c3 100644 --- a/tests/test-cj-org-text-sanitize.el +++ b/tests/test-cj-org-text-sanitize.el @@ -12,7 +12,7 @@ (require 'ert) (add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) -(require 'cj-org-text) +(require 'cj-org-text-lib) ;;; cj/org-sanitize-body-text -- Normal cases -- cgit v1.2.3