This repository has been archived by the owner on Oct 30, 2023. It is now read-only.
generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite plugin and properly deregister views.
- Loading branch information
1 parent
f133d68
commit 097df38
Showing
8 changed files
with
260 additions
and
179 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,19 +1,44 @@ | ||
# Plaintext for Obsidian | ||
|
||
Obisidan (https://obsidian.md) plugin that allows it to open files as plaintext. | ||
Developed for Obsidian version 0.12.12. It might work with older versions, but it is not tested. | ||
This is an [Obisidan](https://obsidian.md) plugin that allows you to open _any_ file as plaintext. It has been developed for Obsidian **v0.13.14**, and tested on **Windows**. | ||
|
||
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. | ||
Honestly, as long as you can run any Obsidian version you can _probably_ run this plugin as well. The only requirements are that we can register extensions (this existed in v0.12.12 for instance), and that the `viewRegistry` exists, which I'm assuming has been there since the beginning of Obsidian. But, this is all speculation! | ||
|
||
**NOTE: There are other plugins that allow you to edit specific files. MAKE SURE TO NOT TYPE THEIR EXTENSIONS INTO THE SETTINGS FIELD FOR THIS PLUGIN. I cannot (yet) check for specific plugins that have their own view for a particular extension, and as such this plugin WILL overwrite the view, and break the other extension. If you do this by accident, open the plugin folder (`.obsidian/plugins/obsidian-plaintext/`), and remove from the `data.json` file the extensions that you typed by mistake.** | ||
|
||
## Installing | ||
|
||
Interested in editing files in Obsidian? Great. Grab the latest release from the [releases](#) page, and copy `main.js` and `manifest.json` to `.obsidian/plugins/obsidian-plaintext/`. That's it! | ||
|
||
When approved, you can also install this through Obsidian by searching for **plaintext**. | ||
|
||
## Roadmap | ||
|
||
For now, nothing is planned. If you're interested in features, please make an issue on Github! | ||
|
||
## Contributing | ||
|
||
Also excited about making Obsidian a full-fledged IDE? Cool, me too! Contact me and let's talk! Pull requests (especially one that updates the code to use `CodeMirror 6`) are very welcome. | ||
|
||
## Pricing | ||
|
||
This is free. Keep your money, I don't want it. | ||
|
||
## Changelog | ||
|
||
**Version 0.0.2 (current)**: | ||
* First actual release. | ||
* Code is functional! You can open and edit files as plaintext. | ||
**Version 0.1.0 (current)**: | ||
|
||
- Complete rewrite of registering and deregistering. | ||
- Now _actually_ removes views when deregistering a particular extension. | ||
- Correctly filters out default obsidian extensions: No more accidentally overwriting the default markdown editor. | ||
|
||
**Version 0.0.2**: | ||
|
||
- First actual release. | ||
- Code is functional! You can open and edit files as plaintext. | ||
|
||
**Version 0.0.1**: | ||
|
||
**Version 0.0.1**: | ||
* Not a release. | ||
* Initial testing code. | ||
* This included the functionality for parsing user-inputted extensions. | ||
- 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 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,24 +1,52 @@ | ||
// 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[] = [ | ||
/** | ||
* Extensions obsidian supports natively. | ||
* Taken from the help page: https://help.obsidian.md/Advanced+topics/Accepted+file+formats | ||
* | ||
* @version 0.1.0 | ||
* @author dbarenholz | ||
* @since 2021/12/26 | ||
*/ | ||
export const obsidianExts: Set<string> = new Set([ | ||
"md", | ||
" png", | ||
" jpg", | ||
" jpeg", | ||
" gif", | ||
" bmp", | ||
" svg", | ||
" mp3", | ||
" webm", | ||
" wav", | ||
" m4a", | ||
" ogg", | ||
" 3gp", | ||
" flac", | ||
" mp4", | ||
" webm", | ||
" ogv", | ||
" pdf", | ||
]; | ||
"png", | ||
"jpg", | ||
"jpeg", | ||
"gif", | ||
"bmp", | ||
"svg", | ||
"mp3", | ||
"webm", | ||
"wav", | ||
"m4a", | ||
"ogg", | ||
"3gp", | ||
"flac", | ||
"mp4", | ||
"webm", | ||
"ogv", | ||
"pdf", | ||
]); | ||
|
||
/** | ||
* Takes in a list of extensions, and removes extensions if they are present in the obsidianExts set. | ||
* | ||
* @param exts extensions to process | ||
* @returns All extensions in exts, except if they're present in obsidianExts. | ||
*/ | ||
export const removeObsidianExtensions = (exts: string[]): string[] => { | ||
return exts.filter(ext => !obsidianExts.has(ext)); | ||
} | ||
|
||
declare module 'obsidian' { | ||
interface App { | ||
viewRegistry: { | ||
unregisterView: CallableFunction // ƒ (e){delete this.viewByType[e]} | ||
unregisterExtensions: CallableFunction // ƒ (e){for(var t=0,n=e;t<n.length;t++){var i=n[t];delete this.typeByExtension[i]}this.trigger("extensions-updated")} | ||
} | ||
} | ||
interface View { | ||
file: { | ||
extension: string | ||
} | ||
} | ||
} |
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.