/usr/share/guile/site/texinfo/plain-text.scm is in guile-library 0.2.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | ;; (texinfo plain-text) -- rendering stexinfo as plain text
;; Copyright (C) 2003,2004 Andy Wingo <wingo at pobox dot com>
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;Transformation from stexi to plain-text. Strives to re-create the
;;output from @code{info}; comes pretty damn close.
;;
;;; Code:
(define-module (texinfo plain-text)
#:use-module (texinfo)
#:use-module (sxml transform)
#:use-module (scheme documentation)
#:use-module (string wrap)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-13)
#:export (stexi->plain-text))
;; The return value is a string.
(define (arg-ref key %-args)
(and=> (and=> (assq key (cdr %-args)) cdr)
stexi->plain-text))
(define (arg-req key %-args)
(or (arg-ref key %-args)
(error "Missing argument:" key %-args)))
(define *indent* (make-fluid))
(define *itemizer* (make-fluid))
(define (make-ticker str)
(lambda () str))
(define (make-enumerator n)
(lambda ()
(let ((last n))
(set! n (1+ n))
(format #f "~A. " last))))
(fluid-set! *indent* "")
;; Shouldn't be necessary to do this, but just in case.
(fluid-set! *itemizer* (make-ticker "* "))
(define-macro (with-indent n . body)
`(with-fluids ((*indent* (string-append (fluid-ref *indent*)
(make-string ,n #\space))))
,@body))
(define (make-indenter n proc)
(lambda args (with-indent n (apply proc args))))
(define (string-indent str)
(string-append (fluid-ref *indent*) str "\n"))
(define-macro (with-itemizer itemizer . body)
`(with-fluids ((*itemizer* ,itemizer))
,@body))
(define (wrap* . strings)
(let ((indent (fluid-ref *indent*)))
(fill-string (string-concatenate strings)
#:width 72 #:initial-indent indent
#:subsequent-indent indent)))
(define (wrap . strings)
(string-append (apply wrap* strings) "\n\n"))
(define (wrap-heading . strings)
(string-append (apply wrap* strings) "\n"))
(define (ref tag args)
(let* ((node (arg-req 'node args))
(name (or (arg-ref 'name args) node))
(manual (arg-ref 'manual args)))
(string-concatenate
(cons*
(or (and=> (assq tag '((xref "See ") (pxref "see "))) cadr) "")
name
(if manual `(" in manual " ,manual) '())))))
(define (uref tag args)
(let ((url (arg-req 'url args))
(title (arg-ref 'title args)))
(if title
(string-append title " (" url ")")
(string-append "`" url "'"))))
(define (def tag args . body)
(define (list/spaces . elts)
(let lp ((in elts) (out '()))
(cond ((null? in) (reverse! out))
((null? (car in)) (lp (cdr in) out))
(else (lp (cdr in)
(cons (car in)
(if (null? out) out (cons " " out))))))))
(define (first-line)
(string-join
(filter identity
(map (lambda (x) (arg-ref x args))
'(data-type class name arguments)))
" "))
(let* ((category (case tag
((defun) "Function")
((defspec) "Special Form")
((defvar) "Variable")
(else (arg-req 'category args)))))
(string-append
(wrap-heading (string-append " - " category ": " (first-line)))
(with-indent 5 (stexi->plain-text body)))))
(define (enumerate tag . elts)
(define (tonumber start)
(let ((c (string-ref start 0)))
(cond ((number? c) (string->number start))
(else (1+ (- (char->integer c)
(char->integer (if (char-upper? c) #\A #\a))))))))
(let* ((args? (and (pair? elts) (pair? (car elts))
(eq? (caar elts) '%)))
(start (and args? (arg-ref 'start (car elts)))))
(with-itemizer (make-enumerator (if start (tonumber start) 1))
(with-indent 5
(stexi->plain-text (if start (cdr elts) elts))))))
(define (itemize tag args . elts)
(with-itemizer (make-ticker "* ")
(with-indent 5
(stexi->plain-text elts))))
(define (item tag . elts)
(let* ((ret (stexi->plain-text elts))
(tick ((fluid-ref *itemizer*)))
(tick-pos (- (string-length (fluid-ref *indent*))
(string-length tick))))
(if (and (not (string-null? ret)) (not (negative? tick-pos)))
(string-copy! ret tick-pos tick))
ret))
(define (table tag args . body)
(stexi->plain-text body))
(define (entry tag args . body)
(let ((heading (wrap-heading
(stexi->plain-text (arg-req 'heading args)))))
(string-append heading
(with-indent 5 (stexi->plain-text body)))))
(define (make-underliner char)
(lambda (tag . body)
(let ((str (stexi->plain-text body)))
(string-append
"\n"
(string-indent str)
(string-indent (make-string (string-length str) char))
"\n"))))
(define chapter (make-underliner #\*))
(define section (make-underliner #\=))
(define subsection (make-underliner #\-))
(define subsubsection (make-underliner #\.))
(define (example tag . body)
(let ((ret (stexi->plain-text body)))
(string-append
(string-concatenate
(with-indent 5 (map string-indent (string-split ret #\newline))))
"\n")))
(define (verbatim tag . body)
(let ((ret (stexi->plain-text body)))
(string-append
(string-concatenate
(map string-indent (string-split ret #\newline)))
"\n")))
(define (fragment tag . body)
(string-concatenate (map-in-order stexi->plain-text body)))
(define (para tag . body)
(wrap (stexi->plain-text body)))
(define (make-surrounder str)
(lambda (tag . body)
(string-append str (stexi->plain-text body) str)))
(define (code tag . body)
(string-append "`" (stexi->plain-text body) "'"))
(define (key tag . body)
(string-append "<" (stexi->plain-text body) ">"))
(define (var tag . body)
(string-upcase (stexi->plain-text body)))
(define (passthrough tag . body)
(stexi->plain-text body))
(define (ignore . args)
"")
(define (texinfo tag args . body)
(let ((title (chapter 'foo (arg-req 'title args))))
(string-append title (stexi->plain-text body))))
(define ignore-list
'(page setfilename setchapternewpage iftex ifinfo ifplaintext ifxml sp vskip
menu ignore syncodeindex comment c % node anchor))
(define (ignored? tag)
(memq tag ignore-list))
(define tag-handlers
`((title ,chapter)
(chapter ,chapter)
(section ,section)
(subsection ,subsection)
(subsubsection ,subsubsection)
(appendix ,chapter)
(appendixsec ,section)
(appendixsubsec ,subsection)
(appendixsubsubsec ,subsubsection)
(unnumbered ,chapter)
(unnumberedsec ,section)
(unnumberedsubsec ,subsection)
(unnumberedsubsubsec ,subsubsection)
(majorheading ,chapter)
(chapheading ,chapter)
(heading ,section)
(subheading ,subsection)
(subsubheading ,subsubsection)
(strong ,(make-surrounder "*"))
(sample ,code)
(samp ,code)
(code ,code)
(kbd ,code)
(key ,key)
(var ,var)
(env ,code)
(file ,code)
(command ,code)
(option ,code)
(url ,code)
(dfn ,(make-surrounder "\""))
(cite ,(make-surrounder "\""))
(acro ,passthrough)
(email ,key)
(emph ,(make-surrounder "_"))
(sc ,var)
(copyright ,(lambda args "(C)"))
(result ,(lambda args "==>"))
(xref ,ref)
(ref ,ref)
(pxref ,ref)
(uref ,uref)
(texinfo ,texinfo)
(quotation ,(make-indenter 5 para))
(itemize ,itemize)
(enumerate ,enumerate)
(item ,item)
(table ,table)
(entry ,entry)
(example ,example)
(lisp ,example)
(smallexample ,example)
(smalllisp ,example)
(verbatim ,verbatim)
(*fragment* ,fragment)
(deftp ,def)
(defcv ,def)
(defivar ,def)
(deftypeivar ,def)
(defop ,def)
(deftypeop ,def)
(defmethod ,def)
(deftypemethod ,def)
(defopt ,def)
(defvr ,def)
(defvar ,def)
(deftypevr ,def)
(deftypevar ,def)
(deffn ,def)
(deftypefn ,def)
(defmac ,def)
(defspec ,def)
(defun ,def)
(deftypefun ,def)))
(define-with-docs stexi->plain-text
"Transform @var{tree} into plain text. Returns a string."
(lambda (tree)
(cond
((null? tree) "")
((string? tree) tree)
((pair? tree)
(cond
((symbol? (car tree))
(let ((handler (and (not (ignored? (car tree)))
(or (and=> (assq (car tree) tag-handlers) cadr)
para))))
(if handler (apply handler tree) "")))
(else
(string-concatenate (map-in-order stexi->plain-text tree)))))
(else ""))))
;;; arch-tag: f966c3f6-3b46-4790-bbf9-3ad27e4917c2
|