Skip to content

Commit

Permalink
feat(text): Hard line break conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li authored Jul 24, 2022
1 parent 6ba4163 commit 398f02c
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 78 deletions.
88 changes: 22 additions & 66 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
"detect-indent": "^7.0.0",
"detect-newline": "^4.0.0",
"js-base64": "^3.7.2",
"obsidian-dataview": "^0.4.25",
"release-please": "^13.18.3",
"standard-version": "^9.5.0",
"stringify-package": "^1.0.1",
"obsidian-dataview": "^0.5.41"
"stringify-package": "^1.0.1"
}
}
4 changes: 3 additions & 1 deletion plugin/githubInteraction/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {deleteFromGithub} from "./delete"
import {
convertDataviewQueries,
convertLinkCitation,
convertWikilinks
convertWikilinks,
addHardLineBreak
} from "../utils/convertText";

import {
Expand Down Expand Up @@ -106,6 +107,7 @@ export default class MkdocsPublish {
const embedFiles = shareFiles.getEmbed(file);
const linkedFiles = shareFiles.getLinkedImageAndFiles(file);
text = await convertDataviewQueries(text, file.path);
text = addHardLineBreak(text, settings);
text = convertLinkCitation(text, this.settings, linkedFiles, this.metadataCache, file, this.vault);
text = convertWikilinks(text, this.settings, linkedFiles);
const path = getReceiptFolder(file, this.settings, this.metadataCache, this.vault)
Expand Down
5 changes: 4 additions & 1 deletion plugin/i18n/locales/en-us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export default {
frontmatterKeyPlaceholder: "category",
rootFolder: "Root folder",
rootFolderDesc: "Append this path to the folder set by the frontmatter key.",
linksConversion: "Link's conversion",
textConversion: "Text conversion",
linksConversion: "Links",
folderNote: "Folder note",
folderNoteDesc: "Rename files with the same name as their parent folder (or category) \"index.md\"",
internalsLinks: "Internals Links",
Expand Down Expand Up @@ -71,6 +72,8 @@ export default {
baselinkDesc: "Create the clipboard link with this base. By default : https://username.github.io/repo/",
linkpathremover: "Remove link part",
linkpathremoverDesc: "Remove this part from the created links. Separate by comma if multiple value must be removed.",
hardBreakTitle: "Markdown hard line break",
hardBreakDesc: "Add a markdown hard line break (double whitespace) after each line. It will also convert '\\' to newline ('\n').",

//notice
unablePublishNote: (fileInfo: string): string => `Unable to publish note ${fileInfo},skipping it`,
Expand Down
5 changes: 4 additions & 1 deletion plugin/i18n/locales/fr-fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export default {
frontmatterKeyPlaceholder: "catégorie",
rootFolder: "Dossier racine",
rootFolderDesc: "Ajoutez ce chemin au dossier défini par la clé de métadonnées.",
linksConversion: "Conversion des liens",
textConversion: "Convertion du texte",
linksConversion: "Liens",
folderNote: "Note de dossier",
folderNoteDesc: "Renommer les fichiers portant le même nom que leur dossier (ou catégorie) parent \"index.md\".",
internalsLinks: "Liens internes",
Expand Down Expand Up @@ -70,6 +71,8 @@ export default {
baselinkDesc: "Créer le lien du presse-papiers avec cette base. Par défaut : https://username.github.io/repo/",
linkpathremover: "Retirer une partie du lien",
linkpathremoverDesc: "Supprimer cette partie des liens créés. Séparer par une virgule si plusieurs valeurs doivent être supprimées.",
hardBreakTitle: "Saut de ligne strict",
hardBreakDesc: "Ajoutez un retour à la ligne Markdown (double espace) après chaque ligne. Il convertit également '\\' en nouvelle ligne ('\n').",
//notice
unablePublishNote: (fileInfo: string): string => `Impossible de publier la note ${fileInfo}, ignorée.`,
errorPublish: (repoInfo: string): string => `Erreur lors de la publication sur ${repoInfo}.`,
Expand Down
3 changes: 3 additions & 0 deletions plugin/i18n/locales/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default {
frontmatterKeyPlaceholder: "category",
rootFolder: "根文件夹",
rootFolderDesc: "将此路径追加到文件夹前",
textConversion: "Text conversion",
linksConversion: "链接转换",
folderNote: "Folder note",
folderNoteDesc: "重命名文件为其父文件夹名(或category名) \"index.md\"",
Expand Down Expand Up @@ -71,6 +72,8 @@ export default {
baselinkDesc: "以此为基础创建剪贴板链接。默认情况下 : https://username.github.io/repo/",
linkpathremover: "删除链接部分",
linkpathremoverDesc: "从创建的链接中删除这部分。如果必须删除多个值,请用逗号分开。",
hardBreakTitle: "Markdown hard line break",
hardBreakDesc: "Add a markdown hard line break (double whitespace) after each line. It will also convert '\\' to newline ('\n').",
//notice
unablePublishNote: (fileInfo: string): string => { return `不能上传文件${fileInfo},已跳过` },
errorPublish: (repoInfo: string): string => `上传至${repoInfo}错误!`,
Expand Down
41 changes: 37 additions & 4 deletions plugin/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export class MkdocsSettingsTab extends PluginSettingTab {
display(): void {
const {containerEl} = this
containerEl.empty();

/* ------------------------ *
* Github configuration *
* ------------------------- */

containerEl.createEl('h1', {text: t('githubConfiguration') as string})
new Setting(containerEl)
.setName(t('repoName') as string)
Expand Down Expand Up @@ -67,9 +72,9 @@ export class MkdocsSettingsTab extends PluginSettingTab {
})
)

/* ------------------------------
* Github Workflow & upload
* ------------------------------ */
/* ------------------------------- *
* Github Workflow & upload *
* ------------------------------- */

containerEl.createEl('h2', {text: t('uploadConfig') as string})

Expand Down Expand Up @@ -157,8 +162,28 @@ export class MkdocsSettingsTab extends PluginSettingTab {
await this.plugin.saveSettings();
});
});
/*
* ----------------------------- *
* Texts conversion *
* ---------------------------- *
*/

containerEl.createEl('h3', {text: t('linksConversion') as string})
containerEl.createEl('h3', {text: t('textConversion') as string})

new Setting(this.containerEl)
.setName(t('hardBreakTitle') as string)
.setDesc(t('hardBreakDesc') as string)
.addToggle((toggle) => {
toggle
.setValue(this.plugin.settings.hardBreak)
.onChange(async (value) => {
this.plugin.settings.hardBreak = value;
await this.plugin.saveSettings();
});
}
)

containerEl.createEl('h4', {text: t('linksConversion') as string})

const folderNoteSettings = new Setting(containerEl)
.setName(t('folderNote') as string)
Expand Down Expand Up @@ -196,7 +221,15 @@ export class MkdocsSettingsTab extends PluginSettingTab {
})
})

/*
* ----------------------------- *
* Embed *
* ---------------------------- *
*/

containerEl.createEl('h3', {text: t('embed') as string})


new Setting(containerEl)
.setName(t('transferImage') as string)
.setDesc(t('transferImageDesc') as string)
Expand Down
5 changes: 3 additions & 2 deletions plugin/settings/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface MkdocsPublicationSettings {
copyLink: boolean;
mainLink: string;
linkRemover: string;
hardBreak: boolean;
}

export enum folderSettings {
Expand Down Expand Up @@ -58,6 +59,6 @@ export const DEFAULT_SETTINGS: MkdocsPublicationSettings = {
embedNotes: false,
copyLink: false,
mainLink:'',
linkRemover:''

linkRemover: '',
hardBreak: false,
}
10 changes: 9 additions & 1 deletion plugin/utils/convertText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import {MetadataCache, TFile, Notice, Vault} from "obsidian";
import {createRelativePath} from "./filePathConvertor";
import { getAPI } from "obsidian-dataview";

function addHardLineBreak(text: string, settings: MkdocsPublicationSettings) {
text = text.replace(/^\s\\\s*$/gmi, '<br/>');
if (settings.hardBreak) {
text = text.replace(/\n/gm, ' \n');
}
return text;
}

async function convertDataviewQueries(text: string, path: string): Promise<string> {
/* Credit : Ole Eskild Steensen from Obsidian Digital Garden */
let replacedText = text;
Expand Down Expand Up @@ -96,4 +104,4 @@ function creatorAltLink(altMatch: RegExpMatchArray, altCreator: string[], fileEx
}


export {convertWikilinks, convertLinkCitation, creatorAltLink, convertDataviewQueries};
export {convertWikilinks, convertLinkCitation, creatorAltLink, convertDataviewQueries, addHardLineBreak};

0 comments on commit 398f02c

Please sign in to comment.