-
+
` at the beginning of the line followed by your quote. Should be used in markdown mode
-snippet-markdownTable = table
- .title = Markdown table, type `|` to separate columns and rows. Should be used in markdown mode
snippet-dryRunFlag = dry run flag
.title = Check if the template is running in dry run mode, e.g. for preview. In dry run mode, the script should not have side effects.
snippet-itemBeforeLoop = before loop
diff --git a/addon/locale/it-IT/templateEditor.ftl b/addon/locale/it-IT/templateEditor.ftl
index 55eed57..e36276c 100644
--- a/addon/locale/it-IT/templateEditor.ftl
+++ b/addon/locale/it-IT/templateEditor.ftl
@@ -45,36 +45,53 @@ restore =
help =
.label = Aiuto
+format-bold =
+ .title = Grassetto
+format-italic =
+ .title = Corsivo
+format-strikethrough =
+ .title = Barrato
+format-underline =
+ .title = Sottolineato
+format-superscript =
+ .title = Apice
+format-subscript =
+ .title = Pedice
+format-textColor =
+ .title = Colore del testo
+format-link =
+ .title = Link
+format-quote =
+ .title = Citazione
+format-monospaced =
+ .title = Testo monospaziato
+format-code =
+ .title = Codice
+format-table =
+ .title = Tabella
+format-h1 =
+ .title = Intestazione di livello 1
+format-h2 =
+ .title = Intestazione di livello 2
+format-h3 =
+ .title = Intestazione di livello 3
+format-bullet =
+ .title = Elenco puntato
+format-numbered =
+ .title = Elenco numerato
+format-inlineMath =
+ .title = Formula matematica in linea
+format-blockMath =
+ .title = Formula matematica multilinea
+format-inlineScript =
+ .title = Aggiungi uno script JS in-linea, e inserisci il risultato nella nota
+format-blockScript =
+ .title = Aggiungi uno script JS multi-linea, e inserisci il valore risultante nella nota
+
snippet-useMarkdown = usa markdown
.title = Elabora il template come markdown
snippet-useRefresh = abilita aggiornamento
.title = Permetti al contenuto generato dal template di essere aggiornato
-snippet-inlineScript = script in-linea
- .title = Aggiungi uno script JS in-linea, e inserisci il risultato nella nota
-snippet-multiLineScript = script multi-linea
- .title = Aggiungi uno script JS multi-linea, e inserisci il valore risultante nella nota
-snippet-markdownHeading1 = intestazione 1
- .title = Intestazione 1 Markdown, digita `#` a inizio riga seguito dall'intestazione. Da usare in modalità markdown
-snippet-markdownHeading2 = intestazione 2
- .title = Intestazione 2 Markdown, digita `##` a inizio riga seguito dall'intestazione. Da usare in modalità markdown
-snippet-markdownHeading3 = intestazione 3
- .title = Intestazione 3 Markdown, digita `###` a inizio riga seguito dall'intestazione. Da usare in modalità markdown
-snippet-markdownBullet = elenco puntato
- .title = Elenco puntato Markdown, digita `-` a inizio riga seguito dalla voce elenco. Da usare in modalità markdown
-snippet-markdownNumber = elenco numerato
- .title = Elenco numerato Markdown, digita `1.` a inizio riga seguito dalla voce elenco. Da usare in modalità markdown
-snippet-markdownBold = grassetto
- .title = Grassetto Markdown, digita `**` a inizio e alla fine del testo. Da usare in modalità markdown
-snippet-markdownItalic = corsivo
- .title = Corsivo Markdown, digita `_` a inizio e alla fine del testo. Da usare in modalità markdown
-snippet-markdownLink = link
- .title = Link Markdown, digita `[` all'inizio e `](url)` alla fine del testo. Da usare in modalità markdown
-snippet-markdownMonospace = testo monospaziato
- .title = Testo monospaziato Markdown, digita ` a inizio e alla fine del testo. Da usare in modalità markdown
-snippet-markdownQuote = citazione
- .title = Citazione Markdown, digita `>` a inizio della riga seguito dalla citazione. Da usare in modalità markdown
-snippet-markdownTable = tabella
- .title = Tabella Markdown, digita `|` per separare righe e colonne. Da usare in modalità markdown
snippet-dryRunFlag = esecuzione simulata
.title = Verifica che il template sia in modalità simulata, ad esempio come anteprima. In modalità di esecuzione simulata, lo script non apporta modifiche e quindi non dovrebbe avere effetti indesiderati.
snippet-itemBeforeLoop = prima del loop
@@ -84,20 +101,6 @@ snippet-itemInLoop = nel loop
snippet-itemAfterLoop = dopo il loop
.title = Contenuto da renderizzare dopo il loop degli elementi
.title = Markdown link, type `[` at the beginning and `](url)` at the end of your text. Should be used in markdown mode
-snippet-markdownMonospace = monospace text
- .title = Markdown monospace text, type ` at the beginning and end of your text. Should be used in markdown mode
-snippet-markdownQuote = quote
- .title = Markdown quote, type `>` at the beginning of the line followed by your quote. Should be used in markdown mode
-snippet-markdownTable = table
- .title = Markdown table, type `|` to separate columns and rows. Should be used in markdown mode
-snippet-dryRunFlag = dry run flag
- .title = Check if the template is running in dry run mode, e.g. for preview. In dry run mode, the script should not have side effects.
-snippet-itemBeforeLoop = before loop
- .title = Content to be rendered before the loop of items
-snippet-itemInLoop = in loop
- .title = Content to be rendered for each item in the loop
-snippet-itemAfterLoop = after loop
- .title = Content to be rendered after the loop of items
-variable-type = Type
-variable-item = Zotero.Item
diff --git a/addon/locale/ru-RU/templateEditor.ftl b/addon/locale/ru-RU/templateEditor.ftl
index cb0b0ce..0da0c21 100644
--- a/addon/locale/ru-RU/templateEditor.ftl
+++ b/addon/locale/ru-RU/templateEditor.ftl
@@ -45,36 +45,53 @@ restore =
help =
.label = Помощь
+format-bold =
+ .title = Bold
+format-italic =
+ .title = Italic
+format-strikethrough =
+ .title = Strike-through
+format-underline =
+ .title = Underline
+format-superscript =
+ .title = Superscript
+format-subscript =
+ .title = Subscript
+format-textColor =
+ .title = Text color
+format-link =
+ .title = Link
+format-quote =
+ .title = Quote
+format-monospaced =
+ .title = Monospace
+format-code =
+ .title = Code block
+format-table =
+ .title = Table
+format-h1 =
+ .title = Level 1 heading
+format-h2 =
+ .title = Level 2 heading
+format-h3 =
+ .title = Level 3 heading
+format-bullet =
+ .title = Bullet list
+format-numbered =
+ .title = Numbered list
+format-inlineMath =
+ .title = Inline math formula
+format-blockMath =
+ .title = Multi-line math formula
+format-inlineScript =
+ .title = Add an inline JS script, the result of which will be embedded in the note
+format-blockScript =
+ .title = Add a multi-line async JS script, the return value of which will be embedded in the note
+
snippet-useMarkdown = use markdown
.title = Parse the template as markdown
snippet-useRefresh = use refresh
.title = Allow the content generated by the template to be refreshed
-snippet-inlineScript = inline script
- .title = Add an inline JS script, the result of which will be embedded in the note
-snippet-multiLineScript = multi-line script
- .title = Add a multi-line async JS script, the return value of which will be embedded in the note
-snippet-markdownHeading1 = heading 1
- .title = Markdown heading 1, type `#` at the beginning of the line followed by your heading. Should be used in markdown mode
-snippet-markdownHeading2 = heading 2
- .title = Markdown heading 2, type `##` at the beginning of the line followed by your heading. Should be used in markdown mode
-snippet-markdownHeading3 = heading 3
- .title = Markdown heading 3, type `###` at the beginning of the line followed by your heading. Should be used in markdown mode
-snippet-markdownBullet = bullet list
- .title = Markdown bullet list, type `-` at the beginning of the line followed by your list item. Should be used in markdown mode
-snippet-markdownNumber = number list
- .title = Markdown number list, type `1.` at the beginning of the line followed by your list item. Should be used in markdown mode
-snippet-markdownBold = bold text
- .title = Markdown bold text, type `**` at the beginning and end of your text. Should be used in markdown mode
-snippet-markdownItalic = italic text
- .title = Markdown italic text, type `_` at the beginning and end of your text. Should be used in markdown mode
-snippet-markdownLink = link
- .title = Markdown link, type `[` at the beginning and `](url)` at the end of your text. Should be used in markdown mode
-snippet-markdownMonospace = monospace text
- .title = Markdown monospace text, type ` at the beginning and end of your text. Should be used in markdown mode
-snippet-markdownQuote = quote
- .title = Markdown quote, type `>` at the beginning of the line followed by your quote. Should be used in markdown mode
-snippet-markdownTable = table
- .title = Markdown table, type `|` to separate columns and rows. Should be used in markdown mode
snippet-dryRunFlag = dry run flag
.title = Check if the template is running in dry run mode, e.g. for preview. In dry run mode, the script should not have side effects.
snippet-itemBeforeLoop = before loop
diff --git a/addon/locale/tr-TR/templateEditor.ftl b/addon/locale/tr-TR/templateEditor.ftl
index f5a634a..f662eda 100644
--- a/addon/locale/tr-TR/templateEditor.ftl
+++ b/addon/locale/tr-TR/templateEditor.ftl
@@ -45,36 +45,53 @@ restore =
help =
.label = Yardım
+format-bold =
+ .title = Bold
+format-italic =
+ .title = Italic
+format-strikethrough =
+ .title = Strike-through
+format-underline =
+ .title = Underline
+format-superscript =
+ .title = Superscript
+format-subscript =
+ .title = Subscript
+format-textColor =
+ .title = Text color
+format-link =
+ .title = Link
+format-quote =
+ .title = Quote
+format-monospaced =
+ .title = Monospace
+format-code =
+ .title = Code block
+format-table =
+ .title = Table
+format-h1 =
+ .title = Level 1 heading
+format-h2 =
+ .title = Level 2 heading
+format-h3 =
+ .title = Level 3 heading
+format-bullet =
+ .title = Bullet list
+format-numbered =
+ .title = Numbered list
+format-inlineMath =
+ .title = Inline math formula
+format-blockMath =
+ .title = Multi-line math formula
+format-inlineScript =
+ .title = Add an inline JS script, the result of which will be embedded in the note
+format-blockScript =
+ .title = Add a multi-line async JS script, the return value of which will be embedded in the note
+
snippet-useMarkdown = use markdown
.title = Parse the template as markdown
snippet-useRefresh = use refresh
.title = Allow the content generated by the template to be refreshed
-snippet-inlineScript = inline script
- .title = Add an inline JS script, the result of which will be embedded in the note
-snippet-multiLineScript = multi-line script
- .title = Add a multi-line async JS script, the return value of which will be embedded in the note
-snippet-markdownHeading1 = heading 1
- .title = Markdown heading 1, type `#` at the beginning of the line followed by your heading. Should be used in markdown mode
-snippet-markdownHeading2 = heading 2
- .title = Markdown heading 2, type `##` at the beginning of the line followed by your heading. Should be used in markdown mode
-snippet-markdownHeading3 = heading 3
- .title = Markdown heading 3, type `###` at the beginning of the line followed by your heading. Should be used in markdown mode
-snippet-markdownBullet = bullet list
- .title = Markdown bullet list, type `-` at the beginning of the line followed by your list item. Should be used in markdown mode
-snippet-markdownNumber = number list
- .title = Markdown number list, type `1.` at the beginning of the line followed by your list item. Should be used in markdown mode
-snippet-markdownBold = bold text
- .title = Markdown bold text, type `**` at the beginning and end of your text. Should be used in markdown mode
-snippet-markdownItalic = italic text
- .title = Markdown italic text, type `_` at the beginning and end of your text. Should be used in markdown mode
-snippet-markdownLink = link
- .title = Markdown link, type `[` at the beginning and `](url)` at the end of your text. Should be used in markdown mode
-snippet-markdownMonospace = monospace text
- .title = Markdown monospace text, type ` at the beginning and end of your text. Should be used in markdown mode
-snippet-markdownQuote = quote
- .title = Markdown quote, type `>` at the beginning of the line followed by your quote. Should be used in markdown mode
-snippet-markdownTable = table
- .title = Markdown table, type `|` to separate columns and rows. Should be used in markdown mode
snippet-dryRunFlag = dry run flag
.title = Check if the template is running in dry run mode, e.g. for preview. In dry run mode, the script should not have side effects.
snippet-itemBeforeLoop = before loop
diff --git a/addon/locale/zh-CN/templateEditor.ftl b/addon/locale/zh-CN/templateEditor.ftl
index 9b35207..a892dce 100644
--- a/addon/locale/zh-CN/templateEditor.ftl
+++ b/addon/locale/zh-CN/templateEditor.ftl
@@ -44,36 +44,53 @@ restore =
help =
.label = 帮助
+format-bold =
+ .title = 加粗
+format-italic =
+ .title = 斜体
+format-strikethrough =
+ .title = 删除线
+format-underline =
+ .title = 下划线
+format-superscript =
+ .title = 上标
+format-subscript =
+ .title = 下标
+format-textColor =
+ .title = 文本颜色
+format-link =
+ .title = 添加链接
+format-quote =
+ .title = 引用文本
+format-monospaced =
+ .title = 单行
+format-code =
+ .title = 多行代码
+format-table =
+ .title = 添加表格
+format-h1 =
+ .title = 一级标题
+format-h2 =
+ .title = 二级标题
+format-h3 =
+ .title = 三级标题
+format-bullet =
+ .title = 无序列表
+format-numbered =
+ .title = 有序列表
+format-inlineMath =
+ .title = 行内数学公式
+format-blockMath =
+ .title = 多行数学公式
+format-inlineScript =
+ .title = 添加行内JS脚本,结果将嵌入到笔记中
+format-blockScript =
+ .title = 添加多行异步JS脚本,返回值将嵌入到笔记中
+
snippet-useMarkdown = 使用 markdown
.title = 将模板解析为 markdown
snippet-useRefresh = 允许内容刷新
.title = 允许模板生成的内容刷新
-snippet-inlineScript = 内联脚本
- .title = 添加一个内联 JS 脚本,其结果将嵌入到笔记中
-snippet-multiLineScript = 多行脚本
- .title = 添加一个多行异步 JS 脚本,其返回值将嵌入到笔记中
-snippet-markdownHeading1 = 一级标题
- .title = Markdown 一级标题,在行首输入 `#` 后跟你的标题。应在 Markdown 模式下使用
-snippet-markdownHeading2 = 二级标题
- .title = Markdown 二级标题,在行首输入 `##` 后跟你的标题。应在 Markdown 模式下使用
-snippet-markdownHeading3 = 三级标题
- .title = Markdown 三级标题,在行首输入 `###` 后跟你的标题。应在 Markdown 模式下使用
-snippet-markdownBullet = 无序列表
- .title = Markdown 无序列表,在行首输入 `-` 后跟你的列表项。应在 Markdown 模式下使用
-snippet-markdownNumber = 有序列表
- .title = Markdown 有序列表,在行首输入 `1.` 后跟你的列表项。应在 Markdown 模式下使用
-snippet-markdownBold = 加粗文本
- .title = Markdown 加粗文本,在文本的开头和结尾输入 `**`。应在 Markdown 模式下使用
-snippet-markdownItalic = 斜体文本
- .title = Markdown 斜体文本,在文本的开头和结尾输入 `_`。应在 Markdown 模式下使用
-snippet-markdownLink = 链接
- .title = Markdown 链接,在文本的开头输入 `[`,在结尾输入 `](url)`。应在 Markdown 模式下使用
-snippet-markdownMonospace = 单行
- .title = Markdown 单行,在文本的开头和结尾输入 `。应在 Markdown 模式下使用
-snippet-markdownQuote = 引用
- .title = Markdown 引用,在行首输入 `>` 后跟你的引用内容。应在 Markdown 模式下使用
-snippet-markdownTable = 表格
- .title = Markdown 表格,使用 `|` 分隔列和行。应在 Markdown 模式下使用
snippet-dryRunFlag = dry run标志
.title = 检查模板是否在dry run模式下运行,例如用于预览。在dry run模式下,脚本不应有副作用。
snippet-itemBeforeLoop = 循环前
diff --git a/src/modules/template/api.ts b/src/modules/template/api.ts
index 4651572..04eb5cf 100644
--- a/src/modules/template/api.ts
+++ b/src/modules/template/api.ts
@@ -90,11 +90,20 @@ async function runTemplate(
},
);
+ // Match the backticks not inside a `${}` and replace them with a placeholder
+ // Not inside a `${}`
+ templateText = templateText.replace(/`(?![^${]*\})(? {
+ const { editor, monaco } = addon.data.template.editor;
+ const selection = editor.getSelection();
+ const range = new monaco.Range(
+ selection.startLineNumber,
+ selection.startColumn,
+ selection.endLineNumber,
+ selection.endColumn,
+ );
+ const textTemplate = format.code;
+ const source =
+ editor.getModel().getValueInRange(range) ||
+ format.defaultText ||
+ "text";
+ const text = textTemplate.replace("${text}", source);
+ editor.executeEdits("", [
+ {
+ range,
+ text,
+ forceMoveMarkers: true,
+ },
+ ]);
+ // Keep the selection after inserting the format
+ const textBeforeReplace = textTemplate.split("${text}")[0];
+ const textBeforeLines = textBeforeReplace.split("\n");
+ const textLines = source.split("\n");
+
+ // Calculate the new range
+ const startLineNumber =
+ selection.startLineNumber + textBeforeLines.length - 1;
+ const startColumn =
+ textBeforeLines.length === 1
+ ? selection.startColumn + textBeforeReplace.length
+ : textBeforeLines.slice(-1)[0].length + 1;
+ const endLineNumber = startLineNumber + textLines.length - 1;
+ const endColumn =
+ textLines.length === 1
+ ? startColumn + source.length
+ : textLines.slice(-1)[0].length + 1;
+
+ const newRange = new monaco.Range(
+ startLineNumber,
+ startColumn,
+ endLineNumber,
+ endColumn,
+ );
+
+ editor.setSelection(newRange);
+
+ // If editor does not contain a line start with // @use-markdown, insert it
+ if (
+ !editor
+ .getModel()
+ .getLinesContent()
+ .some((line: any) => line.startsWith("// @use-markdown"))
+ ) {
+ editor.executeEdits("", [
+ {
+ range: new monaco.Range(1, 1, 1, 1),
+ text: "// @use-markdown\n",
+ forceMoveMarkers: true,
+ },
+ ]);
+ }
+ });
+ container.appendChild(button);
+ }
+}
+
async function updateSnippets(type: string) {
const container = addon.data.template.editor.window?.document.querySelector(
"#snippets-container",
@@ -336,9 +427,9 @@ async function updateSnippets(type: string) {
}
container.innerHTML = "";
- const snippets = snippetsStore[type as keyof typeof snippetsStore].concat(
- snippetsStore.global,
- );
+ const snippets = (
+ snippetsStore[type as keyof typeof snippetsStore] || []
+ ).concat(snippetsStore.global);
if (!snippets) {
return;
}
@@ -596,6 +687,94 @@ async function restoreTemplates(win: Window) {
await refresh();
}
+const formatStore = [
+ {
+ name: "bold",
+ code: "**${text}**",
+ },
+ {
+ name: "italic",
+ code: "_${text}_",
+ },
+ {
+ name: "strikethrough",
+ code: "~~${text}~~",
+ },
+ {
+ name: "underline",
+ code: "${text}",
+ },
+ {
+ name: "superscript",
+ code: "${text}",
+ },
+ { name: "subscript", code: "${text}" },
+ {
+ name: "textColor",
+ code: '${text}',
+ },
+ {
+ name: "link",
+ code: "[${text}](url)",
+ },
+ {
+ name: "quote",
+ code: "\n> ${text}",
+ },
+ {
+ name: "monospaced",
+ code: "`${text}`",
+ },
+ {
+ name: "code",
+ code: "\n```\n${text}\n```\n",
+ },
+ {
+ name: "table",
+ code: "\n| ${text} | Header 2 |\n|----------|----------|\n| Cell 1 | Cell 2 |\n",
+ },
+ {
+ name: "h1",
+ code: "\n# ${text}",
+ },
+ {
+ name: "h2",
+ code: "\n## ${text}",
+ },
+ {
+ name: "h3",
+ code: "\n### ${text}",
+ },
+ {
+ name: "bullet",
+ code: "\n- ${text}",
+ },
+ {
+ name: "numbered",
+ code: "\n1. ${text}",
+ },
+ {
+ name: "inlineMath",
+ code: "$${text}$",
+ defaultText: "e=mc^2",
+ },
+ {
+ name: "blockMath",
+ code: "\n$$\n${text}\n$$\n",
+ defaultText: "e=mc^2",
+ },
+ {
+ name: "inlineScript",
+ code: "${ ${text} }",
+ defaultText: "Zotero.version",
+ },
+ {
+ name: "blockScript",
+ code: "\n${{\n ${text}\n}}$\n",
+ defaultText: "return Zotero.version;",
+ },
+];
+
const snippetsStore = {
global: [
{
@@ -608,77 +787,6 @@ const snippetsStore = {
code: "\n// @use-refresh\n",
type: "syntax",
},
- {
- name: "inlineScript",
- code: "${ // write your script here }",
- type: "syntax",
- },
- {
- name: "multiLineScript",
- code: "\n${{\n // write your script here\n}}$\n",
- type: "syntax",
- },
- {
- name: "markdownHeading1",
- code: "\n# type your heading here",
- type: "syntax",
- },
- {
- name: "markdownHeading2",
- code: "\n## type your heading here",
- type: "syntax",
- },
- {
- name: "markdownHeading3",
- code: "\n### type your heading here",
- type: "syntax",
- },
- {
- name: "markdownBullet",
- code: "\n\n- type your bullet list here",
- type: "syntax",
- },
- {
- name: "markdownNumber",
- code: "\n\n1. type your number list here",
- type: "syntax",
- },
- {
- name: "markdownBold",
- code: "**type your bold text here**",
- type: "syntax",
- },
- {
- name: "markdownItalic",
- code: "_type your italic text here_",
- type: "syntax",
- },
- {
- name: "markdownLink",
- code: "[type your link text here](type your link url here)",
- type: "syntax",
- },
- {
- name: "markdownMonospace",
- code: "\n\n`type your text here`",
- type: "syntax",
- },
- {
- name: "markdownQuote",
- code: "\n\n> type your quote here",
- type: "syntax",
- },
- {
- name: "markdownTable",
- code: `
-
-| Header 1 | Header 2 |
-|----------|----------|
-| Cell 1 | Cell 2 |
-
-`,
- type: "syntax",
- },
{
name: "dryRunFlag",
code: "_env.dryRun",
diff --git a/src/modules/template/preview.ts b/src/modules/template/preview.ts
index f4ea765..bdb6d73 100644
--- a/src/modules/template/preview.ts
+++ b/src/modules/template/preview.ts
@@ -1,5 +1,6 @@
import YAML = require("yamljs");
import { getNoteLink } from "../../utils/link";
+import { renderNoteHTML } from "../../utils/note";
export { renderTemplatePreview };
@@ -142,6 +143,9 @@ async function renderTemplatePreview(
html = generateWarning(`Error: ${err.message || "Unknown error"}`);
}
+ // TODO: might not be stable?
+ html = await renderNoteHTML(html, []);
+
return html;
}