Skip to content

Instantly share code, notes, and snippets.

@badp
Created April 2, 2011 12:45
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/899466 to your computer and use it in GitHub Desktop.
Save badp/899466 to your computer and use it in GitHub Desktop.
Embiggen the awesome of your text dissertations through ligature abuse
#/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", "ᵫ"),
("ffi", "ffi"),
("ffl", "ffl"),
("ff", "ff"),
("IJ", "IJ"),
("ij", "ij"),
("fi", "fi"),
("fl", "fl"),
("ft", "ſt"),
("OI", "Ƣ"),
("oi", "ƣ"),
("IJ", "IJ"),
("ij", "ij"),
("qp", "ȹ"),
("st", "st"),
("ſt", "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"),
]
def ligaturify(text):
"""Replace a number of character combinations with ligatures and digrams thereof.
>>> ligaturify("Officially dissatisfied staff. Afflato floreale.")
'Officially dissatisfied staff. Afflato floreale.'
"""
for replacement_list in [ligatures, digraphs]:
for letters, replacement in replacement_list:
text = text.replace(letters, replacement)
return text
if __name__ == "__main__":
import doctest
doctest.testmod()
text = input("Ligaturify what? ")
print(ligaturify(text))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment