From a415007a982b3c7b73ec10a211c23621a9c9bea0 Mon Sep 17 00:00:00 2001 From: Kevin Matsubara Date: Mon, 2 Sep 2024 23:05:58 +0200 Subject: [PATCH] Add Jsp markdown text markup and classes. --- src/Pages/markdownPage.js | 149 +++++++++++++++++++++++--------------- src/overrides.scss | 56 ++++++++++++++ 2 files changed, 146 insertions(+), 59 deletions(-) diff --git a/src/Pages/markdownPage.js b/src/Pages/markdownPage.js index 35f38f8..98d7318 100644 --- a/src/Pages/markdownPage.js +++ b/src/Pages/markdownPage.js @@ -5,13 +5,80 @@ import SyntaxHighlighter from 'react-syntax-highlighter'; import { docco, dracula } from 'react-syntax-highlighter/dist/esm/styles/hljs'; import { useTheme } from '../ThemeContext'; -const MarkdownPage = ({ md }) => { - const file_name = md; - const [markdownContent, setPost] = useState(''); +const MySection = ({ children }) => { + return (
{children}
); +} + +const MyParagraph = ({ children, ...props }) => { + return (

{children}

); +} + +const MyImage = ({ src, alt }) => { + return ( + + + + + {alt} + ); +} + +const Jps = ({ text, colour, underline, strikethrough }) => { + const { theme } = useTheme(); + let classBuilder = `jsp ` + theme; + + if (colour) { + classBuilder = classBuilder + ` ` + colour + } + if (underline) { + classBuilder = classBuilder + ` u` + } + if (strikethrough) { + classBuilder = classBuilder + ` s` + } + + return ({text}); +} + +const MyCodeBlock = ({ children, className }) => { const { theme } = useTheme(); + function stripLangPrefix(inputString) { + let softwareLanguage = inputString ?? '' + // if (inputString === 'undefinded') { + // return ''; + // } + + if (softwareLanguage.startsWith('lang-')) { + return softwareLanguage.slice(5); + } + return softwareLanguage; + } + + console.log("MyCodeBlock: " + className); + let codeOutput; + let styling = (true) ? docco : dracula; //theme === 'light' + codeOutput = {children}; + + // + + return ( +
+
+ {codeOutput} +
+ ); +} + +// TODO 1: Create error if given markdown file does not exist. +// TODO 2: Create error if file for given language does not exist. + +const MarkdownPage = ({ md }) => { + const [markdownContent, setPost] = useState(''); + + // causes 3 calls somehow... useEffect(() => { - import(`./${file_name}`) + import(`./${md}`) .then(res => { fetch(res.default) .then(res => res.text()) @@ -21,64 +88,28 @@ const MarkdownPage = ({ md }) => { .catch(err => console.log(err)); }); - const MySection = ({ children }) =>
{children}
- - const MyParagraph = ({ children, ...props }) =>

{children}

- - const MyImage = ({ src, alt }) => { - return ( - - - - - {alt} - ) - } - - function stripLangPrefix(inputString) { - if (inputString.startsWith('lang-')) { - return inputString.slice(5); - } - return inputString; - } - - const MyCodeBlock = ({ children, className }) => { - let codeOutput; - if (theme === 'light') { - codeOutput = {children}; - } - else { - codeOutput = {children}; - } - - // - return ( -
-
-
- {codeOutput} -
- ) - } - return ( - + }}> {markdownContent} ) diff --git a/src/overrides.scss b/src/overrides.scss index 194554e..a94dfe8 100644 --- a/src/overrides.scss +++ b/src/overrides.scss @@ -10,6 +10,15 @@ $theme-colors: ( "text-light": #2d0635, "link-dark": #5900ff, "link-light": #0400ff, + // Text highlight colours + "dark-c1": #eeaa00, + "dark-c2": #eeaaff, + "dark-c3": #ff6262, + "dark-dim1": #ababab, + "light-c1": #992299, + "light-c2": #446600, + "light-c3": #c70000, + "light-dim1": #787878, ); // Import Bootstrap and its default variables @@ -152,6 +161,53 @@ body.light { } } +.jsp { + // Dark theme. + &.dark { + &.c1 { + color: map-get($theme-colors, "dark-c1") + } + &.c2 { + color: map-get($theme-colors, "dark-c2") + } + &.c3 { + color: map-get($theme-colors, "dark-c3") + } + &.dim1 { + color: map-get($theme-colors, "dark-dim1"); + } + &.s { + text-decoration: line-through; + } + &.u { + text-decoration: underline; + } + } + + // Light theme. + &.light { + &.c1 { + color: map-get($theme-colors, "light-c1") + } + &.c2 { + color: map-get($theme-colors, "light-c2"); + } + &.c3 { + color: map-get($theme-colors, "light-c3") + } + &.dim1 { + color: map-get($theme-colors, "light-dim1"); + } + &.s { + text-decoration: line-through; + } + &.u { + text-decoration: underline; + } + } +} + + // Core variables and mixins // @import "variables"; // @import "mixins"; \ No newline at end of file