1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-30 05:19:57 +00:00

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
This commit is contained in:
Saq Imtiaz 2024-10-02 14:15:53 +02:00 committed by GitHub
parent c82761a600
commit e591dfd590
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 13 deletions

View File

@ -1,20 +1,30 @@
title: $:/core/ui/EditorToolbar/file-import title: $:/core/ui/EditorToolbar/file-import
tags: $:/tags/EditorTools 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>]"/> <$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>]
\procedure postImportActions()
\whitespace trim \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 <$action-sendmessage
$message="tm-edit-text-operation" $message="tm-edit-text-operation"
$param="insert-text" $param="insert-text"
@ -22,14 +32,14 @@ condition: [<targetTiddler>!has[type]] [<targetTiddler>type[text/vnd.tiddlywiki]
/> />
</$list> </$list>
<<closePopupActions>> <<closePopupActions>>
\end \end postImportActions
\define buttons() \procedure buttons()
\whitespace trim \whitespace trim
<$button class="tc-btn-invisible" actions=<<closePopupActions>> ><<lingo Listing/Cancel/Caption>></$button> <$button class="tc-btn-invisible" actions=<<closePopupActions>> ><<lingo Listing/Cancel/Caption>></$button>
&#32; &#32;
<$button class="tc-btn-invisible" message="tm-perform-import" param=<<importTitle>> actions=<<postImportActions>> ><<lingo Listing/Import/Caption>></$button> <$button class="tc-btn-invisible" message="tm-perform-import" param=<<importTitle>> actions=<<postImportActions>> ><<lingo Listing/Import/Caption>></$button>
\end \end buttons
\whitespace trim \whitespace trim
<$reveal type="popup" state=<<importState>> tag="div" class="tc-editor-importpopup"> <$reveal type="popup" state=<<importState>> tag="div" class="tc-editor-importpopup">

View File

@ -1,4 +1,4 @@
title: $:/config/Editor/EnableImportFilter title: $:/config/Editor/EnableImportFilter
type: text/vnd.tiddlywiki 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]]