Skip to content

Commit

Permalink
Use template to handle image import
Browse files Browse the repository at this point in the history
  • Loading branch information
Leilei332 committed Aug 19, 2024
1 parent c51a233 commit 9fe3c4f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 42 deletions.
46 changes: 5 additions & 41 deletions core/ui/EditorToolbar/file-import.tid
Original file line number Diff line number Diff line change
@@ -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}}
43 changes: 43 additions & 0 deletions core/ui/FileImportTemplate.tid
Original file line number Diff line number Diff line change
@@ -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>
2 changes: 1 addition & 1 deletion core/wiki/config/EditorEnableImportFilter.tid
Original file line number Diff line number Diff line change
@@ -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]]
9 changes: 9 additions & 0 deletions plugins/tiddlywiki/markdown/EditorToolbar/file-import.tid
Original file line number Diff line number Diff line change
@@ -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}}

0 comments on commit 9fe3c4f

Please sign in to comment.