1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-04-24 11:43:11 +00:00

Use template to handle image import

This commit is contained in:
Leilei332 2024-08-19 10:56:42 +08:00
parent c51a233627
commit 9fe3c4fa91
4 changed files with 58 additions and 42 deletions

View File

@ -1,45 +1,9 @@
title: $:/core/ui/EditorToolbar/file-import
tags: $:/tags/EditorTools
image: [img[$title$]]
file: [[$title$]]
regexp-search:
regexp-replace:
condition: [<targetTiddler>!has[type]] [<targetTiddler>type[text/vnd.tiddlywiki]]
\define lingo-base() $:/language/Import/
\define closePopupActions()
<$action-deletetiddler $filter="[title<importState>] [title<importTitle>]"/>
\end
\define replacement-text-image() [img[$title$]]
\define replacement-text-file() [[$title$]]
\define postImportActions()
\whitespace trim
<$list filter="[<importTitle>links[]] :reduce[get[type]prefix[image]then<replacement-text-image>else<replacement-text-file>search-replace[$title$],<currentTiddler>addprefix<accumulator>]" variable="imageTitle">
<$action-sendmessage
$message="tm-edit-text-operation"
$param="insert-text"
text=<<imageTitle>>
/>
</$list>
<<closePopupActions>>
\end
\define buttons()
\whitespace trim
<$button class="tc-btn-invisible" actions=<<closePopupActions>> ><<lingo Listing/Cancel/Caption>></$button>
&#32;
<$button class="tc-btn-invisible" message="tm-perform-import" param=<<importTitle>> actions=<<postImportActions>> ><<lingo Listing/Import/Caption>></$button>
\end
\whitespace trim
<$reveal type="popup" state=<<importState>> tag="div" class="tc-editor-importpopup">
<div class="tc-editor-import">
<$list filter="[<importTitle>field:plugin-type[import]]">
<h2><<lingo Editor/Import/Heading>></h2>
<$tiddler tiddler=<<importTitle>>>
{{||$:/core/ui/ImportListing}}
<<buttons>>
</$tiddler>
</$list>
</div>
</$reveal>
{{||$:/core/ui/FileImportTemplate}}

View File

@ -0,0 +1,43 @@
title: $:/core/ui/FileImportTemplate
\whitespace trim
\procedure lingo-base() $:/language/Import/
\procedure closePopupActions()
<$action-deletetiddler $filter="[title<importState>] [title<importTitle>]"/>
\end
\procedure postImportActions()
<$list filter="[<importTitle>links[]]">
<$let escaped-title={{{ [<currentTiddler>search-replace:g:regexp<replacement-regexp>,<replacement-replace>] }}}>
<$let insertText={{{ [get[type]prefix[image]then<replacement-text-image>else<replacement-text-file>search-replace[$title$],<escaped-title>] }}}>
<$action-sendmessage
$message="tm-edit-text-operation"
$param="insert-text"
text=<<insertText>>
/>
</$let>
</$let>
</$list>
<<closePopupActions>>
\end
\procedure buttons()
<$button class="tc-btn-invisible tc-small-gap-right" actions=<<closePopupActions>> ><<lingo Listing/Cancel/Caption>></$button>
<$button class="tc-btn-invisible" message="tm-perform-import" param=<<importTitle>> actions=<<postImportActions>> ><<lingo Listing/Import/Caption>></$button>
\end
<$let replacement-text-image={{!!image}} replacement-text-file={{!!file}} replacement-regexp={{!!regexp-search}} replacement-replace={{!!regexp-replace}}>
<$reveal type="popup" state=<<importState>> tag="div" class="tc-editor-importpopup">
<div class="tc-editor-import">
<$list filter="[<importTitle>field:plugin-type[import]]">
<h2><<lingo Editor/Import/Heading>></h2>
<$tiddler tiddler=<<importTitle>>>
{{||$:/core/ui/ImportListing}}
<<buttons>>
</$tiddler>
</$list>
</div>
</$reveal>
</$let>

View File

@ -1,4 +1,4 @@
title: $:/config/Editor/EnableImportFilter
type: text/vnd.tiddlywiki
[all[current]type[text/vnd.tiddlywiki]] [all[current]!has[type]]
[all[current]type[text/vnd.tiddlywiki]] [all[current]!has[type]] [all[current]type[text/markdown]] [all[current]type[text/x-markdown]]

View File

@ -0,0 +1,9 @@
title: $:/plugins/tiddlywiki/markdown/EditorToolbar/file-import
tags: $:/tags/EditorTools
image: ![](<#$title$>)
file: [](<#$title$>)
regexp-search: [()<>\\]
regexp-replace: \$&
condition: [<targetTiddler>type[text/x-markdown]] [<targetTiddler>type[text/markdown]]
{{||$:/core/ui/FileImportTemplate}}