<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" rel="stylesheet">
<title>BibTeX 到自定义格式转换器</title>
</head>
<body class="bg-gray-100 font-sans">
<div class="container mx-auto p-8">
<div class="bg-white p-6 rounded-md shadow-md">
<h2 class="text-xl font-bold mb-4">输入 BibTeX</h2>
<textarea id="bibtex-input" class="w-full h-48 border border-gray-300 p-2 rounded-md resize-none">@inproceedings{
hendrycks2021measuring,
title={Measuring Massive Multitask Language Understanding},
author={Dan Hendrycks and Collin Burns and Steven Basart and Andy Zou and Mantas Mazeika and Dawn Song and Jacob Steinhardt},
booktitle={International Conference on Learning Representations},
year={2021},
url={https://openreview.net/forum?id=d7KBjmI3GmQ}
}</textarea>
<button id="convert-button"
class="mt-4 bg-blue-500 text-white py-2 px-4 rounded-md hover:bg-blue-600 transition duration-300">转换</button>
</div>
<div class="mt-8 bg-white p-6 rounded-md shadow-md">
<h2 class="text-xl font-bold mb-4">输出自定义格式</h2>
<textarea id="output" class="w-full h-48 border border-gray-300 p-2 rounded-md resize-none" readonly></textarea>
</div>
</div>
<script>
document.getElementById('convert-button').addEventListener('click', () => {
const bibtex = document.getElementById('bibtex-input').value;
const lines = bibtex.split('\n');
let currentEntry = {};
let inEntry = false;
lines.forEach(line => {
if (line.trim().startsWith('@')) {
inEntry = true;
currentEntry = {};
} else if (line.trim() === '}') {
inEntry = false;
} else if (inEntry) {
const parts = line.split('=');
if (parts.length === 2) {
const key = parts[0].trim();
let value = parts[1].trim().replace(/[{},]/g, '').replace(/"/g, '');
currentEntry[key] = value;
}
}
});
const authorList = currentEntry.author ? currentEntry.author.split(' and ') : [];
let authorStr = '';
if (authorList.length > 3) {
authorStr = authorList.slice(0, 3).map(author => {
const parts = author.split(' ');
const lastName = parts.pop();
const initials = parts.map(name => name[0]).join('');
return `${lastName} ${initials}`;
}).join(', ') + ', et al.';
} else {
authorStr = authorList.map(author => {
const parts = author.split(' ');
const lastName = parts.pop();
const initials = parts.map(name => name[0]).join('');
return `${lastName} ${initials}`;
}).join(', ');
}
const title = currentEntry.title ? currentEntry.title.replace(/[{}]/g, '') : 'unknown';
const booktitle = currentEntry.booktitle || 'unknown';
const year = currentEntry.year || 'unknown';
const output = `${authorStr}. ${title}[C]//${booktitle}. ${year}.`;
document.getElementById('output').value = output;
});
</script>
</body>
</html>
BibTeX转化为默认格式
最新推荐文章于 2025-05-01 20:06:47 发布