Package: texthooks
texthooksA collection ofpre-commithooks for handling text files.In particular, hooks for handling unicode characters which may be undesirable
in a repository.Usage with pre-commitTo use withpre-commit, include this repo and the desired hooks in.pre-commit-config.yaml:-repo:https://github.com/sirosen/texthooksrev:0.6.4hooks:-id:alphabetize-codeowners-id:fix-smartquotes-id:fix-ligaturesStandalone UsageEach hook is usable as a CLI script. Simplypipinstalltexthooksand then invoke, e.g.fix-smartquotesFILENAMEHook SummaryHookDescriptionalphabetize-codeownersAlphabetize names in CODEOWNERS files.fix-smartquotesReplace curly quotes with ASCII quotes.fix-spacesNormalize special space markers to ASCII spaces.fix-ligaturesConvert stylistic ligatures to ASCII text.forbid-bidi-controlsCheck for bi-directional text.macro-expandA simple way to write text formatting macros.Supported Hooksalphabetize-codeownersNormalizeCODEOWNERSfiles to always list people and teams in the same order
by alphabetizing.The default hook targetsCODEOWNERS,.github/CODEOWNERS, anddocs/CODEOWNERS.Sorts Owners, Not Linesalphabetize-codeownersalphabetizes the lists ofownersper path.
It does not alphabetize the lines in the file or otherwise sort them.Ignores Comments and Empty LinesAny comment lines or empty lines should be left unmodified by the hook.Normalizes WhitespaceOn the lines which are modified, the hook will normalize the line to have no
leading whitespace, and to separate codeowner names with a single space
character.fix-smartquotesThis fixes copy-paste from some applications which replace double-quotes with curly
quotes.
It doesnotconvert corner brackets, braile quotation marks, or angle
quotation marks. Those characters are not typically the result of copy-paste
errors, so they are allowed.Low quotation marks vary in usage and meaning by language, and some languages
use quotation marks which are facing "outwards" (opposite facing from english).
For the most part, these and exotic characters (double-prime quotes) are
ignored.In files with the offending marks, they are replaced and the run is marked as
failed.Overriding Quotation CharactersTwo options are available for specifying exactly which characters will be
replaced. For ease of use, they are specified as hex-encoded unicode
codepoints.Suppose you wanted toavoidreplacing the "Heavy single comma quotation
mark ornament" (275C) and the "Heavy single turned comma quotation mark
ornament" (275B) characters. You could override the single quote codepoints
as follows:-repo:https://github.com/sirosen/texthooksrev:0.6.4hooks:-id:fix-smartquotes# replace default single quote chars with this set:# apostrophe, fullwidth apostrophe, left single quote, single high# reversed-9 quote, right single quoteargs:["--single-quote-codepoints","0027,FF07,2018,201B,2019"]fix-spacesReplace various unicode space characters with" ".This normalizes No-Break Space and similar characters to ensure that your files
render the same way in all contexts. It does not modify newlines, carriage
returns, or other whitespace characters outside of the Space Separator
category.Overriding Space CharactersAn option is available for specifying exactly which characters will be
replaced. For ease of use, they are specified as hex-encoded unicode
codepoints.Suppose you wanted toonlyreplace Thin Space (codepoint2009).
You could override the space codepoints as follows:-repo:https://github.com/sirosen/texthooksrev:0.6.4hooks:-id:fix-spacesargs:["--separator-codepoints","2009"]fix-ligaturesAutomatically find and replace ligature characters with their ascii equivalents.This replaces liguatures which may be created by programs like LaTeX for
presentation with their strictly-equivalent ASCII counterparts. For example,fiandffmay be ligature-ized.This hook converts these back into ASCII so that tools likegrepwill behave
as expected.forbid-bidi-controlsThis is checker which forbids the use of unicode bidirectional text control
characters.These are directional formatting characters which can be used to construct text
with unexpected or unclear semantics. For example, in programming languages
which allow bidirectional text in statements,"X" = ייִדישcan be written
with right-to-left reversal to mean that the variableייִדישis assigned a
value of"X".macro-expandReplace simple "macro" strings in text. This fixer is a no-op if no macro
arguments are supplied. Add--macroto arguments to do replacements.For example, convertissue:NNNto an issue link in markdown with the
following sample config:-repo:https://github.com/sirosen/texthooksrev:0.6.4hooks:-id:macro-expandargs:-"--macro"-"issue:"-'[texthooks#$VALUE](https://github.com/sirosen/texthooks/issues/$VALUE)'CHANGELOGUnreleased0.6.4Add support for Gitea and GitLab CODEOWNERS files toalphabetize-codeowners. Thanks @adam-moss for the PR!0.6.3Reduce length of hook names forpre-commit.comrequirements0.6.2Minor whitespace bugfix foralphabetize-codeowners0.6.1Bugfix foralphabetize-codeownersstripping ending newlines0.6.0Addalphabetize-codeownersfixer (ported fromsirosen/alphabetize-codeowners)0.5.0Fix a bug in fixers when running on Windows which could cause data to be
written with the wrong encodingAdd-v/--verboseand-q/--quietflags to tune output verbosity0.4.0Addfix-spacesfixer0.3.1Minor fixes to docstrings0.3.0Add the macro-expand fixer0.2.2Fix a bug in CLI argument handling for all hooks0.2.1Fix a typo inforbid-bidi-controlsentrypoint0.2.0Add theforbid-bidi-controlshookAdjust the handling of file encodings. Files will be read with UTF-8 encoding
by default in most cases.0.1.0Initial release withfix-ligaturesandfix-smartquoteshooks