Files
TiddlyWiki5/core/ui/EditorToolbar/file-import.tid
Saq Imtiaz e591dfd590 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
2024-10-02 13:15:53 +01:00

55 lines
2.1 KiB
Plaintext

title: $:/core/ui/EditorToolbar/file-import
tags: $:/tags/EditorTools
condition: [<targetTiddler>filter{$:/config/Editor/EnableImportFilter}]
\procedure lingo-base() $:/language/Import/
\procedure closePopupActions()
<$action-deletetiddler $filter="[title<importState>] [title<importTitle>]"/>
\end closePopupActions
\procedure tw5-ImageTemplate() [img[$(currentTiddler)$]]
\procedure tw5-FileTemplate() [[$(currentTiddler)$]]
<!-- 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[]] }$>)
\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>]
\procedure postImportActions()
\whitespace trim
<$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 postImportActions
\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 buttons
\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>