Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template for quote slides #492

Open
ooker777 opened this issue Jul 10, 2024 · 1 comment
Open

Template for quote slides #492

ooker777 opened this issue Jul 10, 2024 · 1 comment

Comments

@ooker777
Copy link
Contributor

I manage to create a template for quote slides. This helps users focus on the data and avoid polluting the text with HTML. To use it just use a blockcode with quote and fill these fields.

```quote
quote: Misquotations are the only quotations that are never misquoted.
author:
  name: Hesketh Pearson
  title: British actor, theater director and writer
  org: Company name
  image: https://upload.wikimedia.org/wikipedia/en/d/d0/Hesketh_Pearson.jpg

Do you want me to make a PR from this? I think we can have a snippet or plugin folder.

CSS

figure.quote {
  display: flex;
  gap: .75em;
  margin: 1em;
}

.col1 {
  display: flex;
  flex-direction: column;
  text-align: end
}

.author {
  font-size: .5em
}
.author .name{
  font-weight: bold
}

.author img {
  max-width: 100%;
  height: auto;
  display: block;
  position: relative;
  top: 0
}

Preprocessor

function htmlTemplateFn({quote, name, title, org, image}){
  const quoteSentences = quote.split('. ')
  const quoteWithFragmentTags = "<span class='fragment'>" + quoteSentences.join(".</span> <span class='fragment'>") + "</span>" 
  return `<figure class="quote">
    <div class="col1">
      <div>❝ ${quoteWithFragmentTags}</div>
    </div>
    <div class="author fragment">
      <img src="${image}">
      <div class='name' >${name}</div>
      <div class='title'>${title}</div>
      <div class='org' >${org}</div>
    </div>
  </figure>`
} 

function getValue(quoteBlock, field) {
  const pattern = `${field}:(.*)`;
  const regex = new RegExp(pattern, 'g') 
  return [...quoteBlock.matchAll(regex)][0][1].trim();
}

function quoteSlideFn(markdown) {
  const regex = /\`\`\`quote(.*?)\`\`\`/gs
  const quoteBlocks = [...markdown.matchAll(regex)] 
  let result = markdown

  for (const quoteBlock of quoteBlocks) {
    const data = {
      quote: getValue(quoteBlock[0], 'quote'),
      name: getValue(quoteBlock[0], 'name'),
      title: getValue(quoteBlock[0], 'title'),
      org: getValue(quoteBlock[0], 'org'),
      image: getValue(quoteBlock[0], 'image'),
    } 
    const html = htmlTemplateFn(data) 
    result = result.replace(quoteBlock[0], html)
  } 
  return result;
}

export default function (markdown, _options) {
  return new Promise((resolve, _reject) => {
    return resolve(quoteSlideFn(markdown));
  });
}

Demo

@webpro
Copy link
Owner

webpro commented Jul 11, 2024

Looks cool. That'd be great!

We can link to them in the docs so they can be copy-pasted. Or even add named built-in preprocessors (e.g. reveal-md --preprocessor quotes).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants