Skip to content

Instantly share code, notes, and snippets.

@badp
Created June 21, 2010 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save badp/446542 to your computer and use it in GitHub Desktop.
Save badp/446542 to your computer and use it in GitHub Desktop.
Put ligatures where possible. Save characters.
#/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
if sys.version_info < (3,):
raise Exception("This requires Python 3 to run. Sorry.")
ligatures = { "db": "ȸ",
"AE": "Æ",
"ae": "æ",
"OE": "Œ",
"oe": "œ",
"ue": "ᵫ",
"ff": "ff",
"IJ": "IJ",
"ij": "ij",
"fi": "fi",
"fl": "fl",
"ffi": "ffi",
"ffi": "ffi",
"ffi": "ffi",
"ffl": "ffl",
"ffi": "ffl",
"ffl": "ffl",
"ffl": "ffl",
"ft": "ſt",
"OI": "Ƣ",
"oi": "ƣ",
"IJ": "IJ",
"ij": "ij",
"qp": "ȹ",
"st": "st",
}
additional_ligatures = { "et": "&",
"SS": "ẞ",
"ss": "ß",
}
digraphs = { "DZ": "DZ",
"Dz": "Dz",
"dz": "dz",
"DŽ": "DŽ",
"Dž": "Dž",
"dž": "dž",
"LJ": "LJ",
"Lj": "Lj",
"lj": "lj",
"NJ": "NJ",
"Nj": "Nj",
"nj": "nj",
}
text = sys.stdin.read()
for replacement_list in [ligatures, digraphs]:
for letters, replacement in replacement_list.items():
text = text.replace(letters, replacement)
sys.stdout.write(text)
@badp
Copy link
Author

badp commented Jun 21, 2010

Code is formatted to be best seen with elastic tabstops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment