update license, add acknowledgements, and remove pangu.rkt from this repo

parent 03393b4a
# License
- All *prose writing* are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License, see file `LICENSE.cc-by-sa`.
- All *prose writing* — comprised of all `.html.pm` files — are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License, see file `LICENSE.cc-by-sa`.
- The *source code* — comprised of all `.rkt`, `.sh`, `.yml`, `template.html`, `.css`, and `.css.pp` files — is licensed under the MIT license, see file `LICENSE.mit`.
- The *source code* — comprised of all `.ptree`, `.rkt`, `.yml`, `.html.p`, and `.css.pp` files — is licensed under the MIT license, see file `LICENSE.mit`.
......@@ -7,30 +7,3 @@ Packaging up poems I wrote.
## License
See `LICENSE`. TL;DR: prose = CC-BY-SA 4.0, code = MIT.
Used icons from [Feather](https://github.com/feathericons/feather) (via [icongram](https://icongr.am/)).
`pangu.rkt` is a port of [`pangu.py`](https://github.com/vinta/pangu.py); its license is provided below:
```
The MIT License (MIT)
Copyright (c) 2013 Vinta
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
```
# Acknowledgements
This book is made with [Pollen](https://pollenpub.com), the publishing system behind [Matthew Butterick](https://github.com/mbutterick)’s [Practical Typography](https://practicaltypography.com/).
Navigation buttons use icons from [Feather](https://github.com/feathericons/feather) (via [icongram](https://icongr.am/)).
#lang axe
;; Paranoid text spacing in Racket
;; Port of pangu.py: https://github.com/vinta/pangu.py
;;; Regex definitions
(define cjk "\u2e80-\u2eff\u2f00-\u2fdf\u3040-\u309f\u30a0-\u30fa\u30fc-\u30ff\u3100-\u312f\u3200-\u32ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff")
(define any-cjk (regexp (format r"[~a]" cjk)))
;; there is an extra non-capturing group compared to JavaScript version
(define convert-to-fullwidth-cjk-symbols-cjk
(regexp (format "([~a])([ ]*(?:[\\:]+|\\.)[ ]*)([~a])" cjk cjk)))
(define convert-to-fullwidth-cjk-symbols
(regexp (format "([~a])[ ]*([~~\\!;,\\?]+)[ ]*" cjk)))
(define dots-cjk
(regexp (format "([\\.]{{2,}}|\u2026)([~a])" cjk)))
(define fix-cjk-colon-ans
(regexp (format "([~a])\\:([A-Z0-9\\(\\)])" cjk)))
;; need to escape "
;; highlighting would be screwed if we just used raw strings
(define cjk-quote (regexp (format "([~a])([`\"\u05f4])" cjk)))
(define quote-cjk (regexp (format "([`\"\u05f4])([~a])" cjk)))
(define fix-quote-any-quote
(regexp r'([`"\u05f4]+)(\s*)(.+?)(\s*)([`"\u05f4]+)'))
(define cjk-single-quote-but-possessive
(regexp (format "([~a])('[^s])" cjk)))
(define single-quote-cjk
(regexp (format "(')([~a])" cjk)))
(define fix-possessive-single-quote
(regexp (format "([~aA-Za-z0-9])( )('s)" cjk)))
(define hash-ans-cjk-hash
(regexp (format "([~a])(#)([~a]+)(#)([~a])" cjk cjk cjk)))
(define cjk-hash (regexp (format "([~a])(#([^ ]))" cjk)))
(define hash-cjk (regexp (format "(([^ ])#)([~a])" cjk)))
(define cjk-operator-ans
(regexp (format "([~a])([\\+\\-\\*\\/=&\\|<>])([A-Za-z0-9])" cjk)))
(define ans-operator-cjk
(regexp (format "([A-Za-z0-9])([\\+\\-\\*\\/=&\\|<>])([~a])" cjk)))
(define fix-slash-as
(regexp r"([/]) ([a-z\-_\./]+)"))
(define fix-slash-as-slash
(regexp r"([/\.])([A-Za-z\-_\./]+) ([/])"))
(define cjk-left-bracket
(regexp (format "([~a])([\\(\\[\\{{<>\u201c])" cjk)))
(define right-bracket-cjk
(regexp (format "([\\)\\]\\}}<>\u201d])([~a])" cjk)))
(define fix-left-bracket-any-right-bracket
(regexp r'([\(\[\{<\u201c]+)(\s*)(.+?)(\s*)([\)\]\}>\u201d]+)'))
(define ans-cjk-left-bracket-any-right-bracket
(regexp (format "([A-Za-z0-9~a])[ ]*([\u201c])([A-Za-z0-9~a\\-_ ]+)([\u201d])"
cjk cjk)))
(define left-bracket-any-right-bracket-ans-cjk
(regexp (format "([\u201c])([A-Za-z0-9~a\\-_ ]+)([\u201d])[ ]*([A-Za-z0-9~a])"
cjk cjk)))
(define an-left-bracket (regexp r'([A-Za-z0-9])([\(\[\{])'))
(define right-bracket-an (regexp r'([\)\]\}])([A-Za-z0-9])'))
(define cjk-ans
(regexp (format "([~a])([A-Za-z\u0370-\[email protected]\\$%\\^&\\*\\-\\+\\\\=\\|/\u00a1-\u00ff\u2150-\u218f\u2700—\u27bf])"
cjk)))
(define ans-cjk
(regexp (format "([A-Za-z\u0370-\u03ff0-9~~\\!\\$%\\^&\\*\\-\\+\\\\=\\|;:,\\./\\?\u00a1-\u00ff\u2150-\u218f\u2700—\u27bf])([~a])"
cjk)))
(define s-a #rx"(%)([A-Za-z])")
(define middle-dot (regexp "([ ]*)([\u00b7\u2022\u2027])([ ]*)"))
;; Python version only
(define tildes (regexp r'~+'))
(define exclamation-marks (regexp r'!+'))
(define semicolons (regexp r";+"))
(define colons (regexp r":+"))
(define commas (regexp r",+"))
(define periods (regexp r"\.+"))
(define question-marks #r"\?+")
;;; Functions
(define (convert-to-fullwidth symbols)
(let* ((symbols (regexp-replace tildes symbols "~"))
(symbols (regexp-replace exclamation-marks symbols "!"))
(symbols (regexp-replace semicolons symbols ";"))
(symbols (regexp-replace colons symbols ":"))
(symbols (regexp-replace commas symbols ","))
(symbols (regexp-replace periods symbols "。"))
(symbols (regexp-replace question-marks symbols "?")))
(string-trim symbols)))
;; NOTE: main entry point?
(define (spacing text)
;; https://github.com/vinta/pangu.py/blob/89407cf08dedf9d895c13053dd518d11a20f6c95/pangu.py#L97
;; this is probably not useful for other regexps.
(define (to-fullwidth-symbols regexp text)
(match (regexp-match regexp text)
((cons old new)
(to-fullwidth-symbols
regexp
(string-replace text old (apply ~a (map convert-to-fullwidth new)))))
(#f text)))
;; sure...
;; Return prematurely from function in Racket:
;; https://stackoverflow.com/questions/25523522
(let/ec return
(when (or (<= (string-length text) 1)
(not (regexp-match any-cjk text)))
(return text))
(let* ((text (to-fullwidth-symbols convert-to-fullwidth-cjk-symbols-cjk text))
(text (to-fullwidth-symbols convert-to-fullwidth-cjk-symbols text))
(text (regexp-replace dots-cjk text r'\1 \2'))
(text (regexp-replace fix-cjk-colon-ans text r'\1:\2'))
(text (regexp-replace cjk-quote text r'\1 \2'))
(text (regexp-replace quote-cjk text r'\1 \2'))
(text (regexp-replace fix-quote-any-quote text r'\1\3\5'))
(text (regexp-replace cjk-single-quote-but-possessive text r'\1 \2'))
(text (regexp-replace single-quote-cjk text r'\1 \2'))
(text (regexp-replace fix-possessive-single-quote text r"\1's"))
(text (regexp-replace hash-ans-cjk-hash text r'\1 \2\3\4 \5'))
(text (regexp-replace cjk-hash text r'\1 \2'))
(text (regexp-replace hash-cjk text r'\1 \3'))
(text (regexp-replace cjk-operator-ans text r'\1 \2 \3'))
(text (regexp-replace ans-operator-cjk text r'\1 \2 \3'))
(text (regexp-replace fix-slash-as text r'\1\2'))
(text (regexp-replace fix-slash-as-slash text r'\1\2\3'))
(text (regexp-replace cjk-left-bracket text r'\1 \2'))
(text (regexp-replace right-bracket-cjk text r'\1 \2'))
(text (regexp-replace fix-left-bracket-any-right-bracket text r'\1\3\5'))
(text (regexp-replace ans-cjk-left-bracket-any-right-bracket text r'\1 \2\3\4'))
(text (regexp-replace left-bracket-any-right-bracket-ans-cjk text r'\1\2\3 \4'))
(text (regexp-replace an-left-bracket text r'\1 \2'))
(text (regexp-replace right-bracket-an text r'\1 \2'))
(text (regexp-replace cjk-ans text r'\1 \2'))
(text (regexp-replace ans-cjk text r'\1 \2'))
(text (regexp-replace s-a text r'\1 \2'))
(text (regexp-replace middle-dot text "・")))
(string-trim text))))
(define (spacing-text text)
(spacing text))
(define (spacing-file path)
;; NOTE: pangu.py has a todo here to read line by line.
(spacing-text (file->string path)))
;; -v / --version = show version
;; -t / --text = arguments are text to pangu
;; -f / --file = arguments are files to pangu
;; (define (cli)
;; (command-line
;; #:program "pangu.rkt"
;; #:once-each
;; [("-v" "--version") "Show version" (println "0.0.1")]
;; #:once-any
;; [("-t" "--text") "Arguments are text" (spacing-text (current-command-line-arguments))]
;; [("-t" "--text") "Arguments are text" (spacing-text (current-command-line-arguments))]))
;; TODO: cli
(module+ main
(spacing-text (first (current-command-line-arguments))))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment