The need for this came up during some space-lua shenanigans:
Command Lua: Toggle space-lua on Page
Turns all space-lua codeblocks on any page (current by default) on and off.
needs a
System: Reload
to be effective
Usage
On this page: {[Lua: Toggle space-lua on Page]}
On another page: {[Lua: Toggle space-lua on Page|Toggle space-lua on warpcore]("engineering/warpcore")}
```space-lua
command.define{
name = "Lua: Toggle space-lua on Page",
requireMode = "rw",
run = function(arg)
local my_path = arg[1] or _CTX.currentPage.name
editor.flashNotification("Lua: Toggle space-lua on Page "..my_path)
local my_page = space.readPage(my_path) or ""
local count, action
if string.find(my_page,"```space-lua-DISABLED\n") then
my_page, count = string.gsub(my_page,"```space-lua-DISABLED%s*\n","```space-lua\n")
action = "☑️ Enabled "
else
my_page, count = string.gsub(my_page,"```space-lua%s*\n","```space-lua-DISABLED\n")
action = "❌ Disabled "
end
if count==0 then
editor.flashNotification("❔ Nothing to do: Found no space-lua codeblocks on "..my_path)
else
editor.flashNotification(action..count.." space-lua codeblocks on "..my_path)
end
if my_path == _CTX.currentPage.name then
editor.setText(my_page)
else
space.writePage(my_path,my_page)
end
codeWidget.refreshAll()
end
}
```