@@ -246,41 +246,52 @@ Returns (PREFIX . BARE), where PREFIX is everything before the first `|'."
246246 (md-ts--set-hide-markup t )))
247247 pi-coding-agent--visible-string-buffer)
248248
249+ (defconst pi-coding-agent--markdown-inline-chars-re " [*_`~\\ []"
250+ " Regexp matching characters that can start markdown inline syntax.
251+ Cells without any of these characters have identical visible rendering
252+ and can skip the fontification buffer entirely." )
253+
249254(defun pi-coding-agent--markdown-visible-string (markdown )
250255 " Return the visible chat-buffer rendering of MARKDOWN.
251256This hides markdown delimiters the same way `pi-coding-agent-chat-mode'
252257does, so wrapped table overlays match ordinary visible-copy semantics.
253- Uses a persistent fontification buffer to avoid per-call mode setup."
254- (with-current-buffer (pi-coding-agent--visible-string-buffer)
255- (let ((inhibit-read-only t ))
256- (erase-buffer )
257- (insert markdown))
258- (font-lock-ensure )
259- (pi-coding-agent--visible-text (point-min ) (point-max ))))
258+ Uses a persistent fontification buffer to avoid per-call mode setup.
259+ Cells with no inline syntax characters are returned as-is."
260+ (if (not (string-match-p pi-coding-agent--markdown-inline-chars-re markdown))
261+ markdown
262+ (with-current-buffer (pi-coding-agent--visible-string-buffer)
263+ (let ((inhibit-read-only t ))
264+ (erase-buffer )
265+ (insert markdown))
266+ (font-lock-ensure )
267+ (pi-coding-agent--visible-text (point-min ) (point-max )))))
260268
261269; ;;; Cell Rendering
262270
263271(defun pi-coding-agent--render-table-row-lines (cells col-widths aligns )
264272 " Render table CELLS into display lines using COL-WIDTHS and ALIGNS.
265- Builds each line with a flat string accumulator to reduce intermediate
266- consing: padding and cell fragments are pushed individually, then
267- joined with a single `apply concat'."
273+ When `pi-coding-agent-prettify-tables' is non-nil, emits Unicode
274+ box-drawing verticals instead of markdown pipes."
268275 (let* ((num-cols (length col-widths))
269276 (padded (append cells (make-list (max 0 (- num-cols (length cells))) " " )))
270277 (wrapped-cells
271278 (cl-mapcar (lambda (cell column-width )
272279 (markdown-table-wrap-cell (or cell " " ) column-width))
273280 padded col-widths))
274- (max-height (apply #'max (mapcar #'length wrapped-cells))))
281+ (max-height (apply #'max (mapcar #'length wrapped-cells)))
282+ (pretty pi-coding-agent-prettify-tables)
283+ (delim-open (if pretty " │ " " | " ))
284+ (delim-mid (if pretty " │ " " | " ))
285+ (delim-close (if pretty " │" " |" )))
275286 (cl-loop for line-index below max-height
276287 collect
277- (let ((acc (list " | " )))
288+ (let ((acc (list delim-open )))
278289 (cl-loop for cell-lines in wrapped-cells
279290 for column-width in col-widths
280291 for align in aligns
281292 for first = t then nil
282293 do
283- (unless first (push " | " acc))
294+ (unless first (push delim-mid acc))
284295 (let* ((cell (or (nth line-index cell-lines) " " ))
285296 (empty (string-empty-p cell))
286297 (pad (if empty
@@ -301,31 +312,37 @@ joined with a single `apply concat'."
301312 (t
302313 (push cell acc)
303314 (push (make-string pad ?\s ) acc)))))
304- (push " | " acc)
315+ (push delim-close acc)
305316 (apply #'concat (nreverse acc))))))
306317
307318(defun pi-coding-agent--render-table-separator-line (col-widths aligns )
308- " Render the markdown separator line for COL-WIDTHS and ALIGNS."
309- (let ((parts
310- (cl-mapcar
311- (lambda (column-width align )
312- (let ((dashes (make-string (max 1 column-width) ?- )))
313- (pcase align
314- ('left
315- (if (>= column-width 2 )
316- (concat " :" (substring dashes 1 ))
317- " :" ))
318- ('right
319- (if (>= column-width 2 )
320- (concat (substring dashes 1 ) " :" )
321- " :" ))
322- ('center
323- (if (>= column-width 3 )
324- (concat " :" (substring dashes 2 ) " :" )
325- (if (>= column-width 2 ) " ::" " :" )))
326- (_ dashes))))
327- col-widths aligns)))
328- (concat " | " (mapconcat #'identity parts " | " ) " |" )))
319+ " Render the separator line for COL-WIDTHS and ALIGNS.
320+ When `pi-coding-agent-prettify-tables' is non-nil, emits a box-drawing
321+ rule (├─┼─┤) directly; otherwise emits standard markdown syntax."
322+ (if pi-coding-agent-prettify-tables
323+ (concat " ├─" (mapconcat (lambda (w ) (make-string (max 1 w) ?─ ))
324+ col-widths " ─┼─" )
325+ " ─┤" )
326+ (let ((parts
327+ (cl-mapcar
328+ (lambda (column-width align )
329+ (let ((dashes (make-string (max 1 column-width) ?- )))
330+ (pcase align
331+ ('left
332+ (if (>= column-width 2 )
333+ (concat " :" (substring dashes 1 ))
334+ " :" ))
335+ ('right
336+ (if (>= column-width 2 )
337+ (concat (substring dashes 1 ) " :" )
338+ " :" ))
339+ ('center
340+ (if (>= column-width 3 )
341+ (concat " :" (substring dashes 2 ) " :" )
342+ (if (>= column-width 2 ) " ::" " :" )))
343+ (_ dashes))))
344+ col-widths aligns)))
345+ (concat " | " (mapconcat #'identity parts " | " ) " |" ))))
329346
330347(defun pi-coding-agent--table-alignments (separator-line )
331348 " Return column alignment symbols parsed from SEPARATOR-LINE."
@@ -560,6 +577,7 @@ blank-line spacing between a table and following text is not collapsed."
560577 (ov (make-overlay line-beg line-end nil nil nil )))
561578 (overlay-put ov 'display
562579 (pi-coding-agent--neutralize-fonts display-str))
580+ (overlay-put ov 'face 'default )
563581 (overlay-put ov 'pi-coding-agent-table-display t )
564582 (overlay-put ov 'evaporate t ))
565583 (forward-line 1 ))))
0 commit comments