import { editor, markdown } from "$sb/silverbullet-syscall/mod.ts";
export async function parsePageCommand() {
console.log(
"AST",
JSON.stringify(
await markdown.parseMarkdown(await editor.getText()),
null,
2,
),
);
}
export async function showLogsCommand() {
await editor.showPanel(
"bhs",
1,
`
Loading...
Loading...
`,
`
const clientDiv = document.getElementById("client-log");
clientDiv.scrollTop = clientDiv.scrollHeight;
const serverDiv = document.getElementById("server-log");
serverDiv.scrollTop = serverDiv.scrollHeight;
self.close = () => {
sendEvent("log:hide");
};
syscall("system.getEnv").then((env) => {
const clientServerMode = !!env;
if (!clientServerMode) {
// Running in hybrid mode (mobile), so let's ignore server logs (they're the same as client logs)
serverDiv.style.display = "none";
clientDiv.style.width = "100%";
document.getElementById("server-log-header").style.display = "none";
}
setInterval(() => {
Promise.resolve().then(async () => {
if(clientServerMode) {
const serverLogs = await syscall("sandbox.getServerLogs");
serverDiv.innerHTML = "" + serverLogs.map((le) => "[" + le.level + "] " + le.message).join("\\n") + "
";
}
const clientLogs = await syscall("sandbox.getLogs");
clientDiv.innerHTML = "" + clientLogs.map((le) => "[" + le.level + "] " + le.message).join("\\n") + "
";
}).catch(console.error);
}, 1000);
});
`,
);
}
export async function hideBhsCommand() {
await editor.hidePanel("bhs");
}