Package: degrotesque
degrotesque — A web type setter.Introductiondegrotesque beautifies the web.degrotesqueis aPythonscript. It loads a text/markdown/HTML/XML file from the disc — or several in batch — and for each, it replaces some commonly used non-typographic characters, such as ", ', -, etc. into their typographic representation for improving the pages' appearance.E.g.:"Well - that's not what I had expected."will become:“Well — that's not what I had expected.”I think it looksmuchbetter.The starting and ending quotes have been replaced by “ and ”, respectively, the ' by ' and the - by an —. Of course, this script omits HTML-elements. It keeps the complete format as-is, and replaces characters by their proper HTML entity name or the respective unicode character.It is meant to be a relativelyreliable post-processing step for web pages before releasing them. In version 3.0.0 the support of markdown files was added.BackgroundI often write my texts and web pages using a plain editor. As such, the character " is always used for quotes, a dash is always a minus, etc.I wanted to have a tool that automatically recognizes which characters should be replaced by their more typographic counterpart and applies the according rules.I think it’s a pity that major Desktop Publishing applications do this on the fly but many and even major web sites still show us plain ASCII characters.degrotesquedoes the job pretty fine. After writing / building my pages, the tool converts them to a prettier and typographically more correct form. The structure and format of the pages is completely remained. And as said, it works reliable.If you need any consultations, please let me know. If you know better, too.Download and InstallationThecurrent versionisdegrotesque-3.0.0.You mayinstall degrotesqueusingpython -m pip install degrotesqueYou maydownload a copy or fork the codeatdegrotesque's github page.Besides, you maydownload the current releasehere:degrotesque-3.0.0.zipdegrotesque-3.0.0.tar.gzLicensedegrotesqueis licensed underBSD license.DocumentationUsagedegrotesqueis implemented inPython. It is started on the command line.The option-i<PATH>/--input<PATH>tells the script which file(s) shall be read — you may name a file or a folder, here. If the option-r/--recursiveis set, the given folder will be processed recursively.The tool processes text files, HTML files, XML files, and their derivatives. Per default, all files are processed when-ipoints to a folder. You may limit the files to process by their extension using the-e<EXTENSION>[,<EXTENSION>]*/--extensions<EXTENSION>[,<EXTENSION>]*option. The files are assumed to be encoded using UTF-8 per default. You may change the encoding using the option-E<ENCODING>/--encoding<ENCODING>.The files are read one by one and the replacement of plain ASCII chars by some nicer ones is based upon a chosen set of “actions”. Known and default actions are given inAppendix A. You may select the actions to apply using the-a<ACTION_NAME>[,<ACTION_NAME>]*/--actions<ACTION_NAME>[,<ACTION_NAME>]*option. The default actions are ‘masks’, ‘quotes.english’, ‘dashes’, ‘ellipsis’, ‘math’, ‘apostrophe’, and ‘commercial’.Per default, Unicode entities are inserted (e.g. ‘&#8211;’ for an ‘—’). You may change this using the--format<FORMAT>/-f<FORMAT>. The following formats are currently supported:‘unicode’: uses numeric entities (e.g. ‘&#8211;’ for an ‘—’);‘html’: uses numeric entities (e.g. ‘&mdash;’ for an ‘—’);‘text’: uses plain (utf-8) characters (e.g. ‘—’ for an ‘—’).degrotesquetries to determine whether the read files are plain text files, markdown files, or XML or HTML derivatives using the files& extensions and contents.Appendix Blists the extensions by which files are recognized as HTML / markdown files. To be secure, one may set--html/-Hwhen processing HTML files,--markdown/-Mwhen processing markdown files, or--text/-Twhen processing plain text files.When parsing XML/HTML files, the script does not change the quotation marks within elements, of course. As well, the contents of several elements, such as <code> or <pre>, are skipped. You may change the list of elements which contents shall not be processed using the option-s<ELEMENT_NAME>[,<ELEMENT_NAME>]*/--skip<ELEMENT_NAME>[,<ELEMENT_NAME>]*. The list of elements that are skipped per default is given inAppendix C.When parsing markdown files, code — both indented and defined using ` — is skipped. Quotes as well.After the actions have been applied to its contents, the file is saved. By default, a backup of the original file is saved under the same name, with the appendix “.orig”. You may omit the creation of these backup files using the option-B / --no-backup.The option--help/-hprints a help screen. The option--versionthedegrotesque'sversion number.Please note that “masks” is a special action set that disallows the application of some other actions so that, e.g., the dividers in ISBN numbers are not replaced by &ndash;. The masks action set is given inAppendix D.OptionsThe script can be started on the command line with the following options:--input/-i<PATH>: the file or the folder to process--recursive/-r: Set if the folder — if given — shall be processed recursively--extensions/-e<EXTENSION>[,<EXTENSION>]*: The extensions of files that shall be processed--encoding/-E<ENCODING>: The assumed encoding of the files--html/-H: Files are HTML/XML-derivatives--text/-T: Files are plain text files--markdown/-M: Files are markdown files--format/-f<FORMAT>: Define the format of the replacements [‘html’, ‘unicode’, ‘text’]--no-backup/-B: Set if no backup files shall be generated--skip/-s<ELEMENT_NAME>[,<ELEMENT_NAME>]*: Elements which contents shall not be changed--actions/-a<ACTION_NAME>[,<ACTION_NAME>]*: Name the actions that shall be applied--help: Prints the help screen--version: Prints the versionUsage Examplesdegrotesque -i my_page.html -a quotes.germanReplaces single and double quotes within the file “my_page.html” by their typographic German counterparts.degrotesque -i my_folder -r --no-backupApplies the default actions to all files in the folder “my_folder” and all subfolders. No backup files are generated. The files format of each file is determined using the file's extension.Application Programming Interface — APIYou may as well embedddegrotesquewithin your own applications. The usage is very straightforward:importdegrotesque# build the degrotesque instance with default valuesdegrotesque=degrotesque.Degrotesque()# apply degrotequeplain=' <script> if(i<0) echo "a"</script> "Hello World" 'pretty=degrotesque.prettify(plain,True)plain=' <script> if(i<0) echo "a"</script> "Hello World" 'pretty=degrotesque.prettify(plain,False)The first call will deliver:<script> if(i<0) echo "a"</script> &ldquo;Hello World&rdquo;while the second — as the string is interpreted as plain text, not HTML will deliver:<script> if(i<0) echo &ldquo;a&rdquo;</script> &ldquo;Hello World&rdquo;what is probably not what you wished.The default values can be replaced using some of the class' interfaces (methods):# change the actions to apply (by naming them)# here: apply french quotes and math symbolsdegrotesque.setActions("quotes.french,math")# change the elements which contents shall be skipped# here: skip the contents of "code",#  "script", and "style" elementsdegrotesque.setToSkip("code,script,style")You may as well consult thedegrotesque pydoc code documentation.Further DocumentationThe complete documentation is located at:https://degrotesque.readthedocs.io/en/latest/andhttps://krajzewicz.de/docs/degrotesque/index.htmlDiscussions are open athttps://github.com/dkrajzew/degrotesque/discussionsThe github repository is located at:https://github.com/dkrajzew/degrotesqueThe issue tracker is located at:https://github.com/dkrajzew/degrotesque/issuesThe PyPI page is located at:https://pypi.org/project/degrotesque/Examples / UsersMy own pages (https://www.krajzewicz.de/).PaletteWB— a sophisticated palette editor for MS Windows.Change Logdegrotesque-3.0.0 (26.03.2023)Adding support for degrotesquing markdown files (contents of code and quotes are kept)Added support for processing plain text files; The distinction whether a file is a plain text file or a HTML/XML derivative is done using the extension (see Appendix B for used extensions) and by evaluating the contents; Everything is replaced in text files. When processing a file as a XML/HTML derivative, elements are skipped. Introducing the options--text/-T,--markdown/-M, and--html/-Hto explicitly set the file type.Supporting different target encodings for the replacements using the--format / -f<FORMAT>option (the option--unicode/-uwas removed):‘unicode’: uses numeric entities (e.g. ‘&#8211;’ for an ‘—’);‘html’: uses numeric entities (e.g. ‘&mdash;’ for an ‘—’);‘text’: uses plain (utf-8) characters (e.g. ‘—’ for an ‘—’).100 % test coverage :-)renamed master branch to maindegrotesque-2.0.6 (05.02.2023)Patched documentation (return types)Set proper formatting forreadthedocsIt's not 2.0.4 due to caching by readthedocsdegrotesque-2.0.2 (04.02.2023)Corrected installation and execution as a console scriptdegrotesque-2.0 (05.01.2023)Changed the license toBSD.Using github actions for testing on push instead of using Travis CICleaned up project treeAdding anmkdocsdocumentationOlder VersionsseeChangeLogSummaryWell, have fun. If you have any comments / ideas / issues, please submit them todegrotesque's issue trackeron github or drop me a mail.