Commit e7f4b610 authored by BERTHAUT Florent's avatar BERTHAUT Florent
Browse files

Added modification to odt for correct table style

parent d386d7de
This diff is collapsed.
......@@ -48,6 +48,13 @@ let Papa = require("papaparse");
let fs = require("fs");
//const jsdom = require("jsdom");
const cheerio = require('cheerio');
var JSZip = require("jszip");
var zip = new JSZip();
const { exec } = require("child_process");
const csvFile = "input/fiches.csv";
......@@ -272,6 +279,7 @@ function parseGuides(fiches) {
}
//add enseignants référents to enseignants if not already there
/*
if(!(f["Enseignant.e.s"]+"")
.includes(f["Enseignant.e référent.e"].split(" ")[0])){
......@@ -282,7 +290,7 @@ function parseGuides(fiches) {
sem[sem.length-1]["Enseignant.e.s"]
+=", "+f["Enseignant.e.s"];
}
}
}*/
//change UE number depending on parcours for L3
......@@ -429,7 +437,8 @@ function writeFilteredFicheToStr(guide, guideName, f) {
guide.str += filterField(f["Descriptif"]);
guide.str += fieldSuf;
guide.str += titlePre+ "Évaluation" + titleSuf;
//guide.str += titlePre+ "Évaluation" + titleSuf;
guide.str += titlePre+ "Informations supplémentaires sur l'évaluation" + titleSuf;
guide.str += filterField(f["Informations sur l'évaluation"]);
guide.str += fieldSuf;
......@@ -487,6 +496,94 @@ function writeFilteredFicheToStr(guide, guideName, f) {
guide.str += "<br/> </div>\n";
}
function writeMCCTableToStr(guide, guideName, sem) {
const empty = /\s*/;
guide.str += "<p>\n";
guide.str += "<i> Université de Lille - UFR LEA - "+guideName;
guide.str += " - Semestre "+sem+"</i>\n";
guide.str += "</p>\n";
guide.str += "<p>&nbsp</p>\n";
guide.str += "<p>\n";
guide.str += "<span custom-style='Titre 1 Car1'>Modalités de contrôle des connaissances</span> ";
guide.str += "</p>\n";
guide.str += "<p>&nbsp</p>\n";
guide.str += "<table>\n";
guide.str += "<tr>\n";
guide.str += "<th>UE - EC</th><th>Session initiale</th><th>Rattrapage</th>\n";
guide.str += "</tr>\n";
for(let f of guides.get(guideName).get(sem)) {
guide.str += "<tr>\n";
guide.str += "<td>\n";
guide.str += "UE "+f["UE"]+" : ";
guide.str += f["Nom UE"]+" - "+f["Nom EC"]+"\n";
guide.str += "</td>\n";
guide.str += "<td>\n";
guide.str += f["Evaluation session 1: CC/CT"]+" - ";
guide.str += f["Evaluation session 1: type d'exercices"]+" - ";
guide.str += f["Evaluation session 1: écrit/oral"]+" - ";
guide.str += f["Evaluation session 1: durée de l'épreuve"]+"\n";
guide.str += "</td>\n";
guide.str += "<td>\n";
guide.str += f["Evaluation session 2: CC intégral/CT"]+" - ";
guide.str += f["Evaluation session 2: type d'exercices"]+" - ";
guide.str += f["Evaluation session 2: écrit/oral"]+" - ";
guide.str += f["Evaluation session 2: durée de l'épreuve"]+"\n";
guide.str += "</td>\n";
guide.str += "</tr>\n";
}
guide.str += "</table>\n";
guide.str +="<div custom-style='Page Break'> \n";
guide.str += "<br/> </div>\n";
}
function updateTablesInOdt(input, output) {
fs.readFile(input, function(err, data) {
if (err) throw err;
JSZip.loadAsync(data).then(function (zip) {
zip.forEach(function (relativePath, zipEntry) { // 2) print entries
if(relativePath=="content.xml") {
zipEntry.async("string")
.then(function success(content) {
//modify all tables
const $ = cheerio.load(content, {xmlMode:true});
let cells = $("style\\:table-cell-properties").each(
function(index, element) {
element.attribs["fo:border"]="solid 0.1pt #000000";
});
//write back to file
zip.file("content.xml", $.xml());
//reassign the content
zip
.generateNodeStream({type:'nodebuffer',streamFiles:true})
.pipe(fs.createWriteStream(output))
.on('finish', function () {
//console.log("Wrote output file");
});
}, function error(e) {
// handle the error
});
}
});
});
});
}
function saveToDoc(guideName) {
let guideFileName = "output/guide-"+String(guideName).trim().replace(/\ /g, "_");
......@@ -506,14 +603,11 @@ function saveToDoc(guideName) {
for(let f of guides.get(guideName).get(sem)) {
writeFilteredFicheToStr(guide, guideName, f);
}
if(!guideName.includes("M1") && !guideName.includes("M2")) {
writeMCCTableToStr(guide, guideName, sem);
}
}
//Write MCC list
//Write BCC
//Write the html file
fs.writeFileSync(guideFileName+".html", guide.str, {"encoding":"utf-8"});
console.log("Done building "+guideFileName+".html");
......@@ -521,7 +615,7 @@ function saveToDoc(guideName) {
//Transform from html to markdown
let commandHTML = "pandoc ";
commandHTML+=" -f html "+guideFileName+".html ";
commandHTML+=" -t markdown -o "+guideFileName+".md";
commandHTML+=" -o "+guideFileName+".md";
exec(commandHTML,
(error, stdout, stderr) => {
if (error) {
......@@ -530,12 +624,12 @@ function saveToDoc(guideName) {
}
//Transfrom markdown to doc/odt
let commandODT = "pandoc -t odt ";
let commandODT = "pandoc ";
commandODT+=" --lua-filter src/pagebreak.lua ";
commandODT+=" --lua-filter src/odt-custom-styles.lua ";
commandODT+=" -f markdown "+guideFileName+".md ";
commandODT+=" --reference-doc='input/reference_magali.odt' ";
commandODT+=" -o "+guideFileName+".odt ";
commandODT+=" -t odt --reference-doc='input/reference_magali.odt' ";
commandODT+=" -o "+guideFileName+".odt_tmp ";
exec(commandODT,
(error, stdout, stderr) => {
......@@ -543,6 +637,9 @@ function saveToDoc(guideName) {
console.log(`error: ${error.message}`);
return;
}
//correct tables
updateTablesInOdt(guideFileName+".odt_tmp", guideFileName+".odt");
/*
let commandPDF = "libreoffice --headless --convert-to pdf";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment