Generating documentation using factory

This commit is contained in:
2023-08-25 12:36:37 +02:00
parent 94acee819a
commit 58c0a2cf66
3 changed files with 407 additions and 370 deletions

View File

@ -14,10 +14,10 @@ import { indentWithTab } from "@codemirror/commands";
import { vim } from "@replit/codemirror-vim";
import { AppSettings, Universe } from "./AppSettings";
import { editorSetup } from "./EditorSetup";
import { documentation } from "./Documentation";
import { documentation_factory } from "./Documentation";
import { EditorView } from "codemirror";
import { Clock } from "./Clock";
import { UserAPI } from "./API";
import { loadSamples, UserAPI } from "./API";
import "./style.css";
import {
Universes,
@ -27,9 +27,6 @@ import {
} from "./AppSettings";
import { tryEvaluate } from "./Evaluator";
type Documentation = { [key: string]: string };
const Docs: Documentation = documentation;
// Importing showdown and setting up the markdown converter
import showdown from "showdown";
showdown.setFlavor("github");
@ -78,6 +75,7 @@ export class Editor {
userPlugins: Extension[] = [];
state: EditorState;
api: UserAPI;
docs: { [key: string]: string } = {};
// Audio stuff
audioContext: AudioContext;
@ -236,6 +234,13 @@ export class Editor {
let dynamicPlugins = new Compartment();
// ================================================================================
// Building the documentation
loadSamples().then(() => {
this.docs = documentation_factory(this);
});
// ================================================================================
// ================================================================================
// Application event listeners
// ================================================================================
@ -662,10 +667,11 @@ export class Editor {
const converter = new showdown.Converter({
emoji: true,
moreStyling: true,
backslashEscapesHTMLTags: true,
extensions: [showdownHighlight({ auto_detection: true }), ...bindings],
});
const converted_markdown = converter.makeHtml(
Docs[this.currentDocumentationPane]
this.docs[this.currentDocumentationPane]
);
function wrapCodeWithPre(inputString: string): string {
let newString = inputString.replace(/<code>/g, "<pre><code>");