Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions TeXmacs/plugins/account/data/md.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
\begin{document}
很抱歉,目前Markdown功能仅为会员用户提供。\
详情请见 \url{https://liiistem.cn/} 注册即送14天会员!\
已为您按照纯文本格式粘贴内容。
\end{document}
2 changes: 1 addition & 1 deletion TeXmacs/plugins/account/data/ocr.tex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
\begin{document}
很抱歉,目前OCR功能仅为会员用户提供。\
详情请见 \url{https://liiistem.cn/} 注册即送14天会员!
详情请见 \url{https://liiistem.cn/pricing.html} 注册即送14天会员!
\end{document}
3 changes: 3 additions & 0 deletions TeXmacs/plugins/lang/dic/en_US/zh_CN.scm
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@
("framed block" "边框块")
("framed theorems" "定理加框")
("french" "法语")
("From: " "来自:")
("from center" "从中心")
("front matter" "前置部分")
("full manuals" "完全手册")
Expand Down Expand Up @@ -2314,6 +2315,7 @@
("unfold" "打开")
("unit length" "单位长度")
("unit" "单位")
("Unknown" "未知")
("up" "")
("up" "上")
("update from web" "")
Expand Down Expand Up @@ -2463,6 +2465,7 @@
("yellow" "黄色")
("yes" "是")
("you can also obtain" "")
("ENTER to confirm, ESC to cancel" "ENTER键确认,ESC键取消")
("you do not have write access for" "没有写权限")
("your document is back in its original state" "")
("your first interface" "")
Expand Down
8 changes: 8 additions & 0 deletions TeXmacs/progs/generic/generic-edit.scm
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@
(tm-define (kbd-cancel)
(clipboard-clear "primary"))

(tm-define (markdown-paste)
(clipboard-paste-import "verbatim" "primary")
(kbd-return)
(let* ((latex-code (get-file-string (unix->url "$TEXMACS_PATH/plugins/account/data/md.tex")))
(parsed-latex (parse-latex latex-code))
(texmacs-latex (latex->texmacs parsed-latex)))
(insert texmacs-latex)))

(tm-define (ocr-paste)
(with data
(parse-texmacs-snippet (tree->string (tree-ref (clipboard-get "primary") 1)))
Expand Down
144 changes: 91 additions & 53 deletions TeXmacs/progs/generic/paste-widget.scm
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,12 @@
(texmacs-module (generic paste-widget)
(:use (generic generic-edit)
(utils edit selections)
(liii ocr)))

(define plain-format-list (list "LaTeX" "HTML" (translate "Plain text") "Markdown"))
(define math-format-list (list "LaTeX" "MathML"))
(define program-format-list (list (translate "Code")))
(define graphics-format-list (list "graphics"))
(define image-list (list "OCR" (translate "Image and OCR") (translate "Only image")))

(liii ocr)
(kernel texmacs tm-convert)))
(import (only (liii list) delete))

;; Helper functions (stateless, can remain at module level)
(define (get-name-list)
(cond ((in-math?) math-format-list)
((in-prog?) program-format-list)
((in-graphics?) graphics-format-list)
((is-clipboard-image?) image-list)
(else plain-format-list)))


(define (get-mode)
(cond ((in-math?) "Math mode")
Expand All @@ -48,6 +38,18 @@
((== name "Graphics") "graphics")
((== name (translate "Code")) "code")))

(define (convert-symbol-to-format-string symbol)
(cond ((== symbol "md") "Markdown")
((== symbol "html") "HTML")
((== symbol "latex") "LaTeX")
((== symbol "mathml") "MathML")
((== symbol "ocr") "OCR")
((== symbol "graphics") "Graphics")
((== symbol "verbatim") (translate "Plain text"))
((== symbol "iao") (translate "Image and OCR"))
((== symbol "oi") (translate "Only image"))
((== symbol "code") (translate "Code"))))

(define (get-tips fm)
(cond ((== fm "md") "Insert clipboard content as 'Markdown'")
((== fm "html") "Insert clipboard content as 'HTML'")
Expand All @@ -61,11 +63,28 @@
((== fm "graphics") "Insert clipboard content as 'graphics'")
(else "Please select...")))

;; (convert-format-string-to-symbol (car (get-name-list)))
(define (init-choice)
(with data (parse-texmacs-snippet (tree->string (tree-ref (clipboard-get "primary") 1)))
(cond ((is-clipboard-image?) (convert-format-string-to-symbol (car image-list)))
(else (convert-format-string-to-symbol (car (get-name-list)))))))
(define (get-clipboard-format)
(let* ((data (clipboard-format "primary"))
(fm (tree->string (tree-ref data 3))))
(if (!= fm "")
(convert-symbol-to-format-string fm)
(convert-symbol-to-format-string "verbatim"))))

(define (init-choices l)
(let* ((data (clipboard-format "primary"))
(fm (tree->string (tree-ref data 3))))
(if (!= fm "")
(if (== fm "verbatim")
l
(let* ((name (convert-symbol-to-format-string fm)))
(cons name (delete name l))))
l)))

(define (shortcut fm)
(cond ((and (in-math?) (== fm "latex")) "Ctrl+Shift+v")
((== fm "verbatim") "Ctrl+Shift+v")
((is-clipboard-image?) "Ctrl+Shift+v")
(else "none")))

(tm-define (is-clipboard-image?)
(with data (parse-texmacs-snippet (tree->string (tree-ref (clipboard-get "primary") 1)))
Expand All @@ -75,40 +94,59 @@

(tm-widget (clipboard-paste-from-widget cmd)
(let* ((selected-format "verbatim")
(tips "Please select..."))
(tips1 "Please select...")
(tips2 "")
(tips3 (string-append (translate "shortcut") ":" (translate "none")))
(plain-format-list (list "Markdown" "LaTeX" "HTML" (translate "Plain text")))
(math-format-list (list "LaTeX" "MathML"))
(program-format-list (list (translate "Code")))
(graphics-format-list (list "graphics"))
(image-list (list "OCR" (translate "Image and OCR") (translate "Only image")))
(name-list (cond ((in-math?) math-format-list)
((in-prog?) program-format-list)
((in-graphics?) graphics-format-list)
((is-clipboard-image?) image-list)
(else plain-format-list)))
(l (init-choices name-list)))

;; Initialize selection on first display
(invisible (set! selected-format (init-choice)))
(invisible (set! tips (translate (get-tips selected-format))))

(padded
(vertical
(horizontal
(vertical
(refreshable "current-mode"
(bold (text "Mode"))
(text (get-mode)))
(glue #f #t 0 0))
///
(refreshable "format-selection"
(resize "150px" "150px"
(bold (text "As: "))
===
(scrollable
(choice (begin
(set! selected-format (convert-format-string-to-symbol (translate answer)))
(set! tips (translate (get-tips selected-format)))
(refresh-now "format-explanation"))
(get-name-list)
(car (get-name-list)))))))
===
(refreshable "format-explanation"
(bold (text "Tips"))
(texmacs-output
`(with "bg-color" "white"
"font-base-size" "14"
(document ,tips))
'(style "generic")))))
(invisible (set! selected-format (car l)))
(invisible (set! tips1 (translate (get-tips (convert-format-string-to-symbol selected-format)))))
(invisible (set! tips2 (translate "ENTER to confirm, ESC to cancel")))
(resize "320px" "270px"
(padded
(vertical
(horizontal
(vertical
(bold (text "From: "))
(text (get-clipboard-format))
(glue #f #t 0 0)
(bold (text "Mode"))
(text (get-mode))
(glue #f #t 0 0))
///
(refreshable "format-selection"
(resize "200px" "190px"
(bold (text "As: "))
===
(scrollable
(choice (begin
(set! selected-format (convert-format-string-to-symbol (translate answer)))
(set! tips1 (translate (get-tips selected-format)))
(set! tips3 (string-append (translate "shortcut") ":" (shortcut selected-format)))
(refresh-now "format-explanation")
(refresh-now "paste-shortcut"))
l
(car l))))))
===
(refreshable "format-explanation"
(bold (text "Tips"))
(resize "320px" "90px"
(texmacs-output
`(with "bg-color" "white"
"font-base-size" "18"
(document ,tips1 ,tips3 ,tips2))
'(style "generic")))))))
(bottom-buttons
>> ("ok" (cmd selected-format)) // ("cancel" (cmd #f)))))

Expand All @@ -117,12 +155,12 @@
(dialogue-window clipboard-paste-from-widget
(lambda (fm)
(when fm
(cond ((== fm "md") (open-url "https://liiistem.cn/"))
(cond ((== fm "md") (markdown-paste))
((== fm "ocr") (ocr-paste))
((== fm "iao") (ocr-and-image-paste))
((== fm "oi") (kbd-paste))
((== fm "mathml") (clipboard-paste-import "html" "primary"))
(else (clipboard-paste-import format "primary")))))
(else (clipboard-paste-import fm "primary")))))
"Paste Special"))

(tm-define (interactive-paste-special)
Expand Down
5 changes: 4 additions & 1 deletion devel/202_84.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
+ 仅LaTeX选项会插入提示信息
+ 图片与LaTeX选项会插入两行,第一行为图片,第二行为提示信息
+ 仅图片会正常插入图片
+ 复制HTML、LaTeX、纯文本格式,查看选择性粘贴窗口的状态,左上角是否正确显示来源格式

注:社区版不支持markdown与OCR功能,故虽有选项但无法使用。

## 2025/12/17 按Enter可以确认,按ESC可以取消
## 2025/12/27 智能检测剪贴板内容格式

## 2025/12/27 按Enter可以确认,按ESC可以取消

## 2025/12/27

Expand Down
9 changes: 9 additions & 0 deletions src/Edit/Replace/edit_select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "Interface/edit_interface.hpp"
#include "convert.hpp"
#include "cork.hpp"
#include "observer.hpp"
#include "packrat.hpp"
#include "preferences.hpp"
#include "tree_modify.hpp"
Expand Down Expand Up @@ -490,6 +491,14 @@ edit_select_rep::selection_get (path& p1, path& p2) {
*/
}

tree
edit_select_rep::selection_format (string key) {
tree t;
string s;
(void) ::get_selection (key, t, s, "default");
return t;
}

path
edit_select_rep::selection_get_start () {
return start (cur_sel);
Expand Down
1 change: 1 addition & 0 deletions src/Edit/Replace/edit_select.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class edit_select_rep : virtual public editor_rep {
selection compute_selection (range_set sel);
void selection_get (selection& sel);
void selection_get (path& start, path& end);
tree selection_format (string key);
path selection_get_start ();
path selection_get_end ();
path selection_var_get_start ();
Expand Down
1 change: 1 addition & 0 deletions src/Edit/editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ class editor_rep : public simple_widget_rep {
virtual selection compute_selection (range_set sel) = 0;
virtual void selection_get (selection& sel) = 0;
virtual void selection_get (path& start, path& end) = 0;
virtual tree selection_format (string key) = 0;
virtual path selection_get_start () = 0;
virtual path selection_get_end () = 0;
virtual path selection_var_get_start () = 0;
Expand Down
12 changes: 11 additions & 1 deletion src/Plugins/Qt/qt_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ qt_gui_rep::get_selection (string key, tree& t, string& s, string format) {
string input_format;
string image_w_string, image_h_string;
string clipboard_image_suffix= "png";
string detected_format;

s= "";
t= "none";
Expand Down Expand Up @@ -318,6 +319,7 @@ qt_gui_rep::get_selection (string key, tree& t, string& s, string format) {
if (N (image_data) > 0) {
input_format= "picture";
buf = QByteArray (image_data.begin (), N (image_data));
input_format= "picture";
clipboard_image_suffix= target_suffix;
}
#else
Expand All @@ -343,14 +345,22 @@ qt_gui_rep::get_selection (string key, tree& t, string& s, string format) {
else if (md->hasHtml ()) {
buf = md->html ().toUtf8 ();
input_format= "html-snippet";
string raw_html (buf.constData (), buf.size ());
detected_format= as_string (call ("format-determine", raw_html, "html"));
}
else if (md->hasFormat ("text/plain;charset=utf8")) {
buf = md->data ("text/plain;charset=utf8");
input_format= "verbatim-snippet";
string raw_text (buf.constData (), buf.size ());
detected_format=
as_string (call ("format-determine", raw_text, "verbatim"));
}
else {
buf = md->text ().toUtf8 ();
input_format= "verbatim-snippet";
string raw_text (buf.constData (), buf.size ());
detected_format=
as_string (call ("format-determine", raw_text, "verbatim"));
}
}
else if (format == "verbatim" &&
Expand Down Expand Up @@ -379,7 +389,7 @@ qt_gui_rep::get_selection (string key, tree& t, string& s, string format) {
<< image_h_string << "" << "";
s= as_string (call ("convert", t, "texmacs-tree", "texmacs-snippet"));
}
t= tuple ("extern", s);
t= tuple ("extern", s, input_format, detected_format);
return true;
}

Expand Down
8 changes: 8 additions & 0 deletions src/Scheme/Glue/glue_editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,14 @@ function main()
"string"
}
},
{
scm_name = "clipboard-format",
cpp_name = "selection_format",
ret_type = "tree",
arg_list = {
"string"
}
},
{
scm_name = "cpp-clipboard-copy",
cpp_name = "selection_copy",
Expand Down