2019-11-11 13:46:51 -06:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
# encoding: UTF-8
|
|
|
|
# coding: UTF-8
|
|
|
|
|
|
|
|
require 'fileutils'
|
|
|
|
|
|
|
|
# Variables
|
|
|
|
tesis = 'tesis.md'
|
|
|
|
|
|
|
|
# Lee el archivo de la tesis
|
|
|
|
md = File.read('../md/' + tesis)
|
|
|
|
|
|
|
|
# Limpia la tesis
|
|
|
|
clean = md.gsub(/\+{2,}/, '')
|
2019-11-26 10:27:31 -06:00
|
|
|
.gsub(/\s+{\s*.frances\s*}/, '')
|
2019-11-11 13:46:51 -06:00
|
|
|
.gsub(/@\w+cite\[[^\[]+\]/, ) do |e|
|
|
|
|
# Obtiene tipo de cita y referencias
|
|
|
|
type = e.gsub(/@(\w+)cite\[(.|\n)*$/, '\1')
|
|
|
|
refs = e.gsub(/^.*?\[/, '')
|
|
|
|
.gsub(']', '')
|
|
|
|
.split(/,\s*/)
|
|
|
|
out = []
|
|
|
|
|
|
|
|
# Iteración de las referencias
|
|
|
|
refs.each do |r|
|
|
|
|
name = r.gsub(/\d+\w/, '').capitalize
|
|
|
|
year = r.gsub(/\D+/, '')
|
|
|
|
|
|
|
|
# Formato según si es cita textual o en paréntesis
|
|
|
|
if type == 'text'
|
|
|
|
out.push(name + ' (' + year + ')')
|
|
|
|
else
|
|
|
|
out.push(name + ', ' + year)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Unión de referencias según el tipo de cita
|
|
|
|
if type == 'text'
|
|
|
|
out = out.join(', ')
|
|
|
|
else
|
|
|
|
out = '(' + out.join('; ') + ')'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Guarda la tesis
|
|
|
|
file = File.open(tesis, 'w:utf-8')
|
|
|
|
file.puts clean
|
|
|
|
file.close
|
|
|
|
|
|
|
|
# Convierte a DOCX
|
|
|
|
system("pandoc -V lang:es #{tesis} -o #{File.basename(tesis, '.md')}.docx")
|
|
|
|
|
|
|
|
# Elimina MD
|
|
|
|
FileUtils.rm(tesis)
|