Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the editor file import UI to support markdown tiddlers #8486

Merged
merged 7 commits into from
Oct 2, 2024
34 changes: 22 additions & 12 deletions core/ui/EditorToolbar/file-import.tid
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
title: $:/core/ui/EditorToolbar/file-import
tags: $:/tags/EditorTools
condition: [<targetTiddler>!has[type]] [<targetTiddler>type[text/vnd.tiddlywiki]]
condition: [<targetTiddler>filter{$:/config/Editor/EnableImportFilter}]

\define lingo-base() $:/language/Import/
\procedure lingo-base() $:/language/Import/

\define closePopupActions()
\procedure closePopupActions()
<$action-deletetiddler $filter="[title<importState>] [title<importTitle>]"/>
\end
\end closePopupActions

\define replacement-text-image() [img[$title$]]
\procedure tw5-ImageTemplate() [img[$(currentTiddler)$]]
\procedure tw5-FileTemplate() [[$(currentTiddler)$]]

\define replacement-text-file() [[$title$]]
<!-- The following characters must be escaped in markdown: <>()\ -->
\function escape.title() [search-replace:g:regexp[\(|\)|<|>|\\],[\$&]]
\procedure markdown-ImageTemplate() ![](<#${ [<currentTiddler>escape.title[]] }$>)
\procedure markdown-FileTemplate() [](<#${ [<currentTiddler>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[]then<markdown-ImageTemplate>else<markdown-FileTemplate>]
\function get.tw5.link() [is.image[]then<tw5-ImageTemplate>else<tw5-FileTemplate>]
\function get.link.template() [<storyTiddler>is.markdown.tiddler[]then<get.markdown.link>else<get.tw5.link>]
saqimtiaz marked this conversation as resolved.
Show resolved Hide resolved

\procedure 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">
<$list filter="[<importTitle>links[]] :reduce[get.link.template[]substitute[]addprefix<accumulator>]" variable="imageTitle">
<$action-sendmessage
$message="tm-edit-text-operation"
$param="insert-text"
text=<<imageTitle>>
/>
</$list>
<<closePopupActions>>
\end
\end postImportActions

\define buttons()
\procedure 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
\end buttons

\whitespace trim
<$reveal type="popup" state=<<importState>> tag="div" class="tc-editor-importpopup">
Expand All @@ -42,4 +52,4 @@ condition: [<targetTiddler>!has[type]] [<targetTiddler>type[text/vnd.tiddlywiki]
</$tiddler>
</$list>
</div>
</$reveal>
</$reveal>
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]]
Loading