1
0
mirror of https://codeberg.org/cage/tinmop/ synced 2025-03-02 09:57:48 +01:00

- [fediverse] stripped footnote reference in body of the quoted text, when replying.

This commit is contained in:
cage 2024-11-02 15:40:14 +01:00
parent 39e567bd4e
commit e323c81a1c
3 changed files with 33 additions and 8 deletions

View File

@ -116,6 +116,24 @@
(defparameter *ordered-list-item-number* 0)
(defun append-footnote-reference (text reference-number)
(strcat text
(format nil
"~a~a"
#\ZERO_WIDTH_SPACE
(number->superscripts reference-number))))
(defun footnote-reference-re (&key (enforce-end-string t))
(format nil
"~a[~a]+~@[$~]"
#\ZERO_WIDTH_SPACE
+digits-superscripts+
enforce-end-string))
(let ((scanner (cl-ppcre:create-scanner (footnote-reference-re))))
(defun strip-footnote-reference (word)
(cl-ppcre:regex-replace scanner word "")))
(defun html->text (html &key
(add-link-footnotes t) (body-footnotes-separator "")
(quote-prefix "> ") (list-item-prefix "* "))
@ -160,10 +178,8 @@ Some convenience functions are provided to works with these structures.
link-count))
(descend-children node)
(when add-link-footnotes
(format body-stream
"~a~a "
#\ZERO_WIDTH_SPACE
(number->superscripts link-count)))))
(write-string (append-footnote-reference "" link-count)
body-stream))))
((tag= +tag-break+ node)
(let ((*block-tag* nil))
(format body-stream "~%")

View File

@ -37,8 +37,10 @@
first-mention)))))
(defun line-find-all-usernames (message-line)
(let ((words (split-words message-line)))
(mapcar (lambda (a) (subseq a (length +mention-prefix+))) ; remove the @
(let ((words (split-words message-line))
(mention-prefix-length (length +mention-prefix+)))
(mapcar (lambda (a)
(html-utils:strip-footnote-reference (subseq a mention-prefix-length))) ; remove the @
(remove-if-not (lambda (word)
(cl-ppcre:scan (strcat "^" +mention-prefix+) word))
words))))
@ -59,11 +61,14 @@
usernames)))
(defun local-mention->acct (text-line usernames-table)
"Substitute in `text-line' '@user' with '@user@server', if '@user'
"Substitute in `text-line' '@user' with '@user@server', if '@user'
is found as key in the alist `usernames-table'"
(let ((results text-line))
(loop for (local-mention . actual-mention) in usernames-table do
(let ((local-mention-re (strcat "(\\s|^)" local-mention)))
(let ((local-mention-re (strcat "(\\s|^)"
local-mention
(html-utils:footnote-reference-re :enforce-end-string nil))))
(misc:dbg "table ~a" local-mention-re)
(setf results (regex-replace-all local-mention-re
results
(strcat " " actual-mention)))))

View File

@ -453,6 +453,7 @@
(:export
:+float-regexp+
:+integer-regexp+
:+digits-superscripts+
:*blanks*
:uchar-length
:starts-with-prefix-p
@ -526,6 +527,9 @@
:find-tag
:position-tag
:node->link
:append-footnote-reference
:strip-footnote-reference
:footnote-reference-re
:html->text))
(defpackage :resources-utils