Skip to content

Commit

Permalink
add editor extension for loading markdown activities
Browse files Browse the repository at this point in the history
  • Loading branch information
riknoll committed Oct 22, 2024
1 parent 368fdf6 commit eaaa8a0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions localtypings/pxteditor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,7 @@ declare namespace pxt.editor {

// Used with the @tutorialCompleted macro. See docs/writing-docs/tutorials.md for more info
onTutorialCompleted?: () => void;
onMarkdownActivityLoad?: (path: string, title?: string, editorProjectName?: string) => Promise<void>;

// Used with @codeStart, @codeStop metadata (MINECRAFT HOC ONLY)
onCodeStart?: () => void;
Expand Down
1 change: 1 addition & 0 deletions pxtlib/cmds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ namespace pxt.commands {
export let webUsbPairDialogAsync: (pairAsync: () => Promise<boolean>, confirmAsync: (options: any) => Promise<WebUSBPairResult>, implicitlyCalled?: boolean) => Promise<WebUSBPairResult> = undefined;
export let onTutorialCompleted: () => void = undefined;
export let workspaceLoadedAsync: () => Promise<void> = undefined;
export let onMarkdownActivityLoad: (path: string, title?: string, editorProjectName?: string) => Promise<void> = undefined;
}
4 changes: 4 additions & 0 deletions webapp/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4688,6 +4688,10 @@ export class ProjectView

let markdown: string;

if (pxt.commands.onMarkdownActivityLoad) {
await pxt.commands.onMarkdownActivityLoad(path, title, editorProjectName);
}

try {
if (/^\//.test(path)) {
filename = title || path.split('/').reverse()[0].replace('-', ' '); // drop any kind of sub-paths
Expand Down
4 changes: 4 additions & 0 deletions webapp/src/cmds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ function applyExtensionResult() {
log(`extension showProgramTooLargeErrorAsync`);
pxt.commands.showProgramTooLargeErrorAsync = res.showProgramTooLargeErrorAsync;
}
if (res.onMarkdownActivityLoad) {
log(`extension onMarkdownActivityLoad`);
pxt.commands.onMarkdownActivityLoad = res.onMarkdownActivityLoad;
}
}

export async function initAsync() {
Expand Down

0 comments on commit eaaa8a0

Please sign in to comment.