forked from dbarenholz/obsidian-plaintext
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5fbf3a9
commit f133d68
Showing
11 changed files
with
227 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,19 @@ | ||
## Plaintext for Obsidian | ||
# Plaintext for Obsidian | ||
|
||
Obisidan (https://obsidian.md) plugin that allows it to open files as plaintext. | ||
Developed for Obsidian v0.12.12, might work with older versions, but not tested. | ||
Developed for Obsidian version 0.12.12. It might work with older versions, but it is not tested. | ||
|
||
Code is really ugly, and a complete work in progress. Do not expect this to be functional. | ||
Code is functional! You can actually edit plaintext files now. There's no fancy syntax highlighting, since the file | ||
is interpreted as plaintext, as opposed to some other type of text. | ||
|
||
All text below is left-over from the sample repository for now. | ||
## Changelog | ||
|
||
<hline> | ||
**Version 0.0.2 (current)**: | ||
* First actual release. | ||
* Code is functional! You can open and edit files as plaintext. | ||
|
||
### Releasing new releases | ||
|
||
- Update your `manifest.json` with your new version number, such as `1.0.1`, and the minimum Obsidian version required for your latest release. | ||
- Update your `versions.json` file with `"new-plugin-version": "minimum-obsidian-version"` so older versions of Obsidian can download an older version of your plugin that's compatible. | ||
- Create new GitHub release using your new version number as the "Tag version". Use the exact version number, don't include a prefix `v`. See here for an example: https://github.com/obsidianmd/obsidian-sample-plugin/releases | ||
- Upload the files `manifest.json`, `main.js`, `styles.css` as binary attachments. | ||
- Publish the release. | ||
|
||
### Adding your plugin to the community plugin list | ||
|
||
- Publish an initial version. | ||
- Make sure you have a `README.md` file in the root of your repo. | ||
- Make a pull request at https://github.com/obsidianmd/obsidian-releases to add your plugin. | ||
|
||
### Manually installing the plugin | ||
|
||
- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`. | ||
|
||
### API Documentation | ||
|
||
See https://github.com/obsidianmd/obsidian-api | ||
**Version 0.0.1**: | ||
* Not a release. | ||
* Initial testing code. | ||
* This included the functionality for parsing user-inputted extensions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Taken directly from here | ||
// https://help.obsidian.md/Advanced+topics/Accepted+file+formats | ||
// On sept 2, 2021. May need updates later. | ||
|
||
export const obsidianExts: string[] = [ | ||
"md", | ||
" png", | ||
" jpg", | ||
" jpeg", | ||
" gif", | ||
" bmp", | ||
" svg", | ||
" mp3", | ||
" webm", | ||
" wav", | ||
" m4a", | ||
" ogg", | ||
" 3gp", | ||
" flac", | ||
" mp4", | ||
" webm", | ||
" ogv", | ||
" pdf", | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,105 @@ | ||
// TODO: Do I need a custom view type? | ||
// import { VIEW_TYPE_PLAINTEXT } from "constants"; | ||
import { Plugin, WorkspaceLeaf } from "obsidian"; | ||
import { Plugin, WorkspaceLeaf, ViewCreator } from "obsidian"; | ||
import { obsidianExts } from "./helper"; | ||
import { PlaintextSettings, PlaintextSettingTab, DEFAULT_SETTINGS } from "./settings"; | ||
import PlaintextView from "./view"; | ||
|
||
/** | ||
* The plugin class, extends Obsidian Plugin. | ||
* Plaintext plugin. | ||
* | ||
* This plugin allows you to edit specified extensions as plaintext files. | ||
* It does NOT check if a file is binary or textual! | ||
* | ||
* @author dbarenholz | ||
* @version 0.1.0 | ||
*/ | ||
export default class PlaintextPlugin extends Plugin { | ||
public settings: PlaintextSettings; | ||
private view: PlaintextView; | ||
|
||
async onload() { | ||
/** | ||
* Code that runs (once) when plugin is loaded. | ||
*/ | ||
async onload(): Promise<void> { | ||
console.log("Obsidian Plaintext: loaded plugin."); | ||
|
||
// Load the settings | ||
await this.loadSettings(); | ||
|
||
// Add settings tab | ||
this.addSettingTab(new PlaintextSettingTab(this.app, this)); | ||
|
||
// Adds an item to the status bar (bottom row of the screen) | ||
// TODO: When editing a file in plaintext mode, add item stating "editing plaintext" | ||
// this.addStatusBarItem().setText("Plain Text"); | ||
|
||
// Stuff for editor | ||
// this.registerCodeMirror((cm: CodeMirror.Editor) => { | ||
// console.log("codemirror", cm); | ||
// }); | ||
|
||
// TODO: Do I need this? If so, how does it work? | ||
// this.registerView(VIEW_TYPE_PLAINTEXT, (leaf: WorkspaceLeaf) => (this.view = new PlaintextView(leaf))); | ||
|
||
// Relevant items have class: nav-file-title is-unsupported | ||
const items = document.getElementsByClassName("nav-file-title is-unsupported"); | ||
const numItems = items.length; | ||
for (let i = 0; i < numItems; i++) { | ||
const thing = items.item(i) as HTMLElement; | ||
this.registerDomEvent(thing, "click", (evt: MouseEvent) => { | ||
// TODO: Test if this prevents defaukt behaviour | ||
evt.stopImmediatePropagation(); | ||
// TODO: Open the actual file | ||
console.log("TODO: Open the file."); | ||
|
||
// TODO: Do I need a custom leaf type? | ||
this.app.workspace.createLeafBySplit(null, "vertical", false); | ||
}); | ||
} | ||
// Do the work | ||
this.processExts(this.settings.extensions); | ||
} | ||
|
||
onunload() { | ||
/** | ||
* Code that runs (once) when the plugin is unloaded. | ||
*/ | ||
onunload(): void { | ||
console.log("Obsidian Plaintext: unloaded plugin."); | ||
} | ||
|
||
async loadSettings() { | ||
/** | ||
* Loads the settings. | ||
*/ | ||
async loadSettings(): Promise<void> { | ||
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); | ||
} | ||
|
||
async saveSettings() { | ||
/** | ||
* Saves the settings. | ||
*/ | ||
async saveSettings(): Promise<void> { | ||
await this.saveData(this.settings); | ||
} | ||
|
||
/** | ||
* Creates a view for a plaintext file. | ||
* Plaintext views have <b>NO</b> syntax highlighting or other fancy features! | ||
* | ||
* @param leaf The leaf to create the view at | ||
* @param ext Plaintext extension | ||
* @returns Plaintext view | ||
*/ | ||
viewCreator: ViewCreator = (leaf: WorkspaceLeaf, ext?: string): PlaintextView => { | ||
return new PlaintextView(leaf, ext); | ||
}; | ||
|
||
/** | ||
* Processes the extensions. | ||
* | ||
* @param exts extensions | ||
*/ | ||
processExts = (exts: string[]): void => { | ||
if (exts.length == 0) { | ||
console.log("Plaintext: No extensions to process."); | ||
return; | ||
} | ||
|
||
for (const ext of exts) { | ||
// Disallow using obsidian defaults | ||
if (ext in obsidianExts) { | ||
if (this.settings.debug) { | ||
console.log(`Plaintext: Extension '${ext}' is used by Obsidian already! Don't override Obsidian.`); | ||
} | ||
} | ||
|
||
// Try to register view | ||
try { | ||
this.registerView(ext, this.viewCreator); | ||
} catch { | ||
if (this.settings.debug) { | ||
console.log(`Plaintext: Extension '${ext}' already has a view registered, ignoring...`); | ||
} | ||
} | ||
|
||
// Try to register extension | ||
try { | ||
this.registerExtensions([ext], ext); | ||
} catch { | ||
if (this.settings.debug) { | ||
console.log(`Plaintext: Extension '${ext}' is already registered, ignoring...`); | ||
} | ||
} | ||
} | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.