mirror of
https://github.com/mara-li/obsidian-my-thesaurus.git
synced 2026-07-22 05:38:22 +00:00
feat(standardize): allow to remove accents when reading the table
This commit is contained in:
parent
ada642f7ee
commit
25e7c38de2
7 changed files with 90 additions and 59 deletions
|
|
@ -32,11 +32,11 @@
|
|||
"settings": {
|
||||
"columns": {
|
||||
"synonyms": {
|
||||
"desc": "These values will be recognized in the file content and the corresponding term will be applied.",
|
||||
"desc": "This value is the name of the column of words to be searched in the thesaurus.",
|
||||
"title": "Synonym"
|
||||
},
|
||||
"term": {
|
||||
"desc": "This value will be set as a tag in your properties.",
|
||||
"desc": "This value is the name of the tag column to be added.",
|
||||
"title": "Term"
|
||||
},
|
||||
"title": "Column title"
|
||||
|
|
@ -47,6 +47,14 @@
|
|||
"separate": "Separate paths with coma, semicolon, spaces or newlines.",
|
||||
"title": "Included paths"
|
||||
},
|
||||
"removeAccents": {
|
||||
"by": "like",
|
||||
"cafe": "cafe",
|
||||
"café": "café",
|
||||
"desc": "Ignores accents during recognition: helps identify",
|
||||
"title": "Remove accents",
|
||||
"viceversa": "(and vice versa)"
|
||||
},
|
||||
"separator": {
|
||||
"desc": "CSV column separator.",
|
||||
"md": "Markdown table",
|
||||
|
|
|
|||
|
|
@ -32,11 +32,11 @@
|
|||
"settings": {
|
||||
"columns": {
|
||||
"synonyms": {
|
||||
"desc": "Ces valeurs seront reconnus dans le contenu du fichier et le terme correspondant sera appliqué.",
|
||||
"desc": "Cette valeur est le nom de la colonne des mots à chercher dans le thésaurus.",
|
||||
"title": "Synonymes"
|
||||
},
|
||||
"term": {
|
||||
"desc": "Cette valeur sera ajouté comme tag dans vos propriétés.",
|
||||
"desc": "Cette valeur est le nom de la colonne des tags à ajouter.",
|
||||
"title": "Terme"
|
||||
},
|
||||
"title": "Colonne cible"
|
||||
|
|
@ -47,6 +47,14 @@
|
|||
"separate": "Séparer les chemins par une virgule, point virgule ou un retour à la ligne.",
|
||||
"title": "Chemins inclus"
|
||||
},
|
||||
"removeAccents": {
|
||||
"by": "comme",
|
||||
"cafe": "cafe",
|
||||
"café": "café",
|
||||
"desc": "Ignore les accents lors de la reconnaissance : permet d'identifier",
|
||||
"title": "Supprimer les accents",
|
||||
"viceversa": "(et inversement)"
|
||||
},
|
||||
"separator": {
|
||||
"desc": "Séparateur des colonnes du fichier CSV.",
|
||||
"md": "Markdown table",
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ export interface MyThesaurusSettings {
|
|||
includedPaths: string[];
|
||||
separator: Separator;
|
||||
columns: ColumnName;
|
||||
removeAccents: boolean;
|
||||
}
|
||||
|
||||
export type ColumnName = {
|
||||
|
|
@ -28,10 +29,11 @@ export type Translation = TFunction<"translation", undefined>;
|
|||
|
||||
export const DEFAULT_SETTINGS: MyThesaurusSettings = {
|
||||
thesaurusPath: "",
|
||||
includedPaths: [],
|
||||
includedPaths: [".*"],
|
||||
separator: ";",
|
||||
columns: {
|
||||
term: "term",
|
||||
synonyms: "synonyms",
|
||||
},
|
||||
removeAccents: false,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ export default class MyThesaurus extends Plugin {
|
|||
};
|
||||
}
|
||||
try {
|
||||
const tags = getTags(contents, thesaurus);
|
||||
const tags = getTags(contents, thesaurus, this.settings.removeAccents).concat(...getTags(file.basename, thesaurus, this.settings.removeAccents));
|
||||
if (tags.length > 0) {
|
||||
await this.addTagsToNote(tags, file);
|
||||
const successMsg = sanitizeHTMLToDom(
|
||||
|
|
@ -160,7 +160,8 @@ export default class MyThesaurus extends Plugin {
|
|||
await this.readThesaurus(),
|
||||
this.settings.separator,
|
||||
i18next.t,
|
||||
this.settings.columns
|
||||
this.settings.columns,
|
||||
this.settings.removeAccents
|
||||
);
|
||||
const results: ParseResults = [];
|
||||
const noticeBar = new Notice(
|
||||
|
|
@ -216,7 +217,8 @@ export default class MyThesaurus extends Plugin {
|
|||
thesaurusContent,
|
||||
this.settings.separator,
|
||||
i18next.t,
|
||||
this.settings.columns
|
||||
this.settings.columns,
|
||||
this.settings.removeAccents
|
||||
);
|
||||
this.parseFile(file, false, thesaurus);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -30,47 +30,7 @@ export class MyThesaurusSettingTab extends PluginSettingTab {
|
|||
|
||||
containerEl.empty();
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(i18next.t("settings.separator.title"))
|
||||
.setDesc(i18next.t("settings.separator.desc"))
|
||||
.addDropdown((dropdown) => {
|
||||
dropdown
|
||||
.addOption(";", ";")
|
||||
.addOption(",", ",")
|
||||
.addOption("\t", `${i18next.t("settings.separator.tab")}`)
|
||||
.addOption("|", "|")
|
||||
.addOption("md", `${i18next.t("settings.separator.md")}`)
|
||||
.setValue(this.settings.separator)
|
||||
.onChange(async (value) => {
|
||||
this.settings.separator = value as Separator;
|
||||
await this.plugin.saveSettings();
|
||||
this.display();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl).setName(i18next.t("settings.columns.title")).setHeading();
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(i18next.t("settings.columns.term.title"))
|
||||
.setDesc(i18next.t("settings.columns.term.desc"))
|
||||
.addText((text) => {
|
||||
text.setValue(this.settings.columns.term).onChange(async (value) => {
|
||||
this.settings.columns.term = value;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(i18next.t("settings.columns.synonyms.title"))
|
||||
.setDesc(i18next.t("settings.columns.synonyms.desc"))
|
||||
.addText((text) => {
|
||||
text.setValue(this.settings.columns.synonyms).onChange(async (value) => {
|
||||
this.settings.columns.synonyms = value;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
const thesaurusSetting = new Setting(containerEl)
|
||||
const thesaurusSetting = new Setting(containerEl)
|
||||
.setHeading()
|
||||
.setName(i18next.t("settings.thesaurusPath.title"))
|
||||
.setDesc(i18next.t("settings.thesaurusPath.desc"))
|
||||
|
|
@ -128,6 +88,46 @@ export class MyThesaurusSettingTab extends PluginSettingTab {
|
|||
});
|
||||
});
|
||||
if (this.isInvalid) thesaurusSetting.setClass("is-invalid");
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(i18next.t("settings.separator.title"))
|
||||
.setDesc(i18next.t("settings.separator.desc"))
|
||||
.addDropdown((dropdown) => {
|
||||
dropdown
|
||||
.addOption(";", ";")
|
||||
.addOption(",", ",")
|
||||
.addOption("\t", `${i18next.t("settings.separator.tab")}`)
|
||||
.addOption("|", "|")
|
||||
.addOption("md", `${i18next.t("settings.separator.md")}`)
|
||||
.setValue(this.settings.separator)
|
||||
.onChange(async (value) => {
|
||||
this.settings.separator = value as Separator;
|
||||
await this.plugin.saveSettings();
|
||||
this.display();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl).setName(i18next.t("settings.columns.title")).setHeading();
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(i18next.t("settings.columns.term.title"))
|
||||
.setDesc(i18next.t("settings.columns.term.desc"))
|
||||
.addText((text) => {
|
||||
text.setValue(this.settings.columns.term).onChange(async (value) => {
|
||||
this.settings.columns.term = value;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(i18next.t("settings.columns.synonyms.title"))
|
||||
.setDesc(i18next.t("settings.columns.synonyms.desc"))
|
||||
.addText((text) => {
|
||||
text.setValue(this.settings.columns.synonyms).onChange(async (value) => {
|
||||
this.settings.columns.synonyms = value;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(i18next.t("settings.includedPaths.title"))
|
||||
|
|
@ -138,7 +138,9 @@ export class MyThesaurusSettingTab extends PluginSettingTab {
|
|||
)
|
||||
)
|
||||
.addTextArea((text) => {
|
||||
text.setValue(this.settings.includedPaths.join("\n")).onChange(async (value) => {
|
||||
text
|
||||
.setPlaceholder(".*")
|
||||
.setValue(this.settings.includedPaths.join("\n")).onChange(async (value) => {
|
||||
this.settings.includedPaths = value
|
||||
.split(/[\n,;]+/)
|
||||
.map((path) => path.trim())
|
||||
|
|
@ -146,5 +148,15 @@ export class MyThesaurusSettingTab extends PluginSettingTab {
|
|||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(i18next.t("settings.removeAccents.title"))
|
||||
.setDesc(sanitizeHTMLToDom(`${i18next.t("settings.removeAccents.desc")}<code>"${i18next.t("settings.removeAccents.café")}"</code>${i18next.t("settings.removeAccents.by")}<code>"${i18next.t("settings.removeAccents.cafe")}"</code>${i18next.t("settings.removeAccents.viceversa")}.`))
|
||||
.addToggle((toggle) => {
|
||||
toggle.setValue(this.settings.removeAccents).onChange(async (value) => {
|
||||
this.settings.removeAccents = value;
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@ export function getThesaurus(
|
|||
fileContent: string,
|
||||
separator: Separator,
|
||||
ln: Translation,
|
||||
columnNames: ColumnName
|
||||
columnNames: ColumnName,
|
||||
standardize?: boolean
|
||||
) {
|
||||
//verify if they are only two columns
|
||||
const isMd = separator === "md";
|
||||
|
|
@ -71,14 +72,12 @@ export function getThesaurus(
|
|||
throw new Error(ln("error.csv.malformed", { len: columns.length }));
|
||||
|
||||
const key = columns[indexKey].trim();
|
||||
const synonyms = columns[indexSynonyms].trim();
|
||||
let synonyms = columns[indexSynonyms].trim();
|
||||
if (standardize) synonyms = synonyms.standardize();
|
||||
if (key !== "" && synonyms !== "") {
|
||||
if (thesaurus[key] === undefined) {
|
||||
if (thesaurus[key] === undefined)
|
||||
thesaurus[key] = new Set();
|
||||
thesaurus[key].add(synonyms);
|
||||
} else {
|
||||
thesaurus[key].add(synonyms);
|
||||
}
|
||||
thesaurus[key].add(synonyms);
|
||||
}
|
||||
}
|
||||
return thesaurus;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import type { Thesaurus } from "../interfaces";
|
||||
|
||||
export function getTags(content: string, thesaurus: Thesaurus) {
|
||||
export function getTags(content: string, thesaurus: Thesaurus, standardize?: boolean): string[] {
|
||||
const tagsToAdd: string[] = [];
|
||||
|
||||
if (standardize) content = content.standardize();
|
||||
for (const tags of Object.keys(thesaurus)) {
|
||||
const synonyms = thesaurus[tags];
|
||||
const regex = new RegExp(`\\b(${[...synonyms].join("|")})\\b`, "gi");
|
||||
|
|
|
|||
Loading…
Reference in a new issue