Skip to content

Instantly share code, notes, and snippets.

from collections import Counter
import glob
import os
import xml.etree.ElementTree as ET
# from lxml import etree as ET
import yaml
CSL_STYLES_DIR = '../styles'
NSMAP = {'cs': ''}
bdarcus /
Created June 9, 2023 21:14 — forked from chux0519/
multi level sort in rust
/// Multi-level sort a slice of Foobars according to [(field, reverse)]
fn sort_by_names(f: &mut [Foobar], orderings: &[(Foofields, bool)]) {
use std::cmp::Ordering;
f.sort_by(|a, b| {
let mut cmp = Ordering::Equal;
for (field, reverse) in orderings {
if cmp != Ordering::Equal {
bdarcus / apa1.yaml
Last active May 24, 2023 23:46
apa.csl xml converted to YAML with yq
View apa1.yaml
+p_xml: version="1.0" encoding="utf-8"
class: in-text
version: "1.0"
demote-non-dropping-particle: never
page-range-format: expanded
title: American Psychological Association 7th edition
bdarcus / csl-next-style.go
Created May 24, 2023 01:06
converted from typescript style model to go, using quicktype
View csl-next-style.go
// This file was generated from JSON Schema using quicktype, do not modify it directly.
// To parse and unparse this JSON data, add this code to your project and do:
// localizationTerms, err := UnmarshalLocalizationTerms(bytes)
// bytes, err = localizationTerms.Marshal()
// lang, err := UnmarshalLang(bytes)
// bytes, err = lang.Marshal()
// localizedTermName, err := UnmarshalLocalizedTermName(bytes)
bdarcus / unique-macro-names.yaml
Last active May 11, 2023 00:19
CSL macro names across all files in the central style repository
View unique-macro-names.yaml
- author-short
- author-short-bibliography
- author
- editor-translator
- container-title
- edition
- journal-details
- pages
- title
- year-date
bdarcus / pre-commit
Created May 9, 2023 23:35
pre-commit hook to only run a check on staged files
View pre-commit
fileList=$(git diff --diff-filter=d --cached --name-only)
includeFileList=$(echo "$fileList" | grep -E '\.(ts)$')
if [ ${#includeFileList} -gt 0 ]; then
if ! deno fmt --check ${includeFileList[*]} "$@"; then
echo "$PREFIX Commit aborted."
View locale-en-US.json
"locale": {
"xmlns": "",
"version": "1.0",
"xml:lang": "en-US",
"info": {
"translator": [
{"name": "Andrew Dunning"},
{"name": "Sebastian Karcher"},
{"name": "Rintze M. Zelle"},
bdarcus / schemas.xml
Last active April 5, 2023 13:24
nxml locating rules for CSL
View schemas.xml
<?xml version="1.0"?>
<locatingRules xmlns="">
<uri pattern="*.csl" typeId="CSL"/>
<namespace ns="" typeId="CSL"/>
<typeId id="CSL" uri="~/Code/csl/schemas/schemas/csl.rnc"/>
bdarcus / bibreference.yaml
Last active March 1, 2023 00:38
BibLaTeX Reference JSON/YAML Schema
View bibreference.yaml
$ref: '#/definitions/bibreference'
type: object
additionalProperties: false
type: string
bdarcus / bib2bltx
Last active February 27, 2023 12:10
View bib2bltx
#!/bin/env bash
# use biber to handle conversion, but ensure input is utf-8 first
iconv -t utf-8 "${1}"
biber --tool --tool-fieldcase='lower' --quiet -O "${1}" "${1}"
# tidy the final file
bibtex-tidy --sort-fields --curly --numeric --align=13 --sort=key --duplicates=key --no-escape --no-remove-dupe-fields --generate-keys="[auth:required:lower][year:required]" ${1}