CodePrez
@@ -22,6 +27,15 @@ export const SideBar = () => {' + ) + } else { + return ( + '' + + hljs.highlight(str, { + language: lang, + ignoreIllegals: true, + }).value + + '
play_arrow
' +
+ hljs.highlight(str, {
+ language: lang,
+ ignoreIllegals: true,
+ }).value +
+ "
"
+ );
+ }
+ } catch (__) {}
+ }
+
+ return (
+ '' +
+ md.utils.escapeHtml(str) +
+ "
"
+ );
+ },
+ }
+
+ const md = MarkdownIt(markdownOptions);
+
+ //Include images
+ md.renderer.rules.image = (tokens, idx, options, env, self) => imageRendererRules({tokens, idx, options, env, self, presentationPath});
+
+ //Include code via file
+ md.renderer.rules.link_open = (tokens, idx, options, env, self) => linkRendererRules({tokens, idx, options, env, self, presentationPath})
+
+ return md;
+}
+
+const imageRendererRules = ({tokens, idx, options, env, self, presentationPath}: RendererRulesArguments) => {
+ const token = tokens[idx];
+
+ const src = token.attrGet("src");
+
+ const regexForSrc = /\.\/assets/gm;
+
+ const srcWithPresentationPath = (src?.match(regexForSrc)) ? path.join("codeprez:/", presentationPath, src) : src
+ token.attrSet('src', srcWithPresentationPath || "")
+
+ return self.renderToken(tokens, idx, options)
+}
+
+const linkRendererRules = ({tokens, idx, options, env, self, presentationPath}: RendererRulesArguments) => {
+ const token = tokens[idx];
+
+ const href = token.attrGet("href")
+ const regexPathFile = /^\.\/(.+\.\w+)/gm;
+ const relativeCodeFilePath = href?.match(regexPathFile) ?? [];
+
+ if(relativeCodeFilePath.length) {
+ const codeFilePath = path.join(presentationPath, relativeCodeFilePath[0] ?? "")
+ return codeFileRendererRules({codeFilePath: codeFilePath, href});
+ } else {
+ return self.renderToken(tokens, idx, options);
+ }
+
+}
+
+const codeFileRendererRules = ({codeFilePath, href}: CodeFileRendererRulesArguments) => {
+
+ const regexLineNumber = /#(\d+)-(\d+)/;
+ const regexFileExtension = /\.(\w+)(?:#\d+-\d+)?$/;
+
+ const lineNumbers = href?.match(regexLineNumber) ?? [];
+ const startNumber = lineNumbers[1];
+ const endNumber = lineNumbers[2];
+
+ const fileExtension = href?.match(regexFileExtension) ?? [];
+
+ const file = fs.readFileSync(codeFilePath, { encoding: 'utf8' });
+ const lines = file.split("\n").slice(Number(startNumber)-1, Number(endNumber));
+
+ // I must use a concatenate string instead of `` because of tabulation and break line
+ return (
+ "" +
+ hljs.highlight(lines.join("\n"), {
+ language: fileExtension[1] || "",
+ ignoreIllegals: true,
+ }).value +
+ "
"
+ )
+}
diff --git a/src/main/openAndCloseCodePrezFiles.ts b/src/main/openAndCloseCodePrezFiles.ts
index 8b1aac7..4ceb463 100644
--- a/src/main/openAndCloseCodePrezFiles.ts
+++ b/src/main/openAndCloseCodePrezFiles.ts
@@ -38,7 +38,11 @@ export const openCodePrezArchive = async (archivePath: string) => {
?.data.toString();
const presentationConfig = JSON.parse(plainPresentationConfig ?? "{}");
- return { presentationConfig, presentationFileContent, presentationPath };
+ const presentationStyle = files
+ .find((file) => file.path == "style.css")
+ ?.data.toString();
+
+ return { presentationConfig, presentationFileContent, presentationPath, presentationStyle };
};
export const deleteCodePrezTempFolder = () => {
diff --git a/src/renderer/utils/utils.ts b/src/renderer/utils/utils.ts
index a697926..cb0dc82 100644
--- a/src/renderer/utils/utils.ts
+++ b/src/renderer/utils/utils.ts
@@ -1,20 +1,37 @@
+import { nativeImage } from "electron";
import hljs from "highlight.js";
+import MarkdownIt from "markdown-it";
+import path from "path";
+import fs from 'fs';
-var md = markdownHighlight();
+export function markdownHighlight(presentationPath: string) {
-export function markdownHighlight() {
- return require("markdown-it")({
+ const markdownOptions: MarkdownIt.Options = {
highlight: function (str: string, lang: string) {
if (lang && hljs.getLanguage(lang)) {
try {
- return (
- '' +
- hljs.highlight(str, {
- language: lang,
- ignoreIllegals: true,
- }).value +
- "
"
- );
+
+ if(lang == "bash") {
+ return (
+ '' + ) + } else { + return ( + '' + + hljs.highlight(str, { + language: lang, + ignoreIllegals: true, + }).value + + '
play_arrow
' +
+ hljs.highlight(str, {
+ language: lang,
+ ignoreIllegals: true,
+ }).value +
+ "
"
+ );
+ }
+
+
} catch (__) {}
}
@@ -24,5 +41,66 @@ export function markdownHighlight() {
""
);
},
- });
+ }
+
+ const md = MarkdownIt(markdownOptions);
+
+ //Include images
+ md.renderer.rules.image = (tokens, idx, options, env, self) => {
+ const token = tokens[idx];
+
+ const src = token.attrGet("src");
+
+ const regexForSrc = /\.\/assets/gm;
+
+ const srcWithPresentationPath = (src?.match(regexForSrc)) ? path.join("codeprez:/", presentationPath, src) : src
+ token.attrSet('src', srcWithPresentationPath || "")
+
+ return self.renderToken(tokens, idx, options)
+ }
+
+ //Include code via files
+ md.renderer.rules.link_open = (tokens, idx, options, env, self) => {
+ const token = tokens[idx];
+
+ const href = token.attrGet("href");
+
+ const regexPathFile = /^\.\/(.+\.\w+)/gm;
+ const regexLineNumber = /#(\d+)-(\d+)/;
+ const regexFileExtension = /\.(\w+)(?:#\d+-\d+)?$/;
+
+ const pathFile = href?.match(regexPathFile) ?? [];
+
+ const lineNumbers = href?.match(regexLineNumber) ?? [];
+ const startNumber = lineNumbers[1];
+ const endNumber = lineNumbers[2];
+
+ const fileExtension = href?.match(regexFileExtension) ?? [];
+
+ if(pathFile) {
+ const file = fs.readFileSync(path.join(presentationPath, pathFile[0] ?? ""), { encoding: 'utf8' });
+ const lines = file.split("\n").slice(Number(startNumber)-1, Number(endNumber));
+
+ // return (
+ // `${hljs.highlight(lines.join("\n"), {
+ // language: fileExtension[1] || "",
+ // ignoreIllegals: true,
+ // }).value}
`
+ // )
+
+ // I must use a concatenate string instead of `` because of tabulation and break line
+ return (
+ "" +
+ hljs.highlight(lines.join("\n"), {
+ language: fileExtension[1] || "",
+ ignoreIllegals: true,
+ }).value +
+ "
"
+ )
+ }
+
+ return self.renderToken(tokens, idx, options);
+ }
+
+ return md;
}
diff --git a/src/types.d.ts b/src/types.d.ts
index 2b96695..9c46e07 100644
--- a/src/types.d.ts
+++ b/src/types.d.ts
@@ -2,6 +2,7 @@ type PresentationData = {
presentationConfig: PresentationConfig;
presentationFileContent: string[] | string;
presentationPath: string;
+ presentationStyle: string;
};
type PresentationConfig = {
diff --git a/yarn.lock b/yarn.lock
index 8aa8581..d917b88 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2063,6 +2063,24 @@
dependencies:
"@types/node" "*"
+"@types/linkify-it@*":
+ version "3.0.2"
+ resolved "https://registry.yarnpkg.com/@types/linkify-it/-/linkify-it-3.0.2.tgz#fd2cd2edbaa7eaac7e7f3c1748b52a19143846c9"
+ integrity sha512-HZQYqbiFVWufzCwexrvh694SOim8z2d+xJl5UNamcvQFejLY/2YUtzXHYi3cHdI7PMlS8ejH2slRAOJQ32aNbA==
+
+"@types/markdown-it@^12.2.3":
+ version "12.2.3"
+ resolved "https://registry.yarnpkg.com/@types/markdown-it/-/markdown-it-12.2.3.tgz#0d6f6e5e413f8daaa26522904597be3d6cd93b51"
+ integrity sha512-GKMHFfv3458yYy+v/N8gjufHO6MSZKCOXpZc5GXIWWy8uldwfmPn98vp81gZ5f9SVw8YYBctgfJ22a2d7AOMeQ==
+ dependencies:
+ "@types/linkify-it" "*"
+ "@types/mdurl" "*"
+
+"@types/mdurl@*":
+ version "1.0.2"
+ resolved "https://registry.yarnpkg.com/@types/mdurl/-/mdurl-1.0.2.tgz#e2ce9d83a613bacf284c7be7d491945e39e1f8e9"
+ integrity sha512-eC4U9MlIcu2q0KQmXszyn5Akca/0jrQmwDRgpAMJai7qBWq4amIQhZyNau4VYGtCeALvW1/NtjzJJ567aZxfKA==
+
"@types/mime@*":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-3.0.1.tgz#5f8f2bca0a5863cb69bc0b0acd88c96cb1d4ae10"
From 7c5b5a63c5a925d256223b2ae6e948e208b69c63 Mon Sep 17 00:00:00 2001
From: matheoleger <71370253+matheoleger@users.noreply.github.com>
Date: Sun, 9 Apr 2023 11:47:43 +0200
Subject: [PATCH 2/7] feat(Slide): Style of slide
---
src/assets/css/Presentation.css | 10 +++++++
src/assets/css/SideBar.css | 7 +++++
src/assets/css/Slide.css | 52 ++++++++++++++++++++++++++++-----
src/components/Presentation.tsx | 14 +++++++--
src/components/SideBar.tsx | 23 ++-------------
src/components/Slide.tsx | 11 ++++++-
6 files changed, 87 insertions(+), 30 deletions(-)
diff --git a/src/assets/css/Presentation.css b/src/assets/css/Presentation.css
index 09d875e..47c129c 100644
--- a/src/assets/css/Presentation.css
+++ b/src/assets/css/Presentation.css
@@ -1,4 +1,14 @@
.presentation-page {
overflow-y: auto;
overflow-x: hidden;
+}
+
+.presentation-header {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+}
+
+.authors {
+ display: flex;
}
\ No newline at end of file
diff --git a/src/assets/css/SideBar.css b/src/assets/css/SideBar.css
index f5fba37..b12a0c6 100644
--- a/src/assets/css/SideBar.css
+++ b/src/assets/css/SideBar.css
@@ -13,6 +13,13 @@
gap:1em;
}
+.sidebar .slide-preview {
+ max-width: inherit;
+ max-height: inherit;
+ overflow-y: auto;
+ overflow-x: hidden;
+}
+
button{
cursor: pointer;
display: flex;
diff --git a/src/assets/css/Slide.css b/src/assets/css/Slide.css
index d3a76ed..6d524bc 100644
--- a/src/assets/css/Slide.css
+++ b/src/assets/css/Slide.css
@@ -1,16 +1,51 @@
-.slide-container {
- height: 100vh;
+section {
+ /* height: 100vh; */
border-radius: 10px;
box-shadow: 0 0 20px 10px rgba(0, 0, 0, 0.2);
+ width: 100%;
+ height: 100%;
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ flex-wrap: wrap;
+ background: var(--black-grey);
+}
+
+section p img {
+ max-height: 80%;
+ max-width: 80%;
+}
+
+.slide-container p {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ margin: 10px;
}
-.slide-container pre {
+pre {
border-radius: 10px;
- height: 100%;
+ min-width: 20%;
+ max-width: 90%;
+ display: flex;
+ overflow: auto;
}
-.slide-container code {
- height: 100%;
+code:not(pre > code) {
+ background-color: var(--dark-grey);
+ border-radius: 5px;
+ padding: 2px;
+ color: var(--white);
+ margin: 2px;
+}
+
+pre button {
+ width: 40px;
+ display: flex;
+ flex-direction: row;
+ justify-content: center;
+ align-items: center;
}
.scale-preview {
@@ -18,5 +53,8 @@
}
.scale-sidebar {
- transform : scale(0.3);
+ transform : scale(0.7);
+ /* height: 300px; */
+ width: 100%;
+ max-height: 300px;
}
\ No newline at end of file
diff --git a/src/components/Presentation.tsx b/src/components/Presentation.tsx
index cc11df7..7b432d6 100644
--- a/src/components/Presentation.tsx
+++ b/src/components/Presentation.tsx
@@ -13,7 +13,7 @@ export const Presentation = () => {
useEffect(() => {
// window.api.getPresentationData(setPresentationData);
setPresentationData(state);
- }, [useLocation()]);
+ }, [state]);
return (
WXB>+b^lelkryE^b2iqhOJ$W#B@xTCC{)aQ$V3lcpEk4;G3Wka?m&dMI>Lq!t)afo_a=-CZnqryp`tBJ`7^ot
zx2$BG6AKc@tnl8AV0@dlVt5Uc
zQW2oj6}_}IpQ%My=MAbXK?>mBK&f`p^6STCJ<+T!#QEpv$(tmK04e~{Pm6P54WsQw
zhvbVkGt#Y$H#c&0{mHb(HL`Z!CEtzo*wqtK+vB2F$N3tsJR;bHI4#^JE~eY|UN^c@
zT rtwJpsZ1sy}??RY%Szu9Xr?85L&H8i(z8OQ!2c&qJ
z&mos`e-Jsfd)?s
ztstvM37S8Y;I-u4?~m1tOfYFx;2x&Xy|M=x)a`u|d&%3j=
-V>rwF!`1n)N(Ck|;{Qs*Uj
zt_(i9j1NfMPlO3v!;TRoEnVZKACuW*uM_fFgp00hc5-AAaosVTZ`q2sJy4et6muF;
zZQ(e0Bc5?UoPZJeZ;X5MG57r$hydm_a1KFE9@C%>SOjvkvch+Db2vS(;yw?Cg%#gosEB{9-r
z8V2Vq47-d?4MzFP!zsG)Zlu>mMEzbp-5r;jgs>u<=niwhVwpECnUTJ8!S%`+)NEh41eoDlzPXQy3
z;b!XOL%5" +
- hljs.highlight(lines.join("\n"), {
+ hljs.highlight(codeToDisplay, {
language: fileExtension[1] || "",
ignoreIllegals: true,
}).value +
diff --git a/src/renderer/components/SlideShow.tsx b/src/renderer/components/SlideShow.tsx
new file mode 100644
index 0000000..24962a1
--- /dev/null
+++ b/src/renderer/components/SlideShow.tsx
@@ -0,0 +1,35 @@
+import { useState, useEffect } from "react";
+import { useLocation, useNavigate } from 'react-router-dom';
+import { Slide } from '../../components/Slide';
+import "../../assets/css/SlideViewer.css"
+
+type Props = {
+ config?: PresentationConfig,
+ content: string[],
+ style?: string,
+ slideScale: "slideViewer" | "preview" | "sidebar"
+}
+
+export const SlideShow = (props: Props) => {
+ const {config, content, style, slideScale} = props;
+
+ return (
+ <>
+
{config?.title}
+
+ Créé par : {config?.authors.join(", ")}
+ {presentationData?.presentationConfig.title}
-
- Créé par :
- {presentationData?.presentationConfig.authors.map((author, index) => (
- {author}
- ))}
-
'
- )
- } else {
- return (
- '' +
- hljs.highlight(str, {
- language: lang,
- ignoreIllegals: true,
- }).value
- + '
"
- );
- }
-
-
- } catch (__) {}
- }
-
- return (
- '' +
- hljs.highlight(str, {
- language: lang,
- ignoreIllegals: true,
- }).value +
- "
"
- );
- },
- }
-
- const md = MarkdownIt(markdownOptions);
-
- //Include images
- md.renderer.rules.image = (tokens, idx, options, env, self) => {
- const token = tokens[idx];
-
- const src = token.attrGet("src");
-
- const regexForSrc = /\.\/assets/gm;
-
- const srcWithPresentationPath = (src?.match(regexForSrc)) ? path.join("codeprez:/", presentationPath, src) : src
- token.attrSet('src', srcWithPresentationPath || "")
-
- return self.renderToken(tokens, idx, options)
- }
-
- //Include code via files
- md.renderer.rules.link_open = (tokens, idx, options, env, self) => {
- const token = tokens[idx];
-
- const href = token.attrGet("href");
-
- const regexPathFile = /^\.\/(.+\.\w+)/gm;
- const regexLineNumber = /#(\d+)-(\d+)/;
- const regexFileExtension = /\.(\w+)(?:#\d+-\d+)?$/;
-
- const pathFile = href?.match(regexPathFile) ?? [];
-
- const lineNumbers = href?.match(regexLineNumber) ?? [];
- const startNumber = lineNumbers[1];
- const endNumber = lineNumbers[2];
-
- const fileExtension = href?.match(regexFileExtension) ?? [];
-
- if(pathFile) {
- const file = fs.readFileSync(path.join(presentationPath, pathFile[0] ?? ""), { encoding: 'utf8' });
- const lines = file.split("\n").slice(Number(startNumber)-1, Number(endNumber));
-
- // return (
- // `' +
- md.utils.escapeHtml(str) +
- "
`
- // )
-
- // I must use a concatenate string instead of `` because of tabulation and break line
- return (
- "${hljs.highlight(lines.join("\n"), {
- // language: fileExtension[1] || "",
- // ignoreIllegals: true,
- // }).value}
"
- )
- }
-
- return self.renderToken(tokens, idx, options);
- }
-
- return md;
-}
+export {}
\ No newline at end of file
" +
- hljs.highlight(lines.join("\n"), {
- language: fileExtension[1] || "",
- ignoreIllegals: true,
- }).value +
- "