added escape sequences for special chars

master
Michael Ochmann 2 years ago
parent d74650e32e
commit f29069c3d6
  1. 3
      contextAPI.js
  2. 10837
      package-lock.json
  3. 10
      src/WindowManager.js
  4. 2
      src/ui/src/assets/css/_slide.scss
  5. 20
      src/ui/src/components/SlideItem.js

@ -26,7 +26,8 @@ contextBridge.exposeInMainWorld("api", {
clearCache : () => webFrame.clearCache(), clearCache : () => webFrame.clearCache(),
appVersion : async () => await ipcRenderer.invoke("Ation::appVersion"), appVersion : async () => await ipcRenderer.invoke("Ation::appVersion"),
fonts : async () => await ipcRenderer.invoke("FontManager::fonts"), fonts : async () => await ipcRenderer.invoke("FontManager::fonts"),
resize : size => ipcRenderer.invoke("WindowManager::resize", size) resize : size => ipcRenderer.invoke("WindowManager::resize", size),
fullscreen : fullscreen => ipcRenderer.invoke("WindowManager::presentFullscreen", fullscreen)
}); });
contextBridge.exposeInMainWorld("appSettings", { contextBridge.exposeInMainWorld("appSettings", {

10837
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -2,7 +2,6 @@
const {app, BrowserWindow, ipcMain, globalShortcut} = require("electron"); const {app, BrowserWindow, ipcMain, globalShortcut} = require("electron");
const path = require("path"); const path = require("path");
const util = require("util");
const {isDevelopment} = require("./Util"); const {isDevelopment} = require("./Util");
@ -20,6 +19,7 @@ class WindowManager {
ipcMain.on("WindowManager::openFileDialog", () => this.app.openFile()); ipcMain.on("WindowManager::openFileDialog", () => this.app.openFile());
ipcMain.on("WindowManager::openFile", (_, path) => this.app.openFile(path)); ipcMain.on("WindowManager::openFile", (_, path) => this.app.openFile(path));
ipcMain.handle("WindowManager::resize", (_, height) => this.windows.settings.setSize(800, height + (process.platform === "win32" ? 50 : 0), true)); ipcMain.handle("WindowManager::resize", (_, height) => this.windows.settings.setSize(800, height + (process.platform === "win32" ? 50 : 0), true));
ipcMain.handle("WindowManager::presentFullscreen", (_, fullscreen) => this.windows.main.setFullScreen(fullscreen));
} }
init() { init() {
@ -40,13 +40,6 @@ class WindowManager {
if (["win32", "linux"].includes(process.platform)) { if (["win32", "linux"].includes(process.platform)) {
this.windows.settings.removeMenu(); this.windows.settings.removeMenu();
// we also need to hide the application menu
this.mainWindow.on("enter-full-screen", () => {
this.mainWindow.setAutoHideMenuBar(true);
});
this.mainWindow.on("leave-full-screen", () => {
this.mainWindow.setAutoHideMenuBar(false);
});
} }
this.windows.settings.on("close", event => { this.windows.settings.on("close", event => {
@ -81,6 +74,7 @@ class WindowManager {
show : false, show : false,
devTools : isDevelopment(), devTools : isDevelopment(),
titleBarStyle : "hiddenInset", titleBarStyle : "hiddenInset",
autoHideMenuBar : process.platform === "win32",
webPreferences : { webPreferences : {
contextIsolation : true, contextIsolation : true,
preload : path.join(__dirname, "..", "contextAPI.js") preload : path.join(__dirname, "..", "contextAPI.js")

@ -122,7 +122,7 @@
} }
pre { pre {
font-size: 0.3em; //font-size: 0.3em;
width: 90%; width: 90%;
padding: 1em !important; padding: 1em !important;

@ -5,6 +5,14 @@ import {monokai} from "react-syntax-highlighter/dist/esm/styles/hljs";
import SlideContext from "../shared/SlideContext"; import SlideContext from "../shared/SlideContext";
const EscapeSequences = {
""" : '"',
"&lt;" : "<",
"&gt;" : ">",
"&amp;" : "&"
};
const EscapeSequencesRegex = new RegExp(Object.keys(EscapeSequences).join('|'), "g");
const Children = ({items}) => { const Children = ({items}) => {
if (items instanceof Array) if (items instanceof Array)
return <>{items.map((child, index) => <SlideItem item={child} key={index} />)}</>; return <>{items.map((child, index) => <SlideItem item={child} key={index} />)}</>;
@ -14,8 +22,14 @@ const Children = ({items}) => {
const SlideItem = ({item}) => { const SlideItem = ({item}) => {
const {basePath} = useContext(SlideContext); const {basePath} = useContext(SlideContext);
const processEscapeSequences = text => {
return text.replace(EscapeSequencesRegex, match => EscapeSequences[match]);
};
const content = useMemo(() => { const content = useMemo(() => {
if (item.type === "paragraph")
console.log(item.type, item);
switch (item.type) { switch (item.type) {
case "heading": case "heading":
const level = item.level || item.depth; const level = item.level || item.depth;
@ -66,17 +80,19 @@ const SlideItem = ({item}) => {
return <span dangerouslySetInnerHTML={{__html : item.raw}}></span> return <span dangerouslySetInnerHTML={{__html : item.raw}}></span>
case "link": case "link":
case "text": case "text":
return <>{item.tokens ? <Children items={item.tokens} /> : item.text}</> return <>{item.tokens ? <Children items={item.tokens} /> : processEscapeSequences(item.text)}</>
case "escape": case "escape":
switch(item.text) { switch(item.text) {
case "&lt;": case "&lt;":
return '<'; return '<';
case "&gt;": case "&gt;":
return '>'; return '>';
case '"':
case "&quot;":
return '"';
default: default:
return ""; return "";
} }
break;
default: default:
return "UNKNOWN ITEM" + JSON.stringify(item); return "UNKNOWN ITEM" + JSON.stringify(item);
} }

Loading…
Cancel
Save