Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
piks3l
am2wiki
Commits
ae1391f2
Commit
ae1391f2
authored
Apr 12, 2017
by
piks3l
Browse files
adding code
parents
Changes
1
Hide whitespace changes
Inline
Side-by-side
am2wiki.html
0 → 100644
View file @
ae1391f2
<!DOCTYPE html>
<html>
<head>
<title>
Am2Wiki
</title>
<meta
charset=
"UTF-8"
>
</head>
<!--
Am2Wiki by Oncela
Last modification: 12-04-2017
This program intends to convert amendments drafted by Members of European
Parliament into reusable formats.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. Get a copy of the GNU General
Public License at <http://www.gnu.org/licenses/>.
-->
<!----- For users ----->
<script>
// Colors and symbols used to rate the amendments (you can add or remove some)
var
rates
=
[
"
unrated
"
,
"
--
"
,
"
-
"
,
"
/
"
,
"
+
"
,
"
++
"
];
var
colors
=
[
"
white
"
,
"
#A60000
"
,
"
#F55E33
"
,
"
#BABABA
"
,
"
#AEF279
"
,
"
#44C92C
"
];
// Template for conversion (how the amendments are displayed once processed: you can change it at will)
/*
%number = amendmend number
%rate = amendment rating
%article = amended article
%color = amendment color (according to its rating)
%left = original text
%right = amended text
%comment = comment, if any
*/
var
template
=
"
=== %number %rate ===
\n
"
+
"
\n
"
+
"
{| border='1' style='border-spacing:0;' cellpadding='30'
\n
"
+
"
|-
\n
"
+
"
| colspan='2' style='background-color: %color; text-align:center;' |
\n
"
+
"
'''%number'''<br/>
\n
"
+
"
%article
\n
"
+
"
|-
\n
"
+
"
|width='50%' style='vertical-align:top;'|
\n
"
+
"
%left
\n
"
+
"
|width='50%' style='vertical-align:top;'|
\n
"
+
"
%right
\n
"
+
"
%comment
"
// If the amendment is commented, the templateComment (defined bellow) is inserted here
+
"
|}
\n\n\n
"
;
var
templateComment
=
"
|-
\n
"
+
"
| colspan='2' |
\n
"
+
"
'''Comment:''' %comment
\n
"
;
</script>
<!----- HTML ----->
<body>
<!-- Title -->
<div
id=
"title"
>
Am2Wiki
</div>
<!-- Instructions (change during processing) -->
<div
id=
"intro"
>
Select an HTML document containing EP amendments:
<br/><br/></div>
<!-- File selector (disappears once a file is selected) -->
<input
id =
"input"
type=
"file"
onchange=
"read(this.files[0])"
>
<!-- After processing, contains the checkboxes used for rating the amendments -->
<div
id=
"form"
></div>
<!-- Button opening the output box (appears after processing) -->
<div
id=
"wikify"
onclick=
"convert()"
>
Convert
</div>
<!-- The output box -->
<div
id=
"output"
>
<textarea></textarea>
<div
id=
"refresh"
onclick=
"convert();"
>
Refresh
</div>
<div
id=
"close"
onclick=
"this.parentNode.style.display='none';"
>
Close
</div>
</div>
<!-- Hidden buffer used for DOM manipulation (deleted after processing) -->
<div
id=
"buffer"
></div>
</body>
<!----- Javascript ----->
<script>
// Array of the processed amendments
var
amendments
=
[];
// Open and read the file selected by the user
function
read
(
file
)
{
// Change the info displayed on the page
document
.
getElementById
(
'
input
'
).
style
.
display
=
"
none
"
;
document
.
getElementById
(
'
intro
'
).
innerHTML
=
"
Loading...
"
;
// Open and read the file
var
reader
=
new
FileReader
();
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
)
var
buffer
=
document
.
getElementById
(
'
buffer
'
);
buffer
.
innerHTML
=
file
;
// Simplify 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
];
// Replace HTML by wiki
tr
.
innerHTML
=
tr
.
innerHTML
.
replace
(
/
(
<i>
\n?
<b>
)
|
(
<
\/
b>
\n?
<
\/
i>
)
/gm
,
"
'''''
"
);
// Create a simplified table
var
newTable
=
document
.
createElement
(
"
p
"
);
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
]);
}
// Remove HTML from the file
var
cleanFile
=
""
;
elements
=
buffer
.
getElementsByTagName
(
"
p
"
);
for
(
var
i
=
0
;
i
<
elements
.
length
;
i
++
)
{
cleanFile
+=
elements
[
i
].
innerText
;;
}
// Delete the buffer
buffer
.
parentNode
.
removeChild
(
buffer
);
// Remove tabs and new-lines
cleanFile
=
cleanFile
.
replace
(
/
\t
/g
,
"
"
);
cleanFile
=
cleanFile
.
replace
(
/
\n
/g
,
"
"
);
while
(
cleanFile
.
search
(
/ /g
)
>
-
1
)
cleanFile
=
cleanFile
.
replace
(
/ /g
,
"
"
);
// Remove the begining of the file
cleanFile
=
cleanFile
.
replace
(
/^.*
?(
<NumAm>
)
/
,
"
$1
"
);
// Use the internal tags to retrieve the 4 relevant information for each amendment (number, article, left, right)
var
parser
=
[];
parser
[
0
]
=
cleanFile
.
match
(
/<NumAm>.*
?
<
\/
NumAm> *<RepeatBlock-By>/g
);
parser
[
1
]
=
cleanFile
.
match
(
/<
\/
DocAmend> *<Article>.*
?
<
\/
Article> *
\[\[
/g
);
parser
[
2
]
=
cleanFile
.
match
(
/
\[\[
.*
?\|\|
/g
);
parser
[
3
]
=
cleanFile
.
match
(
/
\|\|
.*
?\]\]
/g
);
// Put the information into the amendments array
for
(
var
i
=
0
;
i
<
parser
[
0
].
length
;
i
++
)
{
var
am
=
{};
am
.
number
=
parser
[
0
][
i
].
replace
(
/<NumAm> *
(
.*
?)
*<
\/
NumAm> *<RepeatBlock-By>/
,
"
Amendment $1
"
);
am
.
article
=
parser
[
1
][
i
].
replace
(
/<
\/
DocAmend> *<Article> *
(
.*
?)
*<
\/
Article> *
\[\[
/
,
"
$1
"
);
am
.
left
=
parser
[
2
][
i
].
replace
(
/
\[\[
*
(
.*
?)
*
\|\|
/
,
"
$1
"
);
am
.
right
=
parser
[
3
][
i
].
replace
(
/
\|\|
*
(
.*
?)
*
\]\]
/
,
"
$1
"
);
am
.
comment
=
""
;
am
.
value
=
0
;
amendments
.
push
(
am
);
}
// Create the form
var
form
=
document
.
getElementById
(
'
form
'
);
// For each amendment
for
(
var
i
=
0
;
i
<
amendments
.
length
;
i
++
)
{
// Create a line
var
line
=
document
.
createElement
(
"
div
"
);
line
.
className
=
"
form_line
"
;
// Attribute the amendment to the line
line
.
am
=
amendments
[
i
];
// Display the amendmend number
var
span
=
document
.
createElement
(
'
span
'
);
span
.
className
=
"
form_am
"
;
span
.
innerHTML
=
amendments
[
i
].
number
;
line
.
appendChild
(
span
);
// Create the checkboxes
var
checkboxes
=
[];
// For each color
for
(
var
j
=
0
;
j
<
colors
.
length
;
j
++
)
{
// Create a background
var
span
=
document
.
createElement
(
'
span
'
);
span
.
className
=
"
form_radio
"
;
span
.
style
.
background
=
colors
[
j
];
// Create a checkbox
var
cb
=
document
.
createElement
(
'
input
'
);
cb
.
type
=
"
radio
"
;
cb
.
name
=
"
radio
"
+
i
;
cb
.
value
=
j
;
// On click, change the displayed color and the value of the amendment
cb
.
onclick
=
function
()
{
this
.
parentNode
.
parentNode
.
am
.
value
=
this
.
value
;
this
.
parentNode
.
parentNode
.
firstChild
.
style
.
background
=
colors
[
this
.
value
];
};
// By default, the first radio is checked
if
(
j
==
0
)
cb
.
checked
=
true
;
span
.
appendChild
(
cb
);
line
.
appendChild
(
span
);
}
// Create the input for adding a comment
var
comment
=
document
.
createElement
(
'
input
'
);
comment
.
type
=
"
text
"
;
comment
.
placeholder
=
"
Comment
"
comment
.
onchange
=
function
()
{
this
.
parentNode
.
am
.
comment
=
this
.
value
;
}
line
.
appendChild
(
comment
);
form
.
appendChild
(
line
);
}
// Change the display
document
.
getElementById
(
'
wikify
'
).
style
.
display
=
"
block
"
;
document
.
getElementById
(
'
intro
'
).
innerHTML
=
"
Rate each amendment (non-rated amendments won't be converted):<br/><br/>
"
;
}
// Convert and display the rated amendments
function
convert
()
{
var
result
=
""
;
// For each amendment
for
(
var
i
=
0
;
i
<
amendments
.
length
;
i
++
)
{
// Convert the amendment if rated
var
am
=
amendments
[
i
];
if
(
am
.
value
>
0
)
{
var
amResult
=
template
.
replace
(
/
\%
number/g
,
am
.
number
);
amResult
=
amResult
.
replace
(
/
\%
rate/g
,
rates
[
am
.
value
]);
amResult
=
amResult
.
replace
(
"
%article
"
,
am
.
article
);
amResult
=
amResult
.
replace
(
"
%color
"
,
colors
[
am
.
value
]);
amResult
=
amResult
.
replace
(
"
%left
"
,
am
.
left
);
amResult
=
amResult
.
replace
(
"
%right
"
,
am
.
right
);
amResult
=
amResult
.
replace
(
"
%comment
"
,
am
.
comment
!=
""
?
templateComment
.
replace
(
"
%comment
"
,
am
.
comment
)
:
""
);
result
+=
amResult
;
}
}
// Display the converted amendmends
var
output
=
document
.
getElementById
(
'
output
'
);
output
.
childNodes
[
1
].
value
=
result
;
output
.
style
.
display
=
"
block
"
;
}
</script>
<!----- CSS ----->
<style>
body
{
padding
:
2em
;
}
#title
{
font-size
:
2em
;
font-weight
:
bold
;
margin
:
1em
;
margin-top
:
0
;
color
:
#486A8C
;
}
.form_line
{
height
:
2.5em
;
}
.form_am
,
.form_radio
{
padding
:
.5em
;
}
.form_line
input
[
type
=
text
]
{
margin-left
:
1em
;
width
:
40em
;
}
#wikify
{
display
:
none
;
margin
:
2em
;
padding
:
1em
2em
;
position
:
fixed
;
top
:
2px
;
right
:
2px
;
border
:
1px
black
solid
;
cursor
:
pointer
;
background
:
white
;
font-weight
:
bold
;
}
#output
{
display
:
none
;
position
:
fixed
;
margin
:
2em
;
top
:
2px
;
right
:
2px
;
background
:
white
;
border
:
1px
solid
black
;
}
#output
textarea
{
width
:
30em
;
height
:
40em
;
margin-left
:
auto
;
margin-top
:
auto
;
border
:
none
;
}
#close
,
#refresh
{
padding
:
1em
2em
;
cursor
:
pointer
;
font-weight
:
bold
;
}
#refresh
{
border-bottom
:
1px
solid
black
;
border-top
:
1px
solid
black
;
}
#wikify
:hover
,
#close
:hover
,
#refresh
:hover
{
background
:
#E8E8E8
;
}
#buffer
{
display
:
none
;
}
</style>
</html>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment