Skip to content

Commit

Permalink
Add support for %PREFIX(...)% and %SUFFIX(...)% #15
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed May 19, 2024
1 parent 64f2bab commit 2ab1ad1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
|Title and URL|`%TITLE%%EOL%%URL%`|
|HTML Link|`<a title="%HTML_SAFE(%TITLE%)%" href="%HTML_SAFE(%URL%)%">%HTML_SAFE(%TITLE%)%</a>`|
|HTML Link (Rich Text)|`%RT%<a title="%HTML_SAFE(%TITLE%)%" href="%HTML_SAFE(%URL%)%">%HTML_SAFE(%TITLE%)%</a>`|
|HTML Link List (Rich Text, unordered)|`%RT%%PREFIX(<ul>%EOL%)%%SUFFIX(</ul>%EOL%)%<li><a href="%URL_HTMLIFIED%">%TITLE_HTMLIFIED%</a></li>%EOL%`|
|Markdown Link|`[%MD_SAFE(%TITLE%)%](%URL% "%MD_LINK_TITLE_SAFE(%TITLE%)%")`|
|Markdown Link List|`%TREE_INDENT(" ")%* [%MD_SAFE(%TITLE%)%](%URL% "%MD_LINK_TITLE_SAFE(%TITLE%)%")`|
|URL without query|`%REPLACE("%URL%", "\?.*$", "")%`|
Expand Down
2 changes: 1 addition & 1 deletion _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"config_copyToClipboardFormats_restoreDefaults": { "message": "Restore default formats keeping added formats" },
"config_copyToClipboardFormats_accesskey": { "message": "A non-whitespace character next to \"&\" (for example \"L\" in \"&Location\") in the label will become the accesskey for the item." },
"config_copyToClipboardFormats_placeholders": { "message": "Available place holders for formats:\n%URL%=Page URL,\n%TITLE%=Page Title,\n%TREE_INDENT(indenter1, indenter2, ... indenterN)%=Indent (powered by tabs management addon like Tree Style Tab)\n%TAB%=Tab,\n%EOL%=Line Feed,\n%CONTAINER_NAME(prefix, suffix)%=Container name with prefix and suffix (ex. `%CONTAINER_NAME(\"[\", \"]\")%` will be filled like \"[Personal]\" for \"Personal\" conainer tab),\n%CONTAINER_URL%=URL with \"ext+container:\" scheme (for Open external links in a container)" },
"config_copyToClipboardFormats_placeholders_special": { "message": "Place holders based on page contents (you need to grant required permission):\n%AUTHOR%=Author name (specified by META),\n%DESCRIPTION%=Description (specified by META),\n%KEYWORDS%=Search keywords (specified by META),\n%RT%=Copy as a rich text (Note: this placeholder itself is cleared from the copied text)" },
"config_copyToClipboardFormats_placeholders_special": { "message": "Place holders based on page contents (you need to grant required permission):\n%AUTHOR%=Author name (specified by META),\n%DESCRIPTION%=Description (specified by META),\n%KEYWORDS%=Search keywords (specified by META),\n%RT%=Copy as a rich text (Note: this placeholder itself is cleared from the copied text),\n%PREFIX(...)%=Add given prefix at the first,\n%SUFFIX(...)%=Add given suffix at the last" },
"config_copyToClipboardFormats_placeholders_replace": { "message": "`%REPLACE(\"base text\", \"match pattern regular expression 1\", \"replaced text 1\", \"match pattern regular expression 2\", \"replaced text 2\", ...)%` will return text replaced with regular expressions. \nFor example: \n%REPLACE(\"%URL%\", \"\\?.*$\", \"\")% \n => URL with stripped query parameters \n%REPLACE(\"%URL%\", \"^((?!\\w+://([^/]*\\.)?(google\\.com|duckduckgo\\.com)/.*).*)\\?.*$\", \"$$1\")% \n => URL with stripped query parameters, except Google and DuckDuckGo" },
"config_copyToClipboardFormats_placeholders_html_safe": { "message": "`%HTML_SAFE(...)%` will return text escaped for HTML. For example:\n%HTML_SAFE(%TITLE%)% => Title escaped for HTML." },
"config_copyToClipboardFormats_placeholders_md_safe": { "message": "`%MD_SAFE(...)%` and `%MD_LINK_TITLE_SAFE(...)%` will return text escaped for Markdown. For example:\n[%MD_LINK_TITLE_SAFE(%TITLE%)%](%MD_SAFE(%URL%)%) => Link in Markdown." },
Expand Down
2 changes: 1 addition & 1 deletion _locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"config_copyToClipboardFormats_restoreDefaults": { "message": "追加した書式を維持して既定の書式を復元する" },
"config_copyToClipboardFormats_accesskey": { "message": "ラベル内で「&」に続く空白以外の文字(例:「&Location」の「L」)はその項目のアクセスキーになります。" },
"config_copyToClipboardFormats_placeholders": { "message": "書式には以下のプレースホルダを使えます:\n%URL%=ページのURL,\n%TITLE%=ページのタイトル,\n%TREE_INDENT(indenter1, indenter2, ... indenterN)%=インデント(Tree Style Tabなどのタブ管理アドオンを使用)\n%TAB%=タブ文字,\n%EOL%=改行,\n%CONTAINER_NAME(prefix, suffix)%=コンテナーの名前(例:「%CONTAINER_NAME('[', ']')%」は「個人用」のコンテナータブであれば「[個人用]」になります),\n%CONTAINER_URL%=\"ext+container:\"スキームを伴ったURL(Open external links in a container用)" },
"config_copyToClipboardFormats_placeholders_special": { "message": "ページの内容に基づくプレースホルダー(権限の許可が必要です):\n%AUTHOR%=metaタグで指定された作者名,\n%DESCRIPTION%=metaタグで指定された説明文,\n%KEYWORDS%=metaタグで指定された検索用キーワード,\n%RT%=リッチテキストとしてコピーする(このプレースホルダ自体は空文字に変換されます)" },
"config_copyToClipboardFormats_placeholders_special": { "message": "ページの内容に基づくプレースホルダー(権限の許可が必要です):\n%AUTHOR%=metaタグで指定された作者名,\n%DESCRIPTION%=metaタグで指定された説明文,\n%KEYWORDS%=metaタグで指定された検索用キーワード,\n%RT%=リッチテキストとしてコピーする(このプレースホルダ自体は空文字に変換されます),\n%PREFIX(...)%=指定文字列を全体の前に足す,\n%SUFFIX(...)%=指定文字列を全体の後に足す" },
"config_copyToClipboardFormats_placeholders_html_safe": { "message": "%HTML_SAFE(...)% で文字列をHTML用にエスケープできます。\n例:\n%HTML_SAFE(%TITLE%)%→HTML用にエスケープされたタイトル" },
"config_copyToClipboardFormats_placeholders_md_safe": { "message": "%MD_SAFE(...)% や %MD_LINK_TITLE_SAFE(...)% で文字列をMarkdown用にもエスケープできます。\n例:\n[%MD_LINK_TITLE_SAFE(%TITLE%)%](%MD_SAFE(%URL%)%) → Markdownでのリンク" },
"config_copyToClipboardFormats_placeholders_replace": { "message": "%REPLACE(\"置換対象の文字列\", \"置換箇所の正規表現1\", \"置換後の文字列1\", \"置換箇所の正規表現2\", \"置換後の文字列2\", ...)% で正規表現による置換を行えます。\n例: \n%REPLACE(\"%URL%\", \"\\?.*$\", \"\")% \n →常にURL末尾のクエリ文字列を除去\n%REPLACE(\"%URL%\", \"^((?!\\w+://([^/]*\\.)?(google\\.com|duckduckgo\\.com)/.*).*)\\?.*$\", \"$$1\")% \n → GoogleとDuckDuckGo以外でURL末尾のクエリ文字列を除去" },
Expand Down
2 changes: 1 addition & 1 deletion _locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"hash": "7292b900eb5211e2a5c8cc8219de8a1b"
},
"config_copyToClipboardFormats_placeholders": {
"message": "格式栏可用的占位符:\n%URL%=页面网址,\n%TITLE%=页面标题,\n%AUTHOR%=作者名(META 信息指定),\n%DESCRIPTION%=描述(META 信息指定),\n%KEYWORDS%=搜索关键词(META 信息指定),\n%URL_HTMLIFIED%=为 HTML 转义的 URL,\n%TITLE_HTMLIFIED%=为 HTML 转义的标题,\n%AUTHOR_HTMLIFIED%=为 HTML 转义的作者名,\n%DESCRIPTION_HTMLIFIED%=为 HTML 转义的描述,\n%KEYWORDS_HTMLIFIED%=为 HTML 转义的关键词,\n%TST_INDENT(indenter)%、%TST_INDENT(indenter1)(indenter2)...(indenterN)%=层级(由 Tree Style Tab 提供)\n%TAB%=Tab,\n%EOL%=换行, \n%CONTAINER_NAME(prefix, suffix)%=Container name with prefix and suffix (ex. \"%CONTAINER_NAME('[', ']')%\" will be filled like \"[Personal]\" for \"Personal\" conainer tab),\n%CONTAINER_NAME_HTMLIFIED(prefix, suffix)%=Container name with prefix and suffix escaped for HTML,\n%CONTAINER_URL%=URL with \"ext+container:\" scheme (for Open external links in a container),\n%CONTAINER_URL_HTMLIFIED%=URL with \"ext+container:\" scheme escaped for HTML,\n%RT%=复制为富文本(注:复制的文本中不含此占位符)",
"message": "格式栏可用的占位符:\n%URL%=页面网址,\n%TITLE%=页面标题,\n%AUTHOR%=作者名(META 信息指定),\n%DESCRIPTION%=描述(META 信息指定),\n%KEYWORDS%=搜索关键词(META 信息指定),\n%URL_HTMLIFIED%=为 HTML 转义的 URL,\n%TITLE_HTMLIFIED%=为 HTML 转义的标题,\n%AUTHOR_HTMLIFIED%=为 HTML 转义的作者名,\n%DESCRIPTION_HTMLIFIED%=为 HTML 转义的描述,\n%KEYWORDS_HTMLIFIED%=为 HTML 转义的关键词,\n%TST_INDENT(indenter)%、%TST_INDENT(indenter1)(indenter2)...(indenterN)%=层级(由 Tree Style Tab 提供)\n%TAB%=Tab,\n%EOL%=换行, \n%CONTAINER_NAME(prefix, suffix)%=Container name with prefix and suffix (ex. \"%CONTAINER_NAME('[', ']')%\" will be filled like \"[Personal]\" for \"Personal\" conainer tab),\n%CONTAINER_NAME_HTMLIFIED(prefix, suffix)%=Container name with prefix and suffix escaped for HTML,\n%CONTAINER_URL%=URL with \"ext+container:\" scheme (for Open external links in a container),\n%CONTAINER_URL_HTMLIFIED%=URL with \"ext+container:\" scheme escaped for HTML,\n%RT%=复制为富文本(注:复制的文本中不含此占位符),\n%PREFIX(...)%=Add given prefix at the first,\n%SUFFIX(...)%=Add given suffix at the last",
"hash": "e4fa53727b5f0e073c95814d82357d4a"
},
"config_shortcuts_caption": {
Expand Down
8 changes: 7 additions & 1 deletion common/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,18 @@ export async function copyToClipboard(tabs, format) {
}
}

const prefix = /%PREFIX\((["'])?(.+?)\)\1%/i.test(format) ? RegExp.$2.replace(/%EOL%/gi, getLineFeed()) : '';
const suffix = /%SUFFIX\((["'])?(.+?)\)\1%/i.test(format) ? RegExp.$2.replace(/%EOL%/gi, getLineFeed()) : '';

const delimiter = getDelimiter();
const itemsToCopy = await Promise.all(tabs.map((tab, index) => fillPlaceHolders(format, tab, indentLevels[index])));

const richText = /%RT%/i.test(format) ? itemsToCopy.map(item => item.richText).join('<br />') : null ;
const richText = /%RT%/i.test(format) ? prefix + itemsToCopy.map(item => item.richText).join('<br />') + suffix : null ;
let plainText = itemsToCopy.map(item => item.plainText).join(delimiter);
if (configs.delimiter == Constants.kDELIMITER_LINE_BREAK &&
tabs.length > 1)
plainText += delimiter;
plainText = prefix + plainText + suffix;

log('richText: ', richText);
log('plainText: ', plainText);
Expand Down Expand Up @@ -313,6 +317,8 @@ function processPlaceHolder(
log('processPlaceHolder ', name, rawArgs, args);
switch (name.trim().toLowerCase()) {
case 'rt':
case 'prefix':
case 'suffix':
return '';

case 'html':
Expand Down

0 comments on commit 2ab1ad1

Please sign in to comment.