Schrek.fr

Mon super blog :)

  1. home
  2. posts
  3. 2023
  4. 04
  5. Pandoc_html_template

Pandoc html template


Pour gérer les templates avec Pandoc, on va utiliser un système de balises qui sont incluses dans l’entête du fichier Markdown.

---
title: Schrek
subtitle: Mon jolie site
abstract: Test template
abstract-title: test abstract-title
author: Schrek christophe
date: 2023-03-23
site: https://schrek.fr/
subject: Pandoc template
description: utilisation des templates avec Pandoc
logo: logo.png
lang: fr
keywords: pandoc html5 css template
category: Web
---

Exemple de template

<!DOCTYPE html>
<html> 
<head>
    <meta charset="utf-8">
    <html $if(lang)$ lang="$lang$" $endif$
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    $for(description)$<meta name="description" content="$description$">$endfor$
    <title>$if(title)$$title$$endif$</title>
    $for(keywords)$<meta name="keywords" content="$keywords$">$endfor$
    $for(author)$<meta name="author" content="$author$"/>$endfor$
    $if(date)$<meta name="date" content="$date$"/>$endif$
    <link rel="stylesheet" href="styles.css">
</head>
<header>
    $if(title)$<h1>$title$</h1>$endif$
    $if(date)$<h3>$date$</h3>$endif$
    $if(author)$<p>$author$</p>$endif$
</header>
<main>
    $if(subject)$<h3>$subject$</h3>$endif$
    $if(description)$<p>$description$</p>$endif$
    $if(category)$<p>$category$</p>$endif$
<nav>
$if(toc)$
$toc$
$endif$
</nav>

<article>
$body$
</article>
</main>
</html>

Compilation du document html

J’ai fait un petit exemple avec plein de balises Markdown. On peut remarquer que les cases à cocher ça marche pas.

test.md.txt (clic droit enregistrer sous)

pandoc -s -f markdown+smart  --template template.html --toc --metadata  --to=html5 test.md -o index.html

Ça donne un fichier HTML brut.

index.html (clic droit enregistrer sous)

Il reste l’habillage avec du CSS (vite fait avec bootstrap), il faut recompiler le fichier a chaque modification du template.

index-2.html (clic droit enregistrer sous)

Liens

https://pandoc.org/MANUAL.html#using-variables-in-templates

https://github.com/ryangrose/easy-pandoc-templates

https://maehr.github.io/academic-pandoc-template/

comments powered by Disqus