Compare commits

...

3 Commits

Author SHA1 Message Date
Neale Pickett 7c5b5b5ccf Make all paths absolute
Fixes #200
2024-04-09 11:54:39 -06:00
Neale Pickett dfecd100b8 Syntax Highlighting is not (currently) optional 2024-04-09 11:52:47 -06:00
Neale Pickett 830eb2851a Color syntax highlighting
Fixes #202
2024-04-09 11:12:32 -06:00
5 changed files with 44 additions and 24 deletions

4
.gitignore vendored
View File

@ -5,6 +5,6 @@
__debug_bin
*.tar.gz
transpile
mothd
winmoth.*.zip
*.exe
/mothd
/*.exe

View File

@ -6,6 +6,7 @@ import (
"log"
"mime"
"os"
"path/filepath"
"time"
"github.com/spf13/afero"
@ -54,21 +55,38 @@ func main() {
)
flag.Parse()
var theme *Theme
osfs := afero.NewOsFs()
theme := NewTheme(afero.NewBasePathFs(osfs, *themePath))
if p, err := filepath.Abs(*themePath); err != nil {
log.Fatal(err)
} else {
theme = NewTheme(afero.NewBasePathFs(osfs, p))
}
config := Configuration{}
var provider PuzzleProvider
provider = NewMothballs(afero.NewBasePathFs(osfs, *mothballPath))
if p, err := filepath.Abs(*mothballPath); err != nil {
log.Fatal(err)
} else {
provider = NewMothballs(afero.NewBasePathFs(osfs, p))
}
if *puzzlePath != "" {
provider = NewTranspilerProvider(afero.NewBasePathFs(osfs, *puzzlePath))
if p, err := filepath.Abs(*puzzlePath); err != nil {
log.Fatal(err)
} else {
provider = NewTranspilerProvider(afero.NewBasePathFs(osfs, p))
}
config.Devel = true
log.Println("-=- You are in development mode, champ! -=-")
}
var state StateProvider
state = NewState(afero.NewBasePathFs(osfs, *statePath))
if p, err := filepath.Abs(*statePath); err != nil {
log.Fatal(err)
} else {
state = NewState(afero.NewBasePathFs(osfs, p))
}
if config.Devel {
state = NewDevelState(state)
}

View File

@ -5,7 +5,6 @@
"": 0
},
"Puzzle": {
"SyntaxHighlighting": true,
"": 0
},
"Scoreboard": {

View File

@ -1,4 +1,4 @@
const pyodidePromise = import("https://cdn.jsdelivr.net/npm/pyodide@0.25.1/pyodide.mjs")
import * as pyodide from "https://cdn.jsdelivr.net/npm/pyodide@0.25.1/pyodide.mjs" // v0.16.1 known good
const HOME = "/home/web_user"

View File

@ -1,21 +1,11 @@
import {Toast} from "../common.mjs"
import "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"
//import "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"
import "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-core.min.js"
import "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/autoloader/prism-autoloader.min.js"
import * as CodeJar from "https://cdn.jsdelivr.net/npm/codejar@4.2.0"
var workers = {}
// loadWorker returns an existing worker if one exists, otherwise, it starts a new worker
function loadWorker(language) {
let worker = workers[language]
if (!worker) {
let url = new URL(language + ".mjs", import.meta.url)
worker = new Worker(url, {
type: "module",
})
workers[language] = worker
}
return worker
}
Prism.plugins.autoloader.languages_path = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/"
const prismCssUrl = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism.min.css"
export class Workspace {
/**
@ -85,7 +75,7 @@ export class Workspace {
.then(() => {
codeBlock.parentElement.replaceWith(this.element)
})
.catch(err => console.warn(`Unable to load ${this.language} interpreter`))
.catch(err => console.warn(`Unable to load interpreter: `, this.language))
.finally(() => {
loadingElement.remove()
})
@ -232,3 +222,16 @@ export class Workspace {
this.element.classList.toggle("fixed")
}
}
function init() {
let link = document.head.appendChild(document.createElement("link"))
link.rel = "stylesheet"
link.href = prismCssUrl
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", init)
} else {
init()
}