csl-clio/Utilitaires/generer-md-pour-citeproc.sh
2021-09-26 12:21:16 +02:00

82 lines
3.1 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
BIBLIO_FILE="$1"
OUTPUT_FILE="$2"
printMetadata() {
echo '---' > "$OUTPUT_FILE"
echo "bibliography: $BIBLIO_FILE" >> "$OUTPUT_FILE"
echo "csl: $(ls | grep -E '.csl$')" >> "$OUTPUT_FILE"
echo '---' >> "$OUTPUT_FILE"
}
printReferences() {
inlineBaseText="$1"
refList="$2"
iCit=0
while read -r ref ; do
iCit=$(($iCit+1))
echo "" >> "$OUTPUT_FILE"
if [[ $(grep '_special' <<< "$ref") ]] ; then
case "$ref" in
*SourceWithInternalDivisions*) echo \
"Localisation dans une source dans une première citation par la référence \
aux divisions de la source et à la page dans la publication \
$iCit (\\$ref)[$ref, {section VI, 5, 4}, p. 57]" >> "$OUTPUT_FILE";;
*LivreMultivolumePourLocator*) echo \
"Localisation dans un ouvrage en plusieurs volumes \
$iCit (\\$ref)[$ref, {volume ii}, p. 56]" >> "$OUTPUT_FILE";;
*TheseLocatorVolume*) echo \
"Localisation dans une thèse ou un mémoire en plusieurs volumes \
$iCit (\\$ref)[$ref, {volume ii}, p. 56]" >> "$OUTPUT_FILE";;
esac
else
echo "$inlineBaseText $iCit (\\$ref)[$ref]" >> "$OUTPUT_FILE"
fi
done <<< "$refList"
}
printLocators() {
ref="$1"
for locator in 'livre' 'chapitre' 'colonne' 'figure' 'folio' 'numéro' 'ligne' 'note' 'opus' 'page' 'paragraphe' 'partie' 'section' 'sub verbo' 'verset' 'volume' ; do
echo "" >> "$OUTPUT_FILE"
echo "Un $locator[$ref, $locator 3]" >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
echo "Plusieurs $locator[$ref, $locator 3-5]" >> "$OUTPUT_FILE"
done
for locator in 'l. ' ; do
echo "" >> "$OUTPUT_FILE"
echo "Un $locator[$ref, {p. 3}, ${locator}3]" >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
echo "Plusieurs $locator[$ref, {p. 4}, ${locator}3-5]" >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
echo "Plusieurs $locator dans la même page que le précédent[$ref, {p. 4}, ${locator}9-10]" >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
echo "Une source dont on indique la section où se trouve la citation[@SourceLivreSimple, {section VI, 5, 3}, p. 56]" >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
echo "Même chose en _ibidem_[@SourceLivreSimple, {section VI, 5, 3}, p. 56]" >> "$OUTPUT_FILE"
done
}
printMultipleCitations() {
ref1="$1"
ref2="$2"
echo "" >> "$OUTPUT_FILE"
echo "Citation multiple[$ref1; $ref2]" >> "$OUTPUT_FILE"
}
if [[ ! $# -eq 2 || "${BIBLIO_FILE##*.}" != json || "${OUTPUT_FILE##*.}" != md ]] ; then
echo 'Syntaxe : ./generer-md-pour-citeproc.sh fichierBiblio.json fichierCitations.md'
exit 1
fi
refList="$(while read -r rawRef ; do
echo @"$rawRef"
done <<< $(grep -oE '"note": "id: [^\\"]+' < "$BIBLIO_FILE" | cut -d ' ' -f 3))"
printMetadata
printReferences "Première citation" "$refList"
printReferences "Deuxième citation" "$refList"
printLocators "$(sed -n 1p <<< $refList)"
printMultipleCitations "$(sed -n 1p <<< $refList)" "$(sed -n 2p <<< $refList)"