Fix README install path and add configurable thread settings
This commit is contained in:
@@ -39,7 +39,7 @@ The selected text is replaced in place.
|
||||
1. Build the plugin (see [Development](#development)) or download a release
|
||||
2. Copy `main.js` and `manifest.json` to your vault at:
|
||||
```
|
||||
<VaultFolder>/.obsidian/plugins/unicode-text-formatter/
|
||||
<VaultFolder>/.obsidian/plugins/obsidian-unicode-formatter/
|
||||
```
|
||||
3. In Obsidian: **Settings → Community Plugins → Installed Plugins** — enable **Unicode Text Formatter**
|
||||
|
||||
|
||||
+7
-4
@@ -1,9 +1,9 @@
|
||||
import { Plugin } from "obsidian";
|
||||
import type UnicodeFormatterPlugin from "./main";
|
||||
import { transformText, cleanText, bulletToEmdash, bulletToArrow, numberedListSlash, numberedListParens, markdownToLinkedIn, FormatStyle } from "./formatter";
|
||||
import { splitIntoThreads } from "./thread-splitter";
|
||||
import { ThreadModal } from "./thread-modal";
|
||||
|
||||
function addFormatCommand(plugin: Plugin, style: FormatStyle, name: string) {
|
||||
function addFormatCommand(plugin: UnicodeFormatterPlugin, style: FormatStyle, name: string) {
|
||||
plugin.addCommand({
|
||||
id: `unicode-formatter:${style}`,
|
||||
name,
|
||||
@@ -16,7 +16,7 @@ function addFormatCommand(plugin: Plugin, style: FormatStyle, name: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function registerCommands(plugin: Plugin): void {
|
||||
export function registerCommands(plugin: UnicodeFormatterPlugin): void {
|
||||
addFormatCommand(plugin, "bold", "Format as unicode bold");
|
||||
addFormatCommand(plugin, "italic", "Format as unicode italic");
|
||||
addFormatCommand(plugin, "bold-italic", "Format as unicode bold italic");
|
||||
@@ -86,7 +86,10 @@ export function registerCommands(plugin: Plugin): void {
|
||||
editorCallback: (editor) => {
|
||||
const selection = editor.getSelection();
|
||||
if (selection) {
|
||||
const tweets = splitIntoThreads(selection);
|
||||
const tweets = splitIntoThreads(selection, {
|
||||
maxChars: plugin.settings.threadMaxChars,
|
||||
addNumbering: plugin.settings.threadAddNumbering,
|
||||
});
|
||||
new ThreadModal(plugin.app, tweets).open();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import { Plugin } from 'obsidian';
|
||||
import { registerCommands } from './commands';
|
||||
import { UnicodeFormatterSettings, DEFAULT_SETTINGS, UnicodeFormatterSettingTab } from './settings';
|
||||
|
||||
export default class UnicodeFormatterPlugin extends Plugin {
|
||||
settings: UnicodeFormatterSettings;
|
||||
|
||||
async onload() {
|
||||
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()) as UnicodeFormatterSettings;
|
||||
this.addSettingTab(new UnicodeFormatterSettingTab(this.app, this));
|
||||
registerCommands(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import { App, PluginSettingTab, Setting } from "obsidian";
|
||||
import type UnicodeFormatterPlugin from "./main";
|
||||
|
||||
export interface UnicodeFormatterSettings {
|
||||
threadMaxChars: number;
|
||||
threadAddNumbering: boolean;
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: UnicodeFormatterSettings = {
|
||||
threadMaxChars: 280,
|
||||
threadAddNumbering: true,
|
||||
};
|
||||
|
||||
export class UnicodeFormatterSettingTab extends PluginSettingTab {
|
||||
plugin: UnicodeFormatterPlugin;
|
||||
|
||||
constructor(app: App, plugin: UnicodeFormatterPlugin) {
|
||||
super(app, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
display(): void {
|
||||
const { containerEl } = this;
|
||||
containerEl.empty();
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Thread character limit")
|
||||
.setDesc("Maximum characters per post.")
|
||||
.addText(text => text
|
||||
.setValue(String(this.plugin.settings.threadMaxChars))
|
||||
.onChange(async (value) => {
|
||||
const num = parseInt(value, 10);
|
||||
if (!isNaN(num) && num > 0) {
|
||||
this.plugin.settings.threadMaxChars = num;
|
||||
await this.plugin.saveData(this.plugin.settings);
|
||||
}
|
||||
}));
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Add post numbering")
|
||||
.setDesc("Prefix each post with numbering (e.g. 1/5) when splitting into a thread.")
|
||||
.addToggle(toggle => toggle
|
||||
.setValue(this.plugin.settings.threadAddNumbering)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.threadAddNumbering = value;
|
||||
await this.plugin.saveData(this.plugin.settings);
|
||||
}));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user