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': 'http://purl.org/net/xbiblio/csl'}
@bdarcus
bdarcus / multi-level-sort.rs
Created June 9, 2023 21:14 — forked from chux0519/multi-level-sort.rs
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 {
break;
}
@bdarcus
bdarcus / apa1.yaml
Last active May 24, 2023 23:46
apa.csl xml converted to YAML with yq
----
+p_xml: version="1.0" encoding="utf-8"
style:
xmlns: http://purl.org/net/xbiblio/csl
class: in-text
version: "1.0"
demote-non-dropping-particle: never
page-range-format: expanded
info:
title: American Psychological Association 7th edition
@bdarcus
bdarcus / csl-next-style.go
Created May 24, 2023 01:06
converted from typescript style model to go, using quicktype
// 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
bdarcus / unique-macro-names.yaml
Last active May 11, 2023 00:19
CSL macro names across all files in the central style repository
- author-short
- author-short-bibliography
- author
- editor-translator
- container-title
- edition
- journal-details
- pages
- title
- year-date
@bdarcus
bdarcus / pre-commit
Created May 9, 2023 23:35
pre-commit hook to only run a check on staged files
#!/bin/sh
PREFIX="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."
{
"locale": {
"xmlns": "http://purl.org/net/xbiblio/csl",
"version": "1.0",
"xml:lang": "en-US",
"info": {
"translator": [
{"name": "Andrew Dunning"},
{"name": "Sebastian Karcher"},
{"name": "Rintze M. Zelle"},
@bdarcus
bdarcus / schemas.xml
Last active April 5, 2023 13:24
nxml locating rules for CSL
<?xml version="1.0"?>
<locatingRules xmlns="http://thaiopensource.com/ns/locating-rules/1.0">
<uri pattern="*.csl" typeId="CSL"/>
<namespace ns="http://purl.org/net/xbiblio/csl" typeId="CSL"/>
<typeId id="CSL" uri="~/Code/csl/schemas/schemas/csl.rnc"/>
</locatingRules>
@bdarcus
bdarcus / bibreference.yaml
Last active March 1, 2023 00:38
BibLaTeX Reference JSON/YAML Schema
$schema: http://json-schema.org/draft-06/schema#
$ref: '#/definitions/bibreference'
definitions:
bibreference:
type: object
additionalProperties: false
properties:
author:
type: string
bookauthor:
@bdarcus
bdarcus / bib2bltx
Last active February 27, 2023 12:10
#!/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}