From e591dfd5903a426bad68aa35959a73387b36bf9b Mon Sep 17 00:00:00 2001 From: Saq Imtiaz Date: Wed, 2 Oct 2024 14:15:53 +0200 Subject: [PATCH] Update the editor file import UI to support markdown tiddlers (#8486) * chore: update editor file import to use procedures and substitute operator * feat: refactor editor file-import UI to reuse filter from $:/config/Editor/EnableImportFilter * feat: support for markdown in editor file import UI * feat: improve markdown type detection and enable markdown image imports by default * fix: uri encode tiddler titles for markdown * escape characters instead of URI encoding * fix: tweak regexp to simplify code and document escaping rules --- core/ui/EditorToolbar/file-import.tid | 34 ++++++++++++------- core/wiki/config/EditorEnableImportFilter.tid | 2 +- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/core/ui/EditorToolbar/file-import.tid b/core/ui/EditorToolbar/file-import.tid index 20cff547d..0fd5e08a5 100644 --- a/core/ui/EditorToolbar/file-import.tid +++ b/core/ui/EditorToolbar/file-import.tid @@ -1,20 +1,30 @@ title: $:/core/ui/EditorToolbar/file-import tags: $:/tags/EditorTools -condition: [!has[type]] [type[text/vnd.tiddlywiki]] +condition: [filter{$:/config/Editor/EnableImportFilter}] -\define lingo-base() $:/language/Import/ +\procedure lingo-base() $:/language/Import/ -\define closePopupActions() +\procedure closePopupActions() <$action-deletetiddler $filter="[title] [title]"/> -\end +\end closePopupActions -\define replacement-text-image() [img[$title$]] +\procedure tw5-ImageTemplate() [img[$(currentTiddler)$]] +\procedure tw5-FileTemplate() [[$(currentTiddler)$]] -\define replacement-text-file() [[$title$]] + +\function escape.title() [search-replace:g:regexp[\(|\)|<|>|\\],[\$&]] +\procedure markdown-ImageTemplate() ![](<#${ [escape.title[]] }$>) +\procedure markdown-FileTemplate() [](<#${ [escape.title[]] }$>) -\define postImportActions() +\function is.markdown.tiddler() [all[]type[text/x-markdown]] [all[]type[text/markdown]] +\function is.image() [get[type]prefix[image]] +\function get.markdown.link() [is.image[]thenelse] +\function get.tw5.link() [is.image[]thenelse] +\function get.link.template() [is.markdown.tiddler[]thenelse] + +\procedure postImportActions() \whitespace trim -<$list filter="[links[]] :reduce[get[type]prefix[image]thenelsesearch-replace[$title$],addprefix]" variable="imageTitle"> +<$list filter="[links[]] :reduce[get.link.template[]substitute[]addprefix]" variable="imageTitle"> <$action-sendmessage $message="tm-edit-text-operation" $param="insert-text" @@ -22,14 +32,14 @@ condition: [!has[type]] [type[text/vnd.tiddlywiki] /> <> -\end +\end postImportActions -\define buttons() +\procedure buttons() \whitespace trim <$button class="tc-btn-invisible" actions=<> ><> <$button class="tc-btn-invisible" message="tm-perform-import" param=<> actions=<> ><> -\end +\end buttons \whitespace trim <$reveal type="popup" state=<> tag="div" class="tc-editor-importpopup"> @@ -42,4 +52,4 @@ condition: [!has[type]] [type[text/vnd.tiddlywiki] - + \ No newline at end of file diff --git a/core/wiki/config/EditorEnableImportFilter.tid b/core/wiki/config/EditorEnableImportFilter.tid index 55d068e12..805ad72f0 100644 --- a/core/wiki/config/EditorEnableImportFilter.tid +++ b/core/wiki/config/EditorEnableImportFilter.tid @@ -1,4 +1,4 @@ title: $:/config/Editor/EnableImportFilter type: text/vnd.tiddlywiki -[all[current]type[text/vnd.tiddlywiki]] [all[current]!has[type]] \ No newline at end of file +[all[current]type[text/vnd.tiddlywiki]] [all[current]!has[type]] [all[current]type[text/markdown]] [all[current]type[text/x-markdown]] \ No newline at end of file