From ed35abf4d2f8fb26533823d0cc4938d626aa5c27 Mon Sep 17 00:00:00 2001 From: Michael Ochmann Date: Fri, 30 Sep 2022 19:52:20 +0200 Subject: [PATCH] added support for metadata and corresponding title slide --- src/Parser.js | 57 +++++++++++++++++++++++++++++-- src/ui/src/assets/css/_slide.scss | 13 +++++++ 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/src/Parser.js b/src/Parser.js index 88c89cb..0e28076 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -3,9 +3,11 @@ const {lexer} = require("marked"); class Slide { + title; content; constructor(content = []) { + this.title = false; this.content = content; } @@ -18,17 +20,68 @@ const tokenize = string => { return lexer(string); }; +const injectTitle = (deck, meta) => { + const title = []; + + if (meta.title) + title.push({ + type : "heading", + level : 1, + tokens : [ + { + type : "text", + text : meta.title + } + ] + }); + if (meta.author) + title.push({ + type : "paragraph", + tokens : [ + { + type : "text", + text : `– ${meta.author}` + }, + ] + }); + if (meta.email) + title.push({ + type : "paragraph", + tokens : [ + { + type : "text", + text : `<${meta.email}>` + }, + ] + }); + const slide = new Slide(title); + slide.title = true; + deck.unshift(slide); + + return deck; +} + const parser = string => { const tokenStream = tokenize(string); const slideDeck = []; let currentSlide = new Slide(); + let metaData = null; for (const token of tokenStream) { - if ( token.type === "space" || token.type === "heading" && token.depth === 1) { + if ( token.type === "space" || (token.type === "heading" && token.depth === 1) || token.type === "html") { if (currentSlide.content.length > 0) { slideDeck.push(currentSlide); currentSlide = new Slide(); } + if (!metaData && token.type === "html" && token.text.charAt(2) === '-') { + const metaString = token.text.replace(/()/gi, ""); + const meta = {}; + for (const attribute of metaString.split(';')) { + const [key, value] = attribute.split(':'); + meta[key.trim()] = value.trim(); + } + metaData = meta; + } if (token.type === "heading") slideDeck.push(new Slide([token])); @@ -39,7 +92,7 @@ const parser = string => { if (currentSlide.content.length > 0) slideDeck.push(currentSlide); - return slideDeck; + return injectTitle(slideDeck, metaData); }; module.exports = { diff --git a/src/ui/src/assets/css/_slide.scss b/src/ui/src/assets/css/_slide.scss index 5f22418..1500252 100644 --- a/src/ui/src/assets/css/_slide.scss +++ b/src/ui/src/assets/css/_slide.scss @@ -2,6 +2,7 @@ font-family: "Iosevka", sans-serif; font-size: 2rem; display: flex; + flex-direction: column; align-items: center; justify-content: center; user-select: none; @@ -9,6 +10,18 @@ background: color(background); color: color(foreground); + &.title { + p { + font-style: italic; + font-size: 1.8rem; + color: color(scrollbar); + + &:nth-of-type(2) { + font-size: 1.2rem; + } + } + } + h1 { font-size: 4rem; }