-
Notifications
You must be signed in to change notification settings - Fork 0
/
pattern.html
85 lines (75 loc) · 1.68 KB
/
pattern.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Pattern</title>
<style type="text/css">
</style>
<script src="https://code.jquery.com/jquery-2.2.4.js"></script>
<script>
function tsv_to_array()
{
var i= 0;
myarray= $('#source').val().trim().split("\n");
//console.log(myarray);
while(i< myarray.length)
{
myarray[i]= myarray[i].trim().split("\t");
i++;
}
}
function replace_var()
{
tsv_to_array();
var tmp= $('#modele').val();
var res="";
var i=1;
var j=0;
while(i< myarray.length)
{
tampon=tmp;
while(j< myarray[0].length)
{
value_replace= myarray[i][j];
if(typeof value_replace=='undefined')
{
value_replace= "";
}
tampon=tampon.replace( new RegExp('\{'+myarray[0][j]+'\}', 'g') ,value_replace);
j++;
}
j=0;
i++;
res+=tampon+"\n\n";
}
return res;
}
function resultat()
{
$('#result').val(replace_var());
}
$( document ).ready(function() {
replace_var();
});
</script>
</head>
<body>
<p>tsv</p>
<textarea id='source' rows="4" cols="60" >
entete1 entete2 entete3
value1 value2 value3
value4 value5 value6
</textarea>
<p>model</p>
<textarea id="modele" rows="4" cols="60">
ceci est un exemple avec les variables {entete1} {entete2}
{entete3} {entete1}
</textarea>
<p>result</p>
<textarea id="result" rows="8" cols="60">
</textarea>
<br>
<input type='button' value='Go!' onclick="resultat()">
</body>
</html>