|
|
@ -3,9 +3,11 @@ |
|
|
|
const {lexer} = require("marked"); |
|
|
|
const {lexer} = require("marked"); |
|
|
|
|
|
|
|
|
|
|
|
class Slide { |
|
|
|
class Slide { |
|
|
|
|
|
|
|
title; |
|
|
|
content; |
|
|
|
content; |
|
|
|
|
|
|
|
|
|
|
|
constructor(content = []) { |
|
|
|
constructor(content = []) { |
|
|
|
|
|
|
|
this.title = false; |
|
|
|
this.content = content; |
|
|
|
this.content = content; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -18,17 +20,68 @@ const tokenize = string => { |
|
|
|
return lexer(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 parser = string => { |
|
|
|
const tokenStream = tokenize(string); |
|
|
|
const tokenStream = tokenize(string); |
|
|
|
const slideDeck = []; |
|
|
|
const slideDeck = []; |
|
|
|
let currentSlide = new Slide(); |
|
|
|
let currentSlide = new Slide(); |
|
|
|
|
|
|
|
let metaData = null; |
|
|
|
|
|
|
|
|
|
|
|
for (const token of tokenStream) { |
|
|
|
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) { |
|
|
|
if (currentSlide.content.length > 0) { |
|
|
|
slideDeck.push(currentSlide); |
|
|
|
slideDeck.push(currentSlide); |
|
|
|
currentSlide = new Slide(); |
|
|
|
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") |
|
|
|
if (token.type === "heading") |
|
|
|
slideDeck.push(new Slide([token])); |
|
|
|
slideDeck.push(new Slide([token])); |
|
|
@ -39,7 +92,7 @@ const parser = string => { |
|
|
|
if (currentSlide.content.length > 0) |
|
|
|
if (currentSlide.content.length > 0) |
|
|
|
slideDeck.push(currentSlide); |
|
|
|
slideDeck.push(currentSlide); |
|
|
|
|
|
|
|
|
|
|
|
return slideDeck; |
|
|
|
return injectTitle(slideDeck, metaData); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
module.exports = { |
|
|
|
module.exports = { |
|
|
|