v1.0.0: add char-width and search-highlight to cl-tty library
char-width → cl-tty.box (text.lisp): terminal column width for Unicode characters including CJK, emoji, combining marks, and tab. search-highlight → cl-tty.markdown: wraps query matches in **bold** markers for search result emphasis. Pure function, zero dependencies.
This commit is contained in:
@@ -18,6 +18,7 @@ and diff rendering. Self-contained in ~cl-tty.markdown~ package.
|
||||
#:make-md-node #:md-node-p #:md-node-text
|
||||
#:parse-blocks #:parse-inline
|
||||
#:highlight-code
|
||||
#:search-highlight
|
||||
#:classify-diff-line #:render-md #:render-md-node
|
||||
#:render-markdown #:render-inline
|
||||
#:apply-style #:apply-styles))
|
||||
@@ -1062,6 +1063,30 @@ Returns an empty string for ~nil~ input.
|
||||
do (unless first (terpri s)) (princ part s)))))
|
||||
#+END_SRC
|
||||
|
||||
*** search-highlight
|
||||
|
||||
~search-highlight~ wraps occurrences of a query string in a text with
|
||||
**bold** markers for emphasis display. Case-insensitive matching.
|
||||
Returns the original text if query is nil or empty.
|
||||
|
||||
#+BEGIN_SRC lisp :tangle ~/.local/share/cl-tty/src/components/markdown.lisp
|
||||
(defun search-highlight (content query)
|
||||
"Wrap occurrences of QUERY in CONTENT with **bold** markers."
|
||||
(let ((lower-content (string-downcase content))
|
||||
(lower-query (string-downcase query))
|
||||
(result "") (pos 0))
|
||||
(when (and query (> (length query) 0))
|
||||
(loop
|
||||
(let ((found (search lower-query lower-content :start2 pos)))
|
||||
(unless found (return))
|
||||
(setf result (concatenate 'string result
|
||||
(subseq content pos found)
|
||||
"**" (subseq content found (+ found (length query))) "**"))
|
||||
(setf pos (+ found (length query)))))
|
||||
(setf result (concatenate 'string result (subseq content pos)))
|
||||
(if (string= result "") content result))))
|
||||
#+END_SRC
|
||||
|
||||
* Tests
|
||||
|
||||
The test suite covers parser edge cases, heading/paragraph parsing, inline
|
||||
|
||||
Reference in New Issue
Block a user