generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 16
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
0 parents
commit 09ce655
Showing
11 changed files
with
471 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Intellij | ||
*.iml | ||
.idea | ||
|
||
# npm | ||
node_modules | ||
package-lock.json | ||
|
||
# build | ||
main.js | ||
*.js.map |
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,38 @@ | ||
# Obsidian ABC.JS plugin | ||
|
||
This plugin renders music sheets from code blocks using the `abc` language. Under the hood it uses [abc.js](https://paulrosen.github.io/abcjs/) and supports everything the library does. | ||
|
||
## Examples | ||
|
||
### Simple song | ||
|
||
```abc | ||
X:1 | ||
T:The Legacy Jig | ||
M:6/8 | ||
L:1/8 | ||
R:jig | ||
K:G | ||
GFG BAB | gfg gab | GFG BAB | d2A AFD | | ||
GFG BAB | gfg gab | age edB |1 dBA AFD :|2 dBA ABd |: | ||
efe edB | dBA ABd | efe edB | gdB ABd | | ||
efe edB | d2d def | gfe edB |1 dBA ABd :|2 dBA AFD |] | ||
``` | ||
|
||
### Chorus music | ||
|
||
```abc | ||
X: 1 | ||
T: Chorus | ||
V: T1 clef=treble name="Soprano" | ||
V: T2 clef=treble name="Alto" | ||
V: B1 clef=bass name="Tenor" | ||
V: B2 clef=bass name="Bass" | ||
L:1/8 | ||
K:G | ||
P:First Part | ||
[V: T1]"C"ed"Am"ed "F"cd"G7"gf | | ||
[V: T2]GGAA- A2BB | | ||
[V: B1]C3D- DF,3 | | ||
[V: B2]C,2A,,2 F,,2G,,2 | | ||
``` |
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,33 @@ | ||
import { App, MarkdownPostProcessor, MarkdownPostProcessorContext, MarkdownPreviewRenderer, MarkdownRenderer, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian'; | ||
import { signature, renderAbc } from 'abcjs'; | ||
|
||
export default class MusicPlugin extends Plugin { | ||
static postprocessor: MarkdownPostProcessor = (el: HTMLElement, ctx: MarkdownPostProcessorContext) => { | ||
// Assumption: One section always contains only the code block | ||
|
||
const blockToReplace = el.querySelector('pre') | ||
if (!blockToReplace) return | ||
|
||
const musicBlock = blockToReplace.querySelector('code.language-abc') | ||
if (!musicBlock) return | ||
|
||
const source = musicBlock.textContent | ||
const destination = document.createElement('div') | ||
renderAbc(destination, source, { | ||
add_classes: true, | ||
responsive: 'resize' | ||
}) | ||
|
||
el.replaceChild(destination, blockToReplace) | ||
} | ||
|
||
onload() { | ||
console.log('loading abcjs plugin'); | ||
MarkdownPreviewRenderer.registerPostProcessor(MusicPlugin.postprocessor) | ||
} | ||
|
||
onunload() { | ||
console.log('unloading abcjs plugin'); | ||
MarkdownPreviewRenderer.unregisterPostProcessor(MusicPlugin.postprocessor) | ||
} | ||
} |
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,10 @@ | ||
{ | ||
"id": "obsidian-plugin-abcjs", | ||
"name": "Music notation", | ||
"version": "1.0.0", | ||
"minAppVersion": "0.9.15", | ||
"description": "Plugin which renders music notation from code blocks. Uses the `abc` language.", | ||
"author": "Til Blechschmidt", | ||
"authorUrl": "https://github.com/TilBlechschmidt/obsidian-plugin-abcjs", | ||
"isDesktopOnly": false | ||
} |
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,26 @@ | ||
{ | ||
"name": "obsidian-sample-plugin", | ||
"version": "0.9.7", | ||
"description": "Plugin which renders music notation from code blocks. Uses the `abc` language.", | ||
"main": "main.js", | ||
"scripts": { | ||
"dev": "rollup --config rollup.config.js -w", | ||
"build": "rollup --config rollup.config.js" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^15.1.0", | ||
"@rollup/plugin-node-resolve": "^9.0.0", | ||
"@rollup/plugin-typescript": "^6.0.0", | ||
"@types/node": "^14.14.2", | ||
"obsidian": "https://github.com/obsidianmd/obsidian-api/tarball/master", | ||
"rollup": "^2.32.1", | ||
"tslib": "^2.0.3", | ||
"typescript": "^4.0.3" | ||
}, | ||
"dependencies": { | ||
"abcjs": "^5.12.0" | ||
} | ||
} |
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,19 @@ | ||
import typescript from '@rollup/plugin-typescript'; | ||
import {nodeResolve} from '@rollup/plugin-node-resolve'; | ||
import commonjs from '@rollup/plugin-commonjs'; | ||
|
||
export default { | ||
input: 'main.ts', | ||
output: { | ||
dir: '.', | ||
sourcemap: 'inline', | ||
format: 'cjs', | ||
exports: 'default' | ||
}, | ||
external: ['obsidian'], | ||
plugins: [ | ||
typescript(), | ||
nodeResolve({browser: true}), | ||
commonjs(), | ||
] | ||
}; |
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 @@ | ||
/* Nothing to do here really, default abcjs styles look good */ |
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,26 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"inlineSourceMap": true, | ||
"inlineSources": true, | ||
"module": "ESNext", | ||
"target": "es5", | ||
"allowJs": true, | ||
"noImplicitAny": true, | ||
"moduleResolution": "node", | ||
"importHelpers": true, | ||
"lib": [ | ||
"dom", | ||
"es5", | ||
"scripthost", | ||
"es2015" | ||
], | ||
"typeRoots": [ | ||
"node_modules/@types", | ||
"typeDefs" | ||
] | ||
}, | ||
"include": [ | ||
"**/*.ts" | ||
] | ||
} |
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,10 @@ | ||
type Params = { | ||
add_classes: boolean, | ||
responsive: 'resize' | undefined | ||
} | ||
|
||
declare module 'abcjs' { | ||
const signature: string | ||
|
||
const renderAbc: (output: HTMLElement, abc: string, parameters: Params) => void | ||
} |
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,3 @@ | ||
{ | ||
"1.0.0": "0.9.15" | ||
} |
Oops, something went wrong.