Commit fafd4769 authored by piks3l's avatar piks3l
Browse files

[fix] troncage des amendements

parent c1df5c7e
Pipeline #1014 failed with stage
......@@ -7,9 +7,8 @@
<!--
Am2Wiki by Oncela
Last modification: 27-04-2017
Last modification: 04-05-2017
This program intends to convert amendments drafted by Members of European
Parliament into reusable formats.
......@@ -30,9 +29,7 @@
var colors = [ "white", "#A60000", "#F55E33", "#BABABA", "#AEF279", "#44C92C" ];
// Political groups of the EP
var groups = [ "", "EPP", "S&D", "ALDE", "Verts/ALE", "ECR", "GUE/NGL", "NI", "EFDD", "ENF"];
var groups = [ "", "EPP", "S&D", "ALDE", "Verts/ALE", "ECR", "GUE/NGL", "NI", "EFD" ];
// Template for conversion (how the amendments are displayed once processed: you can change it at will)
/*
......@@ -55,11 +52,7 @@
+ "%member<br/>\n"
+ "%group" // If a group has been set, the templateGroup (defined bellow) is inserted here
+ "%article\n"
+ "|-\n"
+ "|width='50%' style='vertical-align:top;'|\n"
+ "%left\n"
+ "|width='50%' style='vertical-align:top;'|\n"
+ "%right\n"
+ "%table"
+ "%justif" // If the amendment is justified, the templateJustif (defined bellow) is inserted here
+ "|}\n\n"
+ "%comment" // If the amendment is commented, the templateComment (defined bellow) is inserted here
......@@ -67,6 +60,15 @@
var templateGroup = "'''%group'''<br/>\n";
var templateTable =
"|-\n"
+ "|width='50%' style='vertical-align:top;border-top:none;border-bottom:none;%style'|\n"
+ "%left\n"
+ "|width='50%' style='vertical-align:top;border-top:none;border-bottom:none;%style'|\n"
+ "%right\n";
var tableStyle = ["", "padding-bottom:0em;", "padding-top:0em; padding-bottom:0em", "padding-top:0em"];
var templateJustif =
"|-\n"
+ "| colspan='2' |\n"
......@@ -114,7 +116,7 @@
<script>
// Array of the processed amendments
var amendments = [];
var amendments = [];
// Open and read the file selected by the user
function read(file)
......@@ -125,48 +127,48 @@
// Open and read the file
var reader = new FileReader();
reader.onload = function(){process(reader.result);};
reader.readAsText(file);
reader.onload = function(){process(reader.result);};
reader.readAsText(file);
}
// Process the file content
function process(file)
{
// Put the content of the file into a <div> buffer (for DOM manipulation)
// Put the content of the file into a <div> buffer (for DOM manipulations on tables)
var buffer = document.getElementById('buffer');
buffer.innerHTML = file;
// Simplify the tables
buffer.innerHTML = file;
// Get all the tables
var elements = "";
elements = buffer.getElementsByTagName("table");
for (var i = elements.length; i > 0; i--)
{
// Isolate the third line
var trl = elements[0].getElementsByTagName("tr");
var tr = trl[trl.length-1];
if (trl.length > 3)
tr = trl[2];
elements = buffer.getElementsByTagName("table");
// Replace HTML by wiki
tr.innerHTML = tr.innerHTML.replace(/(<i>\n?<b>)|(<\/b>\n?<\/i>)/gm, "'''''");
// For each table
for (var i = 0; i < elements.length; i++)
{
// Replace HTML <i> and <b> by '''''
elements[i].innerHTML = elements[i].innerHTML.replace(/(<i>\n?<b>)|(<\/b>\n?<\/i>)/gm, "'''''");
// Get all the lines
var lines = elements[i].getElementsByTagName("tr");
// Get the content of each line (starting from the third line and excluding tables shorter than 3 lines)
var content="";
for (var j = 2; lines.length >= 3 && j < lines.length; j++)
{
content += "[[" + lines[j].getElementsByTagName("td")[0].innerText + "||" + lines[j].getElementsByTagName("td")[1].innerText + "]]";
}
// Create a simplified table
// Put the content into a <p>
var newTable = document.createElement("p");
newTable.innerHTML = content;
if (tr.getElementsByTagName("td").length > 1)
newTable.innerHTML =
"[["
+ tr.getElementsByTagName("td")[0].innerText
+ "||"
+ tr.getElementsByTagName("td")[1].innerText
+ "]]";
// Replace the old tables by the simplified one
elements[0].parentNode.replaceChild(newTable, elements[0]);
// Replace the old table by the new p
elements[i].appendChild(newTable);
}
// Remove HTML from the file
// Remove all remaining HTML tags
var cleanFile = "";
elements = buffer.getElementsByTagName("p");
for (var i = 0; i < elements.length; i++)
......@@ -177,36 +179,47 @@
// Delete the buffer
buffer.parentNode.removeChild(buffer);
// Remove tabs and new-lines
// Remove tabs, new-lines and double spaces
cleanFile = cleanFile.replace(/\t/g, " ");
cleanFile = cleanFile.replace(/\n/g, " ");
while (cleanFile.search(/ /g) > -1)
cleanFile = cleanFile.replace(/ /g, " ");
// Check weither the amendments have been tabled by a single rapporteur or several members
var rapporteur = "";
if (cleanFile.search(/<Depute>/) != -1)
rapporteur = cleanFile.match(/<Depute> *(.*) *<\/Depute>/)[1];
var rapporteur = cleanFile.match(/<Depute> *(.*) *<\/Depute>/)[1];
else
var rapporteur = "";
// Remove the begining of the file
// Remove the begining of the file (from its start to the first amendement)
cleanFile = cleanFile.replace(/^.*?(<NumAm>)/, "$1");
// Use the internal tags to isolate each amendment in an array
var parser = cleanFile.match(/Am>.*?<\/NumAm>.*?<Members>.*?\[\[.*?\]\].*?((<Num)|$)/g);
var parser = cleanFile.match(/Am>.*?<\/NumAm>.*?\[\[.*?\]\].*?((<Num)|$)/g);
// Use the internal tags to retrive each info and put them into the amendments array
for (var i = 0; i < parser.length ; i++)
{
var am = {};
am.number = parser[i].replace(/Am> *(.*?) *<\/NumAm>.*/, "Amendment $1");
am.member = parser[i].replace(/.*<RepeatBlock-By> *<Members> *(.*?) *<\/Members>.*/, "$1");
am.member = (rapporteur != "") ? rapporteur :
parser[i].replace(/.*<RepeatBlock-By> *<Members> *(.*?) *<\/Members>.*/, "$1");
am.article = parser[i].replace(/.*<Article> *(.*?) *<\/Article>.*/, "$1");
am.left = parser[i].replace(/.*\[\[ *(.*?) *\|\|.*/, "$1");
am.right = parser[i].replace(/.*\|\| *(.*?) *\]\].*/, "$1");
am.table = parser[i].match(/\[\[.*?\]\]/g);
if (am.table.length>1)
console.log(am.number);
for (var j = 0; j < am.table.length; j ++)
{
var t = {};
t.left = am.table[j].replace(/.*\[\[ *(.*?) *\|\|.*/, "$1");
t.right = am.table[j].replace(/.*\|\| *(.*?) *\]\].*/, "$1");
am.table[j] = t;
}
am.justif = (parser[i].search(/TitreJust/)>0) ? parser[i].replace(/.*<\/TitreJust> *(.*?) *<.*/, "$1") : "";
am.group = 0;
am.comment = "";
......@@ -318,24 +331,31 @@
var content = document.createElement("div");
content.className = "form_content";
content.style.display = "none";
content.innerHTML =
amendments[i].member + "<br/><br/><b>"
+ amendments[i].article + "</b><br/><br/>"
+ "<table><tr><td>"
+ amendments[i].left
+ "</td><td>"
+ amendments[i].right
+ "</td></tr></table>";
var c = "";
c = amendments[i].member + "<br/><br/><b>"
+ amendments[i].article + "</b><br/><br/>"
+ "<table>";
for (j = 0; j < amendments[i].table.length; j++)
{
c += "<tr><td>"
+ amendments[i].table[j].left
+ "</td><td>"
+ amendments[i].table[j].right
+ "</td></tr>";
}
c += "</table>";
if (amendments[i].justif != "")
content.innerHTML += "<br/><i>Justification: " + amendments[i].justif + "</i>";
c += "<br/><i>Justification: " + amendments[i].justif + "</i>";
content.innerHTML = content.innerHTML.replace(/'''''(.*?)'''''/g, "<b>$1</b>");
c = c.replace(/'''''(.*?)'''''/g, "<b>$1</b>");
form.appendChild(content);
content.innerHTML = c;
form.appendChild(content);
}
// Change the display
......@@ -362,8 +382,15 @@
amResult = amResult.replace(/\%group/g, am.group!=0 ? templateGroup.replace(/\%group/g, groups[am.group]) : "");
amResult = amResult.replace(/\%article/g, am.article);
amResult = amResult.replace(/\%color/g, colors[am.value]);
amResult = amResult.replace(/\%left/g, am.left);
amResult = amResult.replace(/\%right/g, am.right);
var table = "";
for (var j = 0; j < am.table.length; j++)
{
var style = am.table.length==1 ? 0 : j == 0 ? 1 : j != am.table.length-1 ? 2 : 3;
table += templateTable.replace(/\%left/g, am.table[j].left).replace(/\%right/g, am.table[j].right).replace(/\%style/g, tableStyle[style]);
}
amResult = amResult.replace(/\%table/g, table);
amResult = amResult.replace(/\%justif/g, am.justif!="" ? templateJustif.replace(/\%justif/g, am.justif) : "");
amResult = amResult.replace(/\%comment/g, am.comment!="" ? templateComment.replace(/\%comment/g, am.comment) : "");
......@@ -503,4 +530,3 @@
</style>
</html>
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