-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
145 lines (135 loc) · 4.37 KB
/
demo.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BibTeX Viewer</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/he/1.2.0/he.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f4f4f4;
}
.error {
color: red;
font-weight: bold;
}
</style>
</head>
<body>
<h1>BibTeX Viewer</h1>
<div id="loading">Loading...</div>
<div id="content" style="display: none;">
<table>
<thead>
<tr>
<th>Title</th>
<th>Author</th>
<th>Year</th>
</tr>
</thead>
<tbody id="bibtex-table-body">
<!-- Entries will be added here -->
</tbody>
</table>
</div>
<div id="error-message" class="error" style="display: none;">Error loading BibTeX file.</div>
<script>
// Ruta al archivo BibTeX
const bibFilePath = "assets/bibfiles/journal.bib";
// Función para decodificar caracteres LaTeX
function decodeLatex(text) {
if (!text) return text; // Manejo de texto nulo o vacío
return text
.replace(/\\'a/g, "á")
.replace(/\\'e/g, "é")
.replace(/\\'i/g, "í")
.replace(/\\'o/g, "ó")
.replace(/\\'u/g, "ú")
.replace(/\\~n/g, "ñ")
.replace(/\\'A/g, "Á")
.replace(/\\'E/g, "É")
.replace(/\\'I/g, "Í")
.replace(/\\'O/g, "Ó")
.replace(/\\'U/g, "Ú")
.replace(/\\~N/g, "Ñ")
.replace(/\\`a/g, "à")
.replace(/\\`e/g, "è")
.replace(/\\`i/g, "ì")
.replace(/\\`o/g, "ò")
.replace(/\\`u/g, "ù")
.replace(/\\\^a/g, "â")
.replace(/\\\^e/g, "ê")
.replace(/\\\^i/g, "î")
.replace(/\\\^o/g, "ô")
.replace(/\\\^u/g, "û")
.replace(/\\\"a/g, "ä")
.replace(/\\\"e/g, "ë")
.replace(/\\\"i/g, "ï")
.replace(/\\\"o/g, "ö")
.replace(/\\\"u/g, "ü")
.replace(/\\\"A/g, "Ä")
.replace(/\\\"E/g, "Ë")
.replace(/\\\"I/g, "Ï")
.replace(/\\\"O/g, "Ö")
.replace(/\\\"U/g, "Ü")
.replace(/\\ss/g, "ß")
.replace(/\\\\/g, "\\"); // Finalmente, decodifica barras invertidas dobles
}
// Función para leer y procesar el archivo BibTeX
async function loadBibtex() {
try {
const response = await fetch(bibFilePath);
if (!response.ok) throw new Error("Failed to load BibTeX file");
const bibtexData = await response.text();
processBibtex(bibtexData);
} catch (error) {
document.getElementById("loading").style.display = "none";
document.getElementById("error-message").style.display = "block";
console.error(error);
}
}
// Función para procesar el contenido BibTeX
function processBibtex(data) {
const entries = data.split("@article").slice(1); // Divide por entradas de artículos
const tableBody = document.getElementById("bibtex-table-body");
entries.forEach((entry) => {
const titleMatch = entry.match(/title\s*=\s*[{"]([^"}]*)[}"]/i);
const authorMatch = entry.match(/author\s*=\s*[{"]([^"}]*)[}"]/i);
const yearMatch = entry.match(/year\s*=\s*[{"]?(\d{4})[}"']?/i);
const title = titleMatch ? decodeLatex(titleMatch[1].trim()) : "No Title";
const author = authorMatch ? decodeLatex(authorMatch[1].trim()) : "No Author";
const year = yearMatch ? yearMatch[1].trim() : "No Year";
// Verifica si los datos tienen errores obvios
if (title.includes("{") || author.includes("{")) {
console.warn("Possibly malformed entry:", { title, author, year });
}
const row = document.createElement("tr");
row.innerHTML = `
<td>${title}</td>
<td>${author}</td>
<td>${year}</td>
`;
tableBody.appendChild(row);
});
document.getElementById("loading").style.display = "none";
document.getElementById("content").style.display = "block";
}
// Llama a la función para cargar el archivo BibTeX
loadBibtex();
</script>
</body>
</html>