Skip to content

Build your personal knowledge base with Trilium Notes

feat(editor): settle the two quote keys apart

Elian Doran27398e349e29
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 36af71295c..7564cdcf4c 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -3156,8 +3156,10 @@
"automatic_replacements": {
"title": "Automatic replacements",
"description": "As you type, some sequences of characters are replaced with the typographic symbol they stand for. This never happens inside a code block or inline code, and pasted text is left alone.",
- "quotes": "Quotation marks",
- "quotes_description": "Which marks a straight quote turns into as you type it. Following the note's content language gives “quote” in English, „quote“ in German and « quote » in French; picking a pair instead uses it everywhere, whatever a note is written in.",
+ "double_quotes": "Double quotation marks",
+ "double_quotes_description": "Which marks a straight \" turns into as you type it. Following the note's content language gives “quote” in English, „quote“ in German and « quote » in French; picking a pair instead uses it everywhere, whatever a note is written in.",
+ "single_quotes": "Single quotation marks",
+ "single_quotes_description": "The same for a straight ', which most conventions keep for a quotation nested inside another one.",
"quotes_auto": "Follow the note's content language",
"quotes_off": "Leave straight quotes alone",
"punctuation": "Punctuation",
diff --git a/apps/client/src/widgets/type_widgets/options/text_notes.tsx b/apps/client/src/widgets/type_widgets/options/text_notes.tsx
index c2c8944893..d36e35f152 100644
--- a/apps/client/src/widgets/type_widgets/options/text_notes.tsx
+++ b/apps/client/src/widgets/type_widgets/options/text_notes.tsx
@@ -19,7 +19,7 @@ import FormText from "../../react/FormText";
import FormTextBox, { FormTextBoxWithUnit } from "../../react/FormTextBox";
import { useColorScheme, useTriliumOption, useTriliumOptionBool } from "../../react/hooks";
import { getHtml } from "../../react/RawHtml";
-import { QUOTE_STYLE_PRESETS } from "../text/quotes";
+import { QUOTE_MARK_PRESETS } from "../text/quotes";
import { type CustomReplacement, parseCustomReplacements } from "../text/replacements";
import OptionsPageHeader from "./components/OptionsPageHeader";
import OptionsRow, { OptionsRowWithToggle } from "./components/OptionsRow";
@@ -188,7 +188,8 @@ function EditorFeatures() {
* behaviour being undocumented as about it being unwanted, so the examples are the point.
*/
function AutomaticReplacements() {
- const [quoteStyle, setQuoteStyle] = useTriliumOption("textNoteQuoteStyle");
+ const [doubleQuoteStyle, setDoubleQuoteStyle] = useTriliumOption("textNoteDoubleQuoteStyle");
+ const [singleQuoteStyle, setSingleQuoteStyle] = useTriliumOption("textNoteSingleQuoteStyle");
const [punctuationEnabled, setPunctuationEnabled] = useTriliumOptionBool("textNotePunctuationReplacementsEnabled");
const [mathEnabled, setMathEnabled] = useTriliumOptionBool("textNoteMathReplacementsEnabled");
const [symbolsEnabled, setSymbolsEnabled] = useTriliumOptionBool("textNoteSymbolReplacementsEnabled");
@@ -196,25 +197,19 @@ function AutomaticReplacements() {
return (
<OptionsSection title={t("automatic_replacements.title")} description={t("automatic_replacements.description")}>
<OptionsRow
- name="quote-style"
- label={t("automatic_replacements.quotes")}
- description={t("automatic_replacements.quotes_description")}
+ name="double-quote-style"
+ label={t("automatic_replacements.double_quotes")}
+ description={t("automatic_replacements.double_quotes_description")}
>
- <FormSelect
- currentValue={quoteStyle || "auto"}
- onChange={setQuoteStyle}
- keyProperty="value" titleProperty="label"
- values={[
- { value: "auto", label: t("automatic_replacements.quotes_auto") },
- { value: "off", label: t("automatic_replacements.quotes_off") },
- // The marks are their own label — no wording to translate, and nothing
- // between the choice and what it produces.
- ...QUOTE_STYLE_PRESETS.map(({ id, style }) => ({
- value: id,
- label: `${style.primary[0]}…${style.primary[1]} ${style.secondary[0]}…${style.secondary[1]}`
- }))
- ]}
- />
+ <QuoteStyleSelect currentValue={doubleQuoteStyle} onChange={setDoubleQuoteStyle} />
+ </OptionsRow>
+
+ <OptionsRow
+ name="single-quote-style"
+ label={t("automatic_replacements.single_quotes")}
+ description={t("automatic_replacements.single_quotes_description")}
+ >
+ <QuoteStyleSelect currentValue={singleQuoteStyle} onChange={setSingleQuoteStyle} />
</OptionsRow>
<OptionsRowWithToggle
@@ -246,6 +241,31 @@ function AutomaticReplacements() {
);
}
+/**
+ * The choice offered for one of the two quote keys. The same list serves both: which pair belongs on
+ * which key is a convention rather than a property of the marks, and the conventions disagree —
+ * British typography puts `‘…’` where American puts `“…”`.
+ */
+function QuoteStyleSelect({ currentValue, onChange }: { currentValue: string, onChange: (newValue: string) => void }) {
+ return (
+ <FormSelect
+ currentValue={currentValue || "auto"}
+ onChange={onChange}
+ keyProperty="value" titleProperty="label"
+ values={[
+ { value: "auto", label: t("automatic_replacements.quotes_auto") },
+ { value: "off", label: t("automatic_replacements.quotes_off") },
+ // The marks are their own label — no wording to translate, and nothing between the
+ // choice and what it produces.
+ ...QUOTE_MARK_PRESETS.map(({ id, marks }) => ({
+ value: id,
+ label: `${marks[0]}…${marks[1]}`
+ }))
+ ]}
+ />
+ );
+}
+
/** A row while it is being edited: the stored pair plus a key that survives its neighbours moving. */
interface EditableReplacement extends CustomReplacement {
id: string;
diff --git a/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx b/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx
index 8bb31099af..f4ce114018 100644
--- a/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx
+++ b/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx
@@ -58,7 +58,8 @@ export default function CKEditorWithWatchdog({ containerRef: externalContainerRe
// the transformation list at plugin init — `normalizeTransformations` runs once inside
// `_enableTransformationWatchers` — so unlike the settings read through a getter (link previews,
// clipboard image embedding) a live editor has nothing left to re-read.
- const [ quoteStyle ] = useTriliumOption("textNoteQuoteStyle");
+ const [ doubleQuoteStyle ] = useTriliumOption("textNoteDoubleQuoteStyle");
+ const [ singleQuoteStyle ] = useTriliumOption("textNoteSingleQuoteStyle");
const [ punctuationReplacements ] = useTriliumOptionBool("textNotePunctuationReplacementsEnabled");
const [ mathReplacements ] = useTriliumOptionBool("textNoteMathReplacementsEnabled");
const [ symbolReplacements ] = useTriliumOptionBool("textNoteSymbolReplacementsEnabled");
@@ -295,7 +296,7 @@ export default function CKEditorWithWatchdog({ containerRef: externalContainerRe
// which is acceptable for a change made deliberately over in the settings.
}, [
contentLanguage, uiLanguage, isClassicEditor, multilineToolbar,
- quoteStyle, punctuationReplacements, mathReplacements, symbolReplacements,
+ doubleQuoteStyle, singleQuoteStyle, punctuationReplacements, mathReplacements, symbolReplacements,
customReplacements, defaultContentLanguage
]);
diff --git a/apps/client/src/widgets/type_widgets/text/config.spec.ts b/apps/client/src/widgets/type_widgets/text/config.spec.ts
index bbd174af6d..f95c98bb37 100644
--- a/apps/client/src/widgets/type_widgets/text/config.spec.ts
+++ b/apps/client/src/widgets/type_widgets/text/config.spec.ts
@@ -281,18 +281,21 @@ describe("CK config - language & emoji", () => {
it("leaves CKEditor's own quotes in force for a locale with no mapping", async () => {
const config = await buildConfig(baseOpts({ contentLanguage: "ku" }));
- // Not removed, so the default `quotes` group still runs — better than a locale we have no
- // pair for losing quote replacement altogether.
- expect(config.typing?.transformations.remove).not.toContain("quotes");
+ // Not removed, so CKEditor's own quotes still run — better than a locale we have no pair for
+ // losing quote replacement altogether.
+ expect(config.typing?.transformations.remove).not.toContain("quotesPrimary");
+ expect(config.typing?.transformations.remove).not.toContain("quotesSecondary");
expect(config.typing?.transformations.extra).toEqual([]);
// The language itself still applies, so right-to-left text lays out correctly regardless.
expect(config.language).toMatchObject({ content: "ku" });
});
it("expresses the enabled groups as deltas, leaving CKEditor's defaults to upstream", async () => {
- // All four groups on: only the quotes are taken over, and only because we supply our own.
+ // All four groups on: only the two quote transformations are taken over, and only because we
+ // supply our own. Named individually rather than as the `quotes` group, which would take both
+ // away together — they are configured apart.
const allOn = await buildConfig(baseOpts({ contentLanguage: "de" }));
- expect(allOn.typing?.transformations.remove).toEqual(["quotes"]);
+ expect(allOn.typing?.transformations.remove).toEqual(["quotesPrimary", "quotesSecondary"]);
expect(allOn.typing?.transformations.extra).toHaveLength(2);
// Each toggle removes its group by name, so the patterns behind the dashes and fractions
@@ -301,7 +304,30 @@ describe("CK config - language & emoji", () => {
optionsState.map.textNoteMathReplacementsEnabled = "false";
optionsState.map.textNoteSymbolReplacementsEnabled = "false";
const allOff = await buildConfig(baseOpts({ contentLanguage: "de" }));
- expect(allOff.typing?.transformations.remove).toEqual(["typography", "mathematical", "symbols", "quotes"]);
+ expect(allOff.typing?.transformations.remove).toEqual([
+ "typography", "mathematical", "symbols", "quotesPrimary", "quotesSecondary"
+ ]);
+ });
+
+ it("settles the two quote keys apart", async () => {
+ const quotesOf = (config: Awaited<ReturnType<typeof buildConfig>>) =>
+ (config.typing?.transformations.extra ?? []).map((t) => (t as { to: string[] }).to);
+
+ // Guillemets on the double key, the language's own marks left on the single one — the mix
+ // that a single dropdown could not express.
+ optionsState.map.textNoteDoubleQuoteStyle = "guillemets";
+ const config = await buildConfig(baseOpts({ contentLanguage: "de" }));
+
+ expect(quotesOf(config)).toEqual([
+ [null, "«", null, "»"],
+ [null, "‚", null, "‘"]
+ ]);
+
+ // Switching one off leaves the other running.
+ optionsState.map.textNoteSingleQuoteStyle = "off";
+ const halfOff = await buildConfig(baseOpts({ contentLanguage: "de" }));
+ expect(quotesOf(halfOff)).toEqual([[null, "«", null, "»"]]);
+ expect(halfOff.typing?.transformations.remove).toContain("quotesSecondary");
});
it("adds the user's own replacements alongside the quote ones", async () => {
@@ -324,13 +350,14 @@ describe("CK config - language & emoji", () => {
expect(config.typing?.transformations.extra).toHaveLength(2);
});
- it("drops the quote replacements entirely when the style is off", async () => {
- optionsState.map.textNoteQuoteStyle = "off";
+ it("drops the quote replacements entirely when both are off", async () => {
+ optionsState.map.textNoteDoubleQuoteStyle = "off";
+ optionsState.map.textNoteSingleQuoteStyle = "off";
const config = await buildConfig(baseOpts({ contentLanguage: "de" }));
// Removed and not re-supplied, so a straight quote stays straight whatever the language.
- expect(config.typing?.transformations.remove).toContain("quotes");
+ expect(config.typing?.transformations.remove).toEqual(["quotesPrimary", "quotesSecondary"]);
expect(config.typing?.transformations.extra).toEqual([]);
});
@@ -341,14 +368,16 @@ describe("CK config - language & emoji", () => {
// The whole point of picking one: a note written in German still gets the chosen marks. This
// is what serves someone writing several languages in a single note, whom no per-note
// language setting can help.
- optionsState.map.textNoteQuoteStyle = "corner";
+ optionsState.map.textNoteDoubleQuoteStyle = "corner";
+ optionsState.map.textNoteSingleQuoteStyle = "white-corner";
expect(quotesOf(await buildConfig(baseOpts({ contentLanguage: "de" })))).toEqual([
[null, "「", null, "」"],
[null, "『", null, "』"]
]);
// An id we do not know falls back to following the language rather than to no quotes.
- optionsState.map.textNoteQuoteStyle = "no-such-style";
+ optionsState.map.textNoteDoubleQuoteStyle = "no-such-style";
+ optionsState.map.textNoteSingleQuoteStyle = "no-such-style";
expect(quotesOf(await buildConfig(baseOpts({ contentLanguage: "de" })))).toEqual([
[null, "„", null, "“"],
[null, "‚", null, "‘"]
diff --git a/apps/client/src/widgets/type_widgets/text/config.ts b/apps/client/src/widgets/type_widgets/text/config.ts
index 77b7921c56..e608a06f16 100644
--- a/apps/client/src/widgets/type_widgets/text/config.ts
+++ b/apps/client/src/widgets/type_widgets/text/config.ts
@@ -15,7 +15,7 @@ import { getTaskStateDefinitions, openCustomTaskStateConfig } from "../../../ser
import { isMac } from "../../../services/utils.js";
import { resolveContentLanguage } from "../../../utils/formatters.js";
import SAMPLE_DIAGRAMS from "../mermaid/sample_diagrams.js";
-import { buildQuoteTransformations, getQuoteStylePreset, resolveQuoteStyle } from "./quotes.js";
+import { buildQuoteTransformation, resolveQuoteSetting } from "./quotes.js";
import { buildCustomTransformations, parseCustomReplacements } from "./replacements.js";
import { buildToolbarConfig } from "./toolbar.js";
@@ -327,18 +327,17 @@ function buildTransformationsConfig(contentLanguage: string | null): TextTransfo
if (options.get("textNoteMathReplacementsEnabled") !== "true") remove.push("mathematical");
if (options.get("textNoteSymbolReplacementsEnabled") !== "true") remove.push("symbols");
- const quoteSetting = options.get("textNoteQuoteStyle") || "auto";
- // An unknown id — the option hand-edited, or written by a version offering a preset this one has
- // dropped — falls back to following the language rather than to no quotes at all.
- const quoteStyle = quoteSetting === "off"
- ? null
- : getQuoteStylePreset(quoteSetting) ?? resolveQuoteStyle(contentLanguage);
- if (quoteSetting === "off" || quoteStyle) {
- remove.push("quotes");
- }
+ // The two keys are settled apart, so each is taken over from upstream only when we have
+ // something to put in its place — naming the individual transformations rather than the `quotes`
+ // group, which would take both away together.
+ const double = resolveQuoteSetting(options.get("textNoteDoubleQuoteStyle"), "primary", contentLanguage);
+ const single = resolveQuoteSetting(options.get("textNoteSingleQuoteStyle"), "secondary", contentLanguage);
+ if (double.overridesUpstream) remove.push("quotesPrimary");
+ if (single.overridesUpstream) remove.push("quotesSecondary");
const extra = [
- ...(quoteStyle ? buildQuoteTransformations(quoteStyle) : []),
+ ...(double.marks ? [buildQuoteTransformation("\"", double.marks)] : []),
+ ...(single.marks ? [buildQuoteTransformation("'", single.marks)] : []),
...buildCustomTransformations(parseCustomReplacements(options.get("textNoteCustomReplacements")))
];
diff --git a/apps/client/src/widgets/type_widgets/text/quotes.spec.ts b/apps/client/src/widgets/type_widgets/text/quotes.spec.ts
index 6018a03380..de4bc114f0 100644
--- a/apps/client/src/widgets/type_widgets/text/quotes.spec.ts
+++ b/apps/client/src/widgets/type_widgets/text/quotes.spec.ts
@@ -1,13 +1,13 @@
import { describe, expect, it } from "vitest";
-import { buildQuoteTransformations, getQuoteStylePreset, QUOTE_STYLE_PRESETS, type QuoteStyle, resolveQuoteStyle } from "./quotes.js";
+import { buildQuoteTransformation, getQuoteMarkPreset, QUOTE_MARK_PRESETS, type QuoteStyle, resolveQuoteSetting, resolveQuoteStyle } from "./quotes.js";
/**
* Applies a transformation the way CKEditor's `TextTransformation` does: match the text before the
* caret, then swap in every group the `to` array names, leaving the `null` ones alone. Lets the
* regex and the replacement array be asserted together, which is where a quote pair actually breaks.
*/
-function transform(transformation: ReturnType<typeof buildQuoteTransformations>[number], text: string) {
+function transform(transformation: ReturnType<typeof buildQuoteTransformation>, text: string) {
const from = transformation.from;
if (!(from instanceof RegExp) || !Array.isArray(transformation.to)) {
throw new Error("the quote transformations are built as a RegExp plus a replacement array");
@@ -27,8 +27,10 @@ function transform(transformation: ReturnType<typeof buildQuoteTransformations>[
function transformationsFor(locale: string) {
const style = resolveQuoteStyle(locale);
if (!style) throw new Error(`expected ${locale} to resolve to a quote style`);
- const [primary, secondary] = buildQuoteTransformations(style);
- return { primary, secondary };
+ return {
+ primary: buildQuoteTransformation("\"", style.primary),
+ secondary: buildQuoteTransformation("'", style.secondary)
+ };
}
describe("resolveQuoteStyle", () => {
@@ -93,9 +95,9 @@ describe("resolveQuoteStyle", () => {
* below do not carry an invisible character that reads as stray whitespace. */
const NNBSP = "\u202F";
-describe("QUOTE_STYLE_PRESETS", () => {
+describe("QUOTE_MARK_PRESETS", () => {
it("offers each pair once, under an id naming the marks rather than a language", () => {
- const ids = QUOTE_STYLE_PRESETS.map((preset) => preset.id);
+ const ids = QUOTE_MARK_PRESETS.map((preset) => preset.id);
expect(new Set(ids).size).toBe(ids.length);
// Named for their shape: the same pair serves several languages, and a writer picking one is
@@ -107,24 +109,51 @@ describe("QUOTE_STYLE_PRESETS", () => {
it("takes its marks from the locale table, so a pair is written in one place", () => {
// French above all: its narrow no-break spaces are invisible in a diff and have been
// mistyped before.
- expect(getQuoteStylePreset("guillemets-spaced")).toEqual(resolveQuoteStyle("fr"));
- expect(getQuoteStylePreset("low-high")).toEqual(resolveQuoteStyle("de"));
- expect(getQuoteStylePreset("corner")).toEqual(resolveQuoteStyle("ja"));
+ expect(getQuoteMarkPreset("guillemets-spaced")).toEqual(resolveQuoteStyle("fr")?.primary);
+ expect(getQuoteMarkPreset("low-high")).toEqual(resolveQuoteStyle("de")?.primary);
+ expect(getQuoteMarkPreset("single-low-high")).toEqual(resolveQuoteStyle("de")?.secondary);
+ expect(getQuoteMarkPreset("white-corner")).toEqual(resolveQuoteStyle("ja")?.secondary);
});
- it("inverts the levels for the single-curly pair rather than restating them", () => {
- const english = resolveQuoteStyle("en");
+ it("offers both curly pairs, so either can go on either key", () => {
+ // The conventions disagree about which belongs on which — British typography sets on the
+ // single marks where American sets on the double — so neither is tied to a key here.
+ expect(getQuoteMarkPreset("double-curly")).toEqual(resolveQuoteStyle("en")?.primary);
+ expect(getQuoteMarkPreset("single-curly")).toEqual(resolveQuoteStyle("en")?.secondary);
+ });
+
+ it("returns null for an id it does not know", () => {
+ expect(getQuoteMarkPreset("no-such-style")).toBeNull();
+ expect(getQuoteMarkPreset("")).toBeNull();
+ expect(getQuoteMarkPreset(null)).toBeNull();
+ });
+});
- expect(getQuoteStylePreset("single-curly")).toEqual({
- primary: english?.secondary,
- secondary: english?.primary
+describe("resolveQuoteSetting", () => {
+ it("lets a chosen pair outrank the note's language", () => {
+ expect(resolveQuoteSetting("corner", "primary", "de")).toEqual({
+ marks: resolveQuoteStyle("ja")?.primary,
+ overridesUpstream: true
});
});
- it("returns null for an id it does not know", () => {
- expect(getQuoteStylePreset("no-such-style")).toBeNull();
- expect(getQuoteStylePreset("")).toBeNull();
- expect(getQuoteStylePreset(null)).toBeNull();
+ it("takes the level asked for when following the language", () => {
+ const german = resolveQuoteStyle("de");
+
+ expect(resolveQuoteSetting("auto", "primary", "de")).toEqual({ marks: german?.primary, overridesUpstream: true });
+ expect(resolveQuoteSetting("auto", "secondary", "de")).toEqual({ marks: german?.secondary, overridesUpstream: true });
+ });
+
+ it("installs nothing but still takes over when switched off", () => {
+ expect(resolveQuoteSetting("off", "primary", "de")).toEqual({ marks: null, overridesUpstream: true });
+ });
+
+ it("leaves upstream in place for a language with no pair of ours", () => {
+ // The distinction that keeps an unmapped locale on CKEditor's own quotes rather than losing
+ // them: nothing to install, and nothing to remove either.
+ expect(resolveQuoteSetting("auto", "primary", "ku")).toEqual({ marks: null, overridesUpstream: false });
+ // An id we do not know is read as "auto" rather than as "off".
+ expect(resolveQuoteSetting("no-such-style", "primary", "ku")).toEqual({ marks: null, overridesUpstream: false });
});
});
diff --git a/apps/client/src/widgets/type_widgets/text/quotes.ts b/apps/client/src/widgets/type_widgets/text/quotes.ts
index 36f2bd79d3..139fff5f9b 100644
--- a/apps/client/src/widgets/type_widgets/text/quotes.ts
+++ b/apps/client/src/widgets/type_widgets/text/quotes.ts
@@ -2,12 +2,15 @@ import type { TextTypingTransformationDescription } from "@triliumnext/ckeditor5
import { normalizeLocale } from "../../../utils/formatters.js";
-/** The opening and closing marks of one quotation level. */
+/** The opening and closing mark of one quotation level — what a single quote key produces. */
+export type QuoteMarks = readonly [open: string, close: string];
+
+/** Both levels a language sets its quotations in. */
export interface QuoteStyle {
- /** The marks a quotation is normally set in. */
- primary: readonly [open: string, close: string];
- /** The marks a quotation nested inside another one is set in. */
- secondary: readonly [open: string, close: string];
+ /** The marks a quotation is normally set in — what the double quote key produces. */
+ primary: QuoteMarks;
+ /** The marks a quotation nested inside another one is set in — the single quote key. */
+ secondary: QuoteMarks;
}
/**
@@ -72,30 +75,65 @@ const QUOTE_STYLES: Record<string, QuoteStyle> = {
};
/**
- * The styles offered as an explicit choice, for writers who would rather name their marks than have
- * a language name them — someone writing three languages in one note, or who simply prefers one
- * pair and does not want the note's metadata deciding. macOS offers exactly this and nothing else;
- * LibreOffice offers it alongside the locale defaults, which is the shape taken here.
+ * The mark pairs offered as an explicit choice, for writers who would rather name their marks than
+ * have a language name them — someone writing three languages in a single note, or who simply
+ * prefers one pair and does not want the note's metadata deciding. macOS offers exactly this and
+ * nothing else; LibreOffice offers it alongside the locale defaults, which is the shape taken here.
+ *
+ * One flat list, offered for both the double and the single quote: which key a pair belongs on is a
+ * convention rather than a property of the marks, and the conventions disagree — British typography
+ * puts `‘…’` on the double quote where American puts `“…”`. Choosing for each key separately is what
+ * lets both be had.
*
- * Each entry points at a row of the table above rather than restating its marks, so a pair is
- * written in one place only — the French narrow no-break spaces above all, which are invisible in a
- * diff and have already been mistyped twice.
+ * Every pair that a locale already writes points at that row rather than restating it, so the marks
+ * live in one place — the French narrow no-break spaces above all, which are invisible in a diff and
+ * have been mistyped twice already.
*/
-export const QUOTE_STYLE_PRESETS = [
- { id: "double-curly", style: QUOTE_STYLES.en },
- // The levels the other way up, which is how British typography traditionally set them.
- { id: "single-curly", style: { primary: QUOTE_STYLES.en.secondary, secondary: QUOTE_STYLES.en.primary } },
- { id: "low-high", style: QUOTE_STYLES.de },
- { id: "low-right", style: QUOTE_STYLES.pl },
- { id: "guillemets", style: QUOTE_STYLES.ru },
- { id: "guillemets-spaced", style: QUOTE_STYLES.fr },
- { id: "corner", style: QUOTE_STYLES.ja }
-] as const satisfies readonly { id: string; style: QuoteStyle }[];
-
-/** The style a preset id names, or `null` for an id we do not know — a hand-edited option, or one
+export const QUOTE_MARK_PRESETS = [
+ { id: "double-curly", marks: QUOTE_STYLES.en.primary },
+ { id: "single-curly", marks: QUOTE_STYLES.en.secondary },
+ { id: "low-high", marks: QUOTE_STYLES.de.primary },
+ { id: "single-low-high", marks: QUOTE_STYLES.de.secondary },
+ { id: "low-right", marks: QUOTE_STYLES.pl.primary },
+ { id: "guillemets", marks: QUOTE_STYLES.ru.primary },
+ { id: "guillemets-spaced", marks: QUOTE_STYLES.fr.primary },
+ // The only pair no locale in the table writes: single guillemets, which several conventions
+ // nest inside the double ones.
+ { id: "single-guillemets", marks: ["‹", "›"] },
+ { id: "corner", marks: QUOTE_STYLES.ja.primary },
+ { id: "white-corner", marks: QUOTE_STYLES.ja.secondary }
+] as const satisfies readonly { id: string; marks: readonly [open: string, close: string] }[];
+
+/** The marks a preset id names, or `null` for an id we do not know — a hand-edited option, or one
* written by a version that offered a preset this one has dropped. */
-export function getQuoteStylePreset(id: string | null | undefined): QuoteStyle | null {
- return QUOTE_STYLE_PRESETS.find((preset) => preset.id === id)?.style ?? null;
+export function getQuoteMarkPreset(id: string | null | undefined): QuoteMarks | null {
+ return QUOTE_MARK_PRESETS.find((preset) => preset.id === id)?.marks ?? null;
+}
+
+/** What one of the two quote settings comes to for a given note. */
+export interface ResolvedQuoteSetting {
+ /** The marks to install, or `null` to install none. */
+ marks: QuoteMarks | null;
+ /** Whether CKEditor's own transformation for this key has to be taken out of the way. */
+ overridesUpstream: boolean;
+}
+
+/**
+ * Works out what one of the two settings means for a note: an explicit pair wins outright, `off`
+ * installs nothing, and anything else follows the note's language.
+ *
+ * The distinction the `overridesUpstream` flag carries is that a language we have no pair for keeps
+ * falling through to CKEditor's own quotes, rather than silently losing quote replacement — while
+ * `off` deliberately takes them away.
+ */
+export function resolveQuoteSetting(setting: string | null | undefined, level: keyof QuoteStyle, contentLanguage: string | null): ResolvedQuoteSetting {
+ if (setting === "off") return { marks: null, overridesUpstream: true };
+
+ const preset = getQuoteMarkPreset(setting);
+ if (preset) return { marks: preset, overridesUpstream: true };
+
+ const style = resolveQuoteStyle(contentLanguage);
+ return style ? { marks: style[level], overridesUpstream: true } : { marks: null, overridesUpstream: false };
}
/**
@@ -120,14 +158,12 @@ export function resolveQuoteStyle(...candidates: (string | null | undefined)[]):
}
/**
- * The transformations that replace a typed `"…"` and `'…'` with the style's marks, in the shape
- * CKEditor's `typing.transformations.extra` takes.
+ * The transformation that replaces a run typed between `quoteCharacter`s with `marks`, in the shape
+ * CKEditor's `typing.transformations.extra` takes. Built one key at a time, since the double and the
+ * single quote are configured apart.
*/
-export function buildQuoteTransformations(style: QuoteStyle): TextTypingTransformationDescription[] {
- return [
- { from: buildQuotesRegExp("\""), to: [null, style.primary[0], null, style.primary[1]] },
- { from: buildQuotesRegExp("'"), to: [null, style.secondary[0], null, style.secondary[1]] }
- ];
+export function buildQuoteTransformation(quoteCharacter: "\"" | "'", marks: QuoteMarks): TextTypingTransformationDescription {
+ return { from: buildQuotesRegExp(quoteCharacter), to: [null, marks[0], null, marks[1]] };
}
/**
diff --git a/packages/commons/src/lib/options_interface.ts b/packages/commons/src/lib/options_interface.ts
index 09e76baec5..9c1d69ba6c 100644
--- a/packages/commons/src/lib/options_interface.ts
+++ b/packages/commons/src/lib/options_interface.ts
@@ -242,11 +242,13 @@ export interface OptionDefinitions extends KeyboardShortcutsOptions<KeyboardActi
codeNoteIndentWithTabs: boolean;
textNoteEditorMultilineToolbar: boolean;
/**
- * Which typographic quotes a typed `"…"` becomes: `auto` to follow the note's content language,
- * `off` to leave straight quotes alone, or the id of one of `QUOTE_STYLE_PRESETS` to always use
- * that pair whatever the note is written in.
+ * Which marks a typed `"…"` becomes: `auto` to follow the note's content language, `off` to
+ * leave straight quotes alone, or the id of one of `QUOTE_MARK_PRESETS` to always use that pair
+ * whatever the note is written in.
*/
- textNoteQuoteStyle: string;
+ textNoteDoubleQuoteStyle: string;
+ /** The same for a typed `'…'`, which conventions set a nested quotation in. */
+ textNoteSingleQuoteStyle: string;
/** Whether `...` becomes `…`, and ` -- ` / ` --- ` become an en/em dash, as they are typed. */
textNotePunctuationReplacementsEnabled: boolean;
/** Whether `1/2`, `!=`, `->` and their kin become `½`, `≠`, `→` as they are typed. */
diff --git a/packages/trilium-core/src/routes/api/options.ts b/packages/trilium-core/src/routes/api/options.ts
index bc7006934b..0831eaba60 100644
--- a/packages/trilium-core/src/routes/api/options.ts
+++ b/packages/trilium-core/src/routes/api/options.ts
@@ -124,7 +124,8 @@ const ALLOWED_OPTIONS = new Set<OptionNames>([
"languages",
"textNoteEditorType",
"textNoteEditorMultilineToolbar",
- "textNoteQuoteStyle",
+ "textNoteDoubleQuoteStyle",
+ "textNoteSingleQuoteStyle",
"textNotePunctuationReplacementsEnabled",
"textNoteMathReplacementsEnabled",
"textNoteSymbolReplacementsEnabled",
diff --git a/packages/trilium-core/src/services/options_init.ts b/packages/trilium-core/src/services/options_init.ts
index 500508f5de..4a981e3d51 100644
--- a/packages/trilium-core/src/services/options_init.ts
+++ b/packages/trilium-core/src/services/options_init.ts
@@ -309,8 +309,11 @@ const defaultOptions: DefaultOption[] = [
// they could be turned off; the point of the setting is that the behaviour is now visible and
// refusable, not that it changes for anyone who leaves it alone.
// "auto" keeps the marks following the note's language, which is what the editor did before the
- // setting existed. An explicit preset overrides the language entirely — the point of offering it.
- { name: "textNoteQuoteStyle", value: "auto", isSynced: true },
+ // setting existed. An explicit preset overrides the language entirely — the point of offering
+ // it. The two keys are set apart because the conventions disagree about which pair belongs on
+ // which: British typography puts the single curly marks where American puts the double ones.
+ { name: "textNoteDoubleQuoteStyle", value: "auto", isSynced: true },
+ { name: "textNoteSingleQuoteStyle", value: "auto", isSynced: true },
{ name: "textNotePunctuationReplacementsEnabled", value: "true", isSynced: true },
{ name: "textNoteMathReplacementsEnabled", value: "true", isSynced: true },
{ name: "textNoteSymbolReplacementsEnabled", value: "true", isSynced: true },