From a9afa6080e7ecdcc5df9d7749edb87d843a8c1d8 Mon Sep 17 00:00:00 2001 From: saqimtiaz Date: Mon, 5 Aug 2024 08:37:48 +0200 Subject: [PATCH 1/7] chore: update editor file import to use procedures and substitute operator --- core/ui/EditorToolbar/file-import.tid | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/ui/EditorToolbar/file-import.tid b/core/ui/EditorToolbar/file-import.tid index 20cff547d42..7eacb24decd 100644 --- a/core/ui/EditorToolbar/file-import.tid +++ b/core/ui/EditorToolbar/file-import.tid @@ -2,19 +2,19 @@ title: $:/core/ui/EditorToolbar/file-import tags: $:/tags/EditorTools condition: [!has[type]] [type[text/vnd.tiddlywiki]] -\define lingo-base() $:/language/Import/ +\procedure lingo-base() $:/language/Import/ -\define closePopupActions() +\procedure closePopupActions() <$action-deletetiddler $filter="[title] [title]"/> \end -\define replacement-text-image() [img[$title$]] +\procedure replacement-text-image() [img[$1$]] -\define replacement-text-file() [[$title$]] +\procedure replacement-text-file() [[$1$]] -\define postImportActions() +\procedure postImportActions() \whitespace trim -<$list filter="[links[]] :reduce[get[type]prefix[image]thenelsesearch-replace[$title$],addprefix]" variable="imageTitle"> +<$list filter="[links[]] :reduce[get[type]prefix[image]thenelsesubstituteaddprefix]" variable="imageTitle"> <$action-sendmessage $message="tm-edit-text-operation" $param="insert-text" @@ -24,7 +24,7 @@ condition: [!has[type]] [type[text/vnd.tiddlywiki] <> \end -\define buttons() +\procedure buttons() \whitespace trim <$button class="tc-btn-invisible" actions=<> ><> From 658767480942756598179175c97415412e735928 Mon Sep 17 00:00:00 2001 From: saqimtiaz Date: Mon, 5 Aug 2024 08:43:56 +0200 Subject: [PATCH 2/7] feat: refactor editor file-import UI to reuse filter from $:/config/Editor/EnableImportFilter --- core/ui/EditorToolbar/file-import.tid | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/ui/EditorToolbar/file-import.tid b/core/ui/EditorToolbar/file-import.tid index 7eacb24decd..5b0269fb9e4 100644 --- a/core/ui/EditorToolbar/file-import.tid +++ b/core/ui/EditorToolbar/file-import.tid @@ -1,6 +1,6 @@ title: $:/core/ui/EditorToolbar/file-import tags: $:/tags/EditorTools -condition: [!has[type]] [type[text/vnd.tiddlywiki]] +condition: [filter{$:/config/Editor/EnableImportFilter}] \procedure lingo-base() $:/language/Import/ From 5b7d6d0ee3cdbcfd4b6126b35c5d8d9115e664d9 Mon Sep 17 00:00:00 2001 From: saqimtiaz Date: Mon, 5 Aug 2024 09:12:19 +0200 Subject: [PATCH 3/7] feat: support for markdown in editor file import UI --- core/ui/EditorToolbar/file-import.tid | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/ui/EditorToolbar/file-import.tid b/core/ui/EditorToolbar/file-import.tid index 5b0269fb9e4..ac2e8b6880f 100644 --- a/core/ui/EditorToolbar/file-import.tid +++ b/core/ui/EditorToolbar/file-import.tid @@ -8,13 +8,19 @@ condition: [filter{$:/config/Editor/EnableImportFilter}] <$action-deletetiddler $filter="[title] [title]"/> \end -\procedure replacement-text-image() [img[$1$]] +\procedure tw5-ImageTemplate() [img[$1$]] +\procedure tw5-FileTemplate() [[$1$]] -\procedure replacement-text-file() [[$1$]] +\procedure markdown-ImageTemplate() ![]($1$) +\procedure mardkown-FileTempalte() []($1$) + +\function getImageTemplate() [type[text/x-markdown]thenelse] +\function getFileTemplate() [type[text/x-markdown]thenelse] +\function getReplacementTemplate() [get[type]prefix[image]thenelse] \procedure postImportActions() \whitespace trim -<$list filter="[links[]] :reduce[get[type]prefix[image]thenelsesubstituteaddprefix]" variable="imageTitle"> +<$list filter="[links[]] :reduce[substituteaddprefix]" variable="imageTitle"> <$action-sendmessage $message="tm-edit-text-operation" $param="insert-text" From 2670b82f7b2e746288225683cd77fc68c15a1dda Mon Sep 17 00:00:00 2001 From: saqimtiaz Date: Mon, 5 Aug 2024 13:33:41 +0200 Subject: [PATCH 4/7] feat: improve markdown type detection and enable markdown image imports by default --- core/ui/EditorToolbar/file-import.tid | 6 ++++-- core/wiki/config/EditorEnableImportFilter.tid | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/core/ui/EditorToolbar/file-import.tid b/core/ui/EditorToolbar/file-import.tid index ac2e8b6880f..d6192d039b2 100644 --- a/core/ui/EditorToolbar/file-import.tid +++ b/core/ui/EditorToolbar/file-import.tid @@ -14,10 +14,12 @@ condition: [filter{$:/config/Editor/EnableImportFilter}] \procedure markdown-ImageTemplate() ![]($1$) \procedure mardkown-FileTempalte() []($1$) -\function getImageTemplate() [type[text/x-markdown]thenelse] -\function getFileTemplate() [type[text/x-markdown]thenelse] +\function is.Markdown.Tiddler() [all[]type[text/x-markdown]] [all[]type[text/markdown]] +\function getImageTemplate() [is.Markdown.Tiddler[]thenelse] +\function getFileTemplate() [is.Markdown.Tiddler[]thenelse] \function getReplacementTemplate() [get[type]prefix[image]thenelse] + \procedure postImportActions() \whitespace trim <$list filter="[links[]] :reduce[substituteaddprefix]" variable="imageTitle"> diff --git a/core/wiki/config/EditorEnableImportFilter.tid b/core/wiki/config/EditorEnableImportFilter.tid index 55d068e120c..805ad72f0b0 100644 --- a/core/wiki/config/EditorEnableImportFilter.tid +++ b/core/wiki/config/EditorEnableImportFilter.tid @@ -1,4 +1,4 @@ title: $:/config/Editor/EnableImportFilter type: text/vnd.tiddlywiki -[all[current]type[text/vnd.tiddlywiki]] [all[current]!has[type]] \ No newline at end of file +[all[current]type[text/vnd.tiddlywiki]] [all[current]!has[type]] [all[current]type[text/markdown]] [all[current]type[text/x-markdown]] \ No newline at end of file From a6e2a00a5a7a1a897c2b87d22f8103dc09480af3 Mon Sep 17 00:00:00 2001 From: saqimtiaz Date: Fri, 9 Aug 2024 10:18:21 +0200 Subject: [PATCH 5/7] fix: uri encode tiddler titles for markdown --- core/ui/EditorToolbar/file-import.tid | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/core/ui/EditorToolbar/file-import.tid b/core/ui/EditorToolbar/file-import.tid index d6192d039b2..58aae0ddb5f 100644 --- a/core/ui/EditorToolbar/file-import.tid +++ b/core/ui/EditorToolbar/file-import.tid @@ -6,23 +6,24 @@ condition: [filter{$:/config/Editor/EnableImportFilter}] \procedure closePopupActions() <$action-deletetiddler $filter="[title] [title]"/> -\end +\end closePopupActions -\procedure tw5-ImageTemplate() [img[$1$]] -\procedure tw5-FileTemplate() [[$1$]] +\procedure tw5-ImageTemplate() [img[$(currentTiddler)$]] +\procedure tw5-FileTemplate() [[$(currentTiddler)$]] -\procedure markdown-ImageTemplate() ![]($1$) -\procedure mardkown-FileTempalte() []($1$) - -\function is.Markdown.Tiddler() [all[]type[text/x-markdown]] [all[]type[text/markdown]] -\function getImageTemplate() [is.Markdown.Tiddler[]thenelse] -\function getFileTemplate() [is.Markdown.Tiddler[]thenelse] -\function getReplacementTemplate() [get[type]prefix[image]thenelse] +\procedure markdown-ImageTemplate() ![](<#${ [encodeuri[]] }$>) +\procedure markdown-FileTemplate() [](<#${ [encodeuri[]] }$>) +\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[]thenelse] +\function get.tw5.link() [is.image[]thenelse] +\function get.link.template() [is.markdown.tiddler[]thenelse] \procedure postImportActions() \whitespace trim -<$list filter="[links[]] :reduce[substituteaddprefix]" variable="imageTitle"> +<$list filter="[links[]] :reduce[get.link.template[]substitute[]addprefix]" variable="imageTitle"> +<$action-log $$filter="imageTitle"/> <$action-sendmessage $message="tm-edit-text-operation" $param="insert-text" @@ -30,14 +31,14 @@ condition: [filter{$:/config/Editor/EnableImportFilter}] /> <> -\end +\end postImportActions \procedure buttons() \whitespace trim <$button class="tc-btn-invisible" actions=<> ><> <$button class="tc-btn-invisible" message="tm-perform-import" param=<> actions=<> ><> -\end +\end buttons \whitespace trim <$reveal type="popup" state=<> tag="div" class="tc-editor-importpopup"> From 19c122456137f59c0788b6a4f8e276312ef8baf6 Mon Sep 17 00:00:00 2001 From: saqimtiaz Date: Fri, 9 Aug 2024 13:51:57 +0200 Subject: [PATCH 6/7] escape characters instead of URI encoding --- core/ui/EditorToolbar/file-import.tid | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/ui/EditorToolbar/file-import.tid b/core/ui/EditorToolbar/file-import.tid index 58aae0ddb5f..571078e963d 100644 --- a/core/ui/EditorToolbar/file-import.tid +++ b/core/ui/EditorToolbar/file-import.tid @@ -11,8 +11,10 @@ condition: [filter{$:/config/Editor/EnableImportFilter}] \procedure tw5-ImageTemplate() [img[$(currentTiddler)$]] \procedure tw5-FileTemplate() [[$(currentTiddler)$]] -\procedure markdown-ImageTemplate() ![](<#${ [encodeuri[]] }$>) -\procedure markdown-FileTemplate() [](<#${ [encodeuri[]] }$>) +\procedure escape-regexp() [()<>\\] +\function escape.title() [search-replace:g:regexp,[\$&]] +\procedure markdown-ImageTemplate() ![](<#${ [escape.title[]] }$>) +\procedure markdown-FileTemplate() [](<#${ [escape.title[]] }$>) \function is.markdown.tiddler() [all[]type[text/x-markdown]] [all[]type[text/markdown]] \function is.image() [get[type]prefix[image]] @@ -23,7 +25,6 @@ condition: [filter{$:/config/Editor/EnableImportFilter}] \procedure postImportActions() \whitespace trim <$list filter="[links[]] :reduce[get.link.template[]substitute[]addprefix]" variable="imageTitle"> -<$action-log $$filter="imageTitle"/> <$action-sendmessage $message="tm-edit-text-operation" $param="insert-text" @@ -51,4 +52,4 @@ condition: [filter{$:/config/Editor/EnableImportFilter}] - + \ No newline at end of file From aec092e10966cd39fb75dadb00f713935b1f57a5 Mon Sep 17 00:00:00 2001 From: saqimtiaz Date: Fri, 9 Aug 2024 15:50:08 +0200 Subject: [PATCH 7/7] fix: tweak regexp to simplify code and document escaping rules --- core/ui/EditorToolbar/file-import.tid | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/ui/EditorToolbar/file-import.tid b/core/ui/EditorToolbar/file-import.tid index 571078e963d..0fd5e08a512 100644 --- a/core/ui/EditorToolbar/file-import.tid +++ b/core/ui/EditorToolbar/file-import.tid @@ -11,8 +11,8 @@ condition: [filter{$:/config/Editor/EnableImportFilter}] \procedure tw5-ImageTemplate() [img[$(currentTiddler)$]] \procedure tw5-FileTemplate() [[$(currentTiddler)$]] -\procedure escape-regexp() [()<>\\] -\function escape.title() [search-replace:g:regexp,[\$&]] + +\function escape.title() [search-replace:g:regexp[\(|\)|<|>|\\],[\$&]] \procedure markdown-ImageTemplate() ![](<#${ [escape.title[]] }$>) \procedure markdown-FileTemplate() [](<#${ [escape.title[]] }$>)