mirror of
https://github.com/TiddlyWiki/TiddlyWiki5.git
synced 2026-04-25 05:04:41 +00:00
* 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
55 lines
2.1 KiB
Plaintext
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() 
|
|
\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>
|
|
 
|
|
<$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> |