mirror of
https://github.com/meld-cp/obsidian-build.git
synced 2026-07-22 07:30:25 +00:00
toolbar
This commit is contained in:
parent
c7288f7c7e
commit
ff4383953c
3 changed files with 102 additions and 1716 deletions
0
docs/user-guide.md
Normal file
0
docs/user-guide.md
Normal file
87
main.ts
87
main.ts
|
|
@ -20,31 +20,78 @@ export default class MeldBuildPlugin extends Plugin {
|
|||
|
||||
this.registerHandlebarHelpers();
|
||||
|
||||
// try {
|
||||
// this.registerExtensions(['html'], 'meld-build-html-view');
|
||||
// } catch (error) {
|
||||
// new Notice(error);
|
||||
// //await showError(`File extensions ${HTML_FILE_EXTENSIONS} had been registered by other plugin!`);
|
||||
// }
|
||||
// this.registerMarkdownPostProcessor((element, context) => {
|
||||
// const toolbarElements = element.querySelectorAll('code.language-meld-build-toolbar');
|
||||
// toolbarElements.forEach(el => {
|
||||
// context.addChild()
|
||||
// });
|
||||
// });
|
||||
|
||||
this.addCommand({
|
||||
id: 'meld-build-run',
|
||||
name: 'Run',
|
||||
editorCallback: async (editor: Editor, view: MarkdownView) => {
|
||||
const logger = new RunLogger();
|
||||
try{
|
||||
//await view.save();
|
||||
const compiler = new Compiler();
|
||||
const runner = compiler.compile(logger, editor, view);
|
||||
runner();
|
||||
}catch(e){
|
||||
logger.error(e);
|
||||
new Notice(e);
|
||||
this.registerMarkdownCodeBlockProcessor('meld-build-toolbar', (source, el, ctx) => {
|
||||
const lines = source.split('\n');
|
||||
const valueMap = new Map<string,string>();
|
||||
lines.forEach(line => {
|
||||
const pair = line.split('=');
|
||||
if(pair.length == 2){
|
||||
valueMap.set(pair[0].trim(), pair[1].trim());
|
||||
}
|
||||
});
|
||||
|
||||
const runButtonLabel = valueMap.get('run');
|
||||
const showRunButton = runButtonLabel !== '';
|
||||
|
||||
const helpButtonLabel = valueMap.get('help');
|
||||
const showHelpButton = helpButtonLabel !== '';
|
||||
|
||||
let buttonCount = 0;
|
||||
if (showRunButton){
|
||||
buttonCount++;
|
||||
el.createEl('button', { text: runButtonLabel ?? 'Run'}, el =>{
|
||||
el.on('click', '*', ev=>{
|
||||
const view = app.workspace.getActiveViewOfType( MarkdownView );
|
||||
if (!view){
|
||||
return;
|
||||
}
|
||||
this.buildAndRun(view.editor, view);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (showHelpButton){
|
||||
if ( buttonCount > 0 ){
|
||||
el.createSpan('', el=>{ el.style.marginLeft = '1em'; });
|
||||
}
|
||||
buttonCount++;
|
||||
el.createEl('button', {text: helpButtonLabel ?? '❔', title: 'Help' }, el=>{
|
||||
el.on('click', '*', async ev=>{
|
||||
window.open('https://github.com/meld-cp/obsidian-build/docs/user-guide.md');
|
||||
});
|
||||
} );
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
this.addCommand({
|
||||
id: 'run',
|
||||
name: 'Run',
|
||||
editorCallback: this.buildAndRun
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
private buildAndRun( editor:Editor, view: MarkdownView ){
|
||||
const logger = new RunLogger();
|
||||
try{
|
||||
//await view.save();
|
||||
const compiler = new Compiler();
|
||||
const runner = compiler.compile(logger, editor, view);
|
||||
runner();
|
||||
}catch(e){
|
||||
logger.error(e);
|
||||
new Notice(e);
|
||||
}
|
||||
}
|
||||
|
||||
private registerHandlebarHelpers(){
|
||||
|
|
@ -92,4 +139,4 @@ export default class MeldBuildPlugin extends Plugin {
|
|||
async saveSettings() {
|
||||
await this.saveData(this.settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
1731
package-lock.json
generated
1731
package-lock.json
generated
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue