所以这就是问题所在。
我有一个Google Apps脚本程序,它由两部分组成:
重要的是要知道该程序在用户的Google云端硬盘上生成一个名为'新文档'的新Google文档,该文档将包含原始文档中的相同文本,但每个 \引用{id} 替换为 [id] 并删除 \ bibliography 并添加引用部分。
这是 Sidebar.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
<!-- The CSS package above applies Google styling to buttons and other elements. -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.js"></script>
<style>
div.success {
padding-top: 10px;
color: green;
}
select.select_style{
padding-top: 10px;
}
div.error {
padding-top: 10px;
}
#select_file {
text-align: left;
width: 95%;
font-size: 1em;
margin: auto;
height: 3em;
}
.branding-below {
bottom: 56px;
top: 0;
}
.branding-text {
left: 7px;
position: relative;
top: 3px;
}
.col-contain {
overflow: hidden;
}
.col-one {
float: left;
width: 50%;
}
.logo {
vertical-align: middle;
}
.radio-spacer {
height: 20px;
}
.width-100 {
width: 100%;
}
</style>
</head>
<body>
<div class="sidebar branding-below">
<form>
<div class="block form-group">
<label for="select_file">Selecciona el documento bibtex:</label>
<br>
<select id="select_file" name="select_file"></select>
<p><b id="tittle" ></b></p>
<p id="id"></p>
</div>
<div class="block form-group">
<label for="select_style">Selecciona el estilo para la Bibliografía:</label>
<br>
<select id="select_style" name="select_style">
<option value="unsrt">unsrt</option>
</select>
</div>
<!-- <div class="block form-group">
<label for="text"><b>Prueba:</b></label>
<textarea class="width-100" id="text" name="text" rows="15"></textarea>
</div> -->
<div class="block" id="button-bar">
<button class="blue" id="combinar">Combinar documentos</button>
<input type="reset" id="reset" value="Resetear formulario">
</div>
</form>
</div>
<div class="sidebar bottom">
<img alt="Add-on logo" class="logo" src="https://www.gstatic.com/images/branding/product/1x/translate_48dp.png" width="27" height="27">
<span class="gray branding-text">ALPHA</span>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
var alldata = {};
/**
* On document load, assign click handlers to each button and try to load the
* user's origin and destination language preferences if previously set.
*/
$(function() {
$('#combinar').click(openDoc);
});
$(function() {
$('#reset').click(resetValues);
});
$(function() {
google.script.run.withSuccessHandler(importData).getFiles("root");
$('#select_file').change(function() {
var id = $('#select_file').val();
var disp = $('#select_file option:selected').text();
if (~disp.indexOf("Folder") || ~disp.indexOf("../")) {
$('#select_file > option').remove();
if (alldata[id]) {
var dat = {};
dat[id] = alldata[id];
importData(dat);
return;
} else {
google.script.run.withSuccessHandler(importData).getFiles(id);
return;
}
return;
}
});
});
function importData(e) {
var key = Object.keys(e)[0];
if (!alldata[key]) alldata[key] = e[key];
if (e[key]["keyparent"]) {
$('#select_file').append($('<option>').html("./" + e[key]["keyname"]).val(key));
$('#select_file').append($('<option>').html("../").val(e[key]["keyparent"]));
} else {
$('#select_file').append($('<option>').html("./" + e[key]["keyname"]).val(key));
}
for (var i=0; i < e[key]["files"].length; i++) {
$('#select_file').append($('<option>')
.html(e[key]["files"][i].mimeType == "folder" ? "[Folder]" + e[key]["files"][i].name : e[key]["files"][i].name)
.val(e[key]["files"][i].id)
);
}
}
function openDoc(){
$("#success").remove();
this.disabled = true;
$('#error').remove();
var style = $('#select_style').val();
var id = $('#select_file').val();
google.script.run
.withSuccessHandler(
function(exitoBibtex, element) {
if(exitoBibtex){
var msg = "Comprueba el nuevo documento que se ha creado en tu Drive con nombre: New Document";
showSuccess(msg, $('#button-bar'));
}else{
var msg = "Hubo algun error durante el proceso. Es posible que en tu .bib falte algún campo obligatorio en alguna entrada o no hayas añadido el \bibliography para insertar la sección References.";
showError(msg, $('#button-bar'));
}
element.disabled = false;
})
.withFailureHandler(
function(msg, element) {
msg = "Hubo un problema durante el proceso.Comprueba que hayas seleccionado el documento correcto.";
showError(msg, $('#button-bar'));
element.disabled = false;
})
.withUserObject(this)
.getBibtexAndDoc(id,style);
}
function resetValues() {
document.getElementById("id").innerHTML = "";
document.getElementById("tittle").innerHTML = "";
}
/*function runCombination() {
this.disabled = true;
$('#error').remove();
google.script.run
.withSuccessHandler(
function(msg, element) {
openDoc();
element.disabled = false;
})
.withFailureHandler(
function(msg, element) {
showError(msg, $('#button-bar'));
element.disabled = false;
})
.withUserObject(this)
.getText();
}*/
function showError(msg, element) {
var div = $('<div id="error" class="error">' + msg + '</div>');
$(element).after(div);
}
function showSuccess(msg, element) {
var div = $('<div id="success" class="success">' + msg + '</div>');
$(element).after(div);
}
</script>
</body>
</html>
由于 Codigo.gs 文件的大小很大,通过点击此链接到GitHub,您将能够看到代码GitHub Project。
现在,我的问题是:
如何让程序接受的不只是一个.bib文件?问题是如果我有一些引用只是在一个.bib文件和一些其他引用存在于不同的.bib文件中引用,所以目标是能够选择多个.bib文件并查找引用在两个.bib文件中。
感谢您阅读整个问题。