ox: fix some docstrings
[org-mode/org-kjn.git] / lisp / ox-ascii.el
blob8e750078e15d86106515aa994b2413c4e144d853
1 ;;; ox-ascii.el --- ASCII Back-End for Org Export Engine
3 ;; Copyright (C) 2012, 2013 Free Software Foundation, Inc.
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; GNU Emacs is free software: you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
21 ;;; Commentary:
23 ;; This library implements an ASCII back-end for Org generic exporter.
24 ;; See Org manual for more information.
26 ;;; Code:
28 (eval-when-compile (require 'cl))
29 (require 'ox)
30 (require 'ox-publish)
32 (declare-function aa2u "ext:ascii-art-to-unicode" ())
34 ;;; Define Back-End
36 ;; The following setting won't allow to modify preferred charset
37 ;; through a buffer keyword or an option item, but, since the property
38 ;; will appear in communication channel nonetheless, it allows to
39 ;; override `org-ascii-charset' variable on the fly by the ext-plist
40 ;; mechanism.
42 ;; We also install a filter for headlines and sections, in order to
43 ;; control blank lines separating them in output string.
45 (org-export-define-backend 'ascii
46 '((bold . org-ascii-bold)
47 (center-block . org-ascii-center-block)
48 (clock . org-ascii-clock)
49 (code . org-ascii-code)
50 (comment . (lambda (&rest args) ""))
51 (comment-block . (lambda (&rest args) ""))
52 (drawer . org-ascii-drawer)
53 (dynamic-block . org-ascii-dynamic-block)
54 (entity . org-ascii-entity)
55 (example-block . org-ascii-example-block)
56 (export-block . org-ascii-export-block)
57 (export-snippet . org-ascii-export-snippet)
58 (fixed-width . org-ascii-fixed-width)
59 (footnote-reference . org-ascii-footnote-reference)
60 (headline . org-ascii-headline)
61 (horizontal-rule . org-ascii-horizontal-rule)
62 (inline-src-block . org-ascii-inline-src-block)
63 (inlinetask . org-ascii-inlinetask)
64 (inner-template . org-ascii-inner-template)
65 (italic . org-ascii-italic)
66 (item . org-ascii-item)
67 (keyword . org-ascii-keyword)
68 (latex-environment . org-ascii-latex-environment)
69 (latex-fragment . org-ascii-latex-fragment)
70 (line-break . org-ascii-line-break)
71 (link . org-ascii-link)
72 (node-property . org-ascii-node-property)
73 (paragraph . org-ascii-paragraph)
74 (plain-list . org-ascii-plain-list)
75 (plain-text . org-ascii-plain-text)
76 (planning . org-ascii-planning)
77 (property-drawer . org-ascii-property-drawer)
78 (quote-block . org-ascii-quote-block)
79 (quote-section . org-ascii-quote-section)
80 (radio-target . org-ascii-radio-target)
81 (section . org-ascii-section)
82 (special-block . org-ascii-special-block)
83 (src-block . org-ascii-src-block)
84 (statistics-cookie . org-ascii-statistics-cookie)
85 (strike-through . org-ascii-strike-through)
86 (subscript . org-ascii-subscript)
87 (superscript . org-ascii-superscript)
88 (table . org-ascii-table)
89 (table-cell . org-ascii-table-cell)
90 (table-row . org-ascii-table-row)
91 (target . org-ascii-target)
92 (template . org-ascii-template)
93 (timestamp . org-ascii-timestamp)
94 (underline . org-ascii-underline)
95 (verbatim . org-ascii-verbatim)
96 (verse-block . org-ascii-verse-block))
97 :export-block "ASCII"
98 :menu-entry
99 '(?t "Export to Plain Text"
100 ((?A "As ASCII buffer"
101 (lambda (a s v b)
102 (org-ascii-export-as-ascii a s v b '(:ascii-charset ascii))))
103 (?a "As ASCII file"
104 (lambda (a s v b)
105 (org-ascii-export-to-ascii a s v b '(:ascii-charset ascii))))
106 (?L "As Latin1 buffer"
107 (lambda (a s v b)
108 (org-ascii-export-as-ascii a s v b '(:ascii-charset latin1))))
109 (?l "As Latin1 file"
110 (lambda (a s v b)
111 (org-ascii-export-to-ascii a s v b '(:ascii-charset latin1))))
112 (?U "As UTF-8 buffer"
113 (lambda (a s v b)
114 (org-ascii-export-as-ascii a s v b '(:ascii-charset utf-8))))
115 (?u "As UTF-8 file"
116 (lambda (a s v b)
117 (org-ascii-export-to-ascii a s v b '(:ascii-charset utf-8))))))
118 :filters-alist '((:filter-headline . org-ascii-filter-headline-blank-lines)
119 (:filter-parse-tree org-ascii-filter-paragraph-spacing
120 org-ascii-filter-comment-spacing)
121 (:filter-section . org-ascii-filter-headline-blank-lines))
122 :options-alist '((:ascii-charset nil nil org-ascii-charset)))
126 ;;; User Configurable Variables
128 (defgroup org-export-ascii nil
129 "Options for exporting Org mode files to ASCII."
130 :tag "Org Export ASCII"
131 :group 'org-export)
133 (defcustom org-ascii-text-width 72
134 "Maximum width of exported text.
135 This number includes margin size, as set in
136 `org-ascii-global-margin'."
137 :group 'org-export-ascii
138 :version "24.4"
139 :package-version '(Org . "8.0")
140 :type 'integer)
142 (defcustom org-ascii-global-margin 0
143 "Width of the left margin, in number of characters."
144 :group 'org-export-ascii
145 :version "24.4"
146 :package-version '(Org . "8.0")
147 :type 'integer)
149 (defcustom org-ascii-inner-margin 2
150 "Width of the inner margin, in number of characters.
151 Inner margin is applied between each headline."
152 :group 'org-export-ascii
153 :version "24.4"
154 :package-version '(Org . "8.0")
155 :type 'integer)
157 (defcustom org-ascii-quote-margin 6
158 "Width of margin used for quoting text, in characters.
159 This margin is applied on both sides of the text."
160 :group 'org-export-ascii
161 :version "24.4"
162 :package-version '(Org . "8.0")
163 :type 'integer)
165 (defcustom org-ascii-inlinetask-width 30
166 "Width of inline tasks, in number of characters.
167 This number ignores any margin."
168 :group 'org-export-ascii
169 :version "24.4"
170 :package-version '(Org . "8.0")
171 :type 'integer)
173 (defcustom org-ascii-headline-spacing '(1 . 2)
174 "Number of blank lines inserted around headlines.
176 This variable can be set to a cons cell. In that case, its car
177 represents the number of blank lines present before headline
178 contents whereas its cdr reflects the number of blank lines after
179 contents.
181 A nil value replicates the number of blank lines found in the
182 original Org buffer at the same place."
183 :group 'org-export-ascii
184 :version "24.4"
185 :package-version '(Org . "8.0")
186 :type '(choice
187 (const :tag "Replicate original spacing" nil)
188 (cons :tag "Set an uniform spacing"
189 (integer :tag "Number of blank lines before contents")
190 (integer :tag "Number of blank lines after contents"))))
192 (defcustom org-ascii-indented-line-width 'auto
193 "Additional indentation width for the first line in a paragraph.
194 If the value is an integer, indent the first line of each
195 paragraph by this number. If it is the symbol `auto' preserve
196 indentation from original document."
197 :group 'org-export-ascii
198 :version "24.4"
199 :package-version '(Org . "8.0")
200 :type '(choice
201 (integer :tag "Number of white spaces characters")
202 (const :tag "Preserve original width" auto)))
204 (defcustom org-ascii-paragraph-spacing 'auto
205 "Number of white lines between paragraphs.
206 If the value is an integer, add this number of blank lines
207 between contiguous paragraphs. If is it the symbol `auto', keep
208 the same number of blank lines as in the original document."
209 :group 'org-export-ascii
210 :version "24.4"
211 :package-version '(Org . "8.0")
212 :type '(choice
213 (integer :tag "Number of blank lines")
214 (const :tag "Preserve original spacing" auto)))
216 (defcustom org-ascii-charset 'ascii
217 "The charset allowed to represent various elements and objects.
218 Possible values are:
219 `ascii' Only use plain ASCII characters
220 `latin1' Include Latin-1 characters
221 `utf-8' Use all UTF-8 characters"
222 :group 'org-export-ascii
223 :version "24.4"
224 :package-version '(Org . "8.0")
225 :type '(choice
226 (const :tag "ASCII" ascii)
227 (const :tag "Latin-1" latin1)
228 (const :tag "UTF-8" utf-8)))
230 (defcustom org-ascii-underline '((ascii ?= ?~ ?-)
231 (latin1 ?= ?~ ?-)
232 (utf-8 ?═ ?─ ?╌ ?┄ ?┈))
233 "Characters for underlining headings in ASCII export.
235 Alist whose key is a symbol among `ascii', `latin1' and `utf-8'
236 and whose value is a list of characters.
238 For each supported charset, this variable associates a sequence
239 of underline characters. In a sequence, the characters will be
240 used in order for headlines level 1, 2, ... If no character is
241 available for a given level, the headline won't be underlined."
242 :group 'org-export-ascii
243 :version "24.4"
244 :package-version '(Org . "8.0")
245 :type '(list
246 (cons :tag "Underline characters sequence"
247 (const :tag "ASCII charset" ascii)
248 (repeat character))
249 (cons :tag "Underline characters sequence"
250 (const :tag "Latin-1 charset" latin1)
251 (repeat character))
252 (cons :tag "Underline characters sequence"
253 (const :tag "UTF-8 charset" utf-8)
254 (repeat character))))
256 (defcustom org-ascii-bullets '((ascii ?* ?+ ?-)
257 (latin1 ?§ ?¶)
258 (utf-8 ?◊))
259 "Bullet characters for headlines converted to lists in ASCII export.
261 Alist whose key is a symbol among `ascii', `latin1' and `utf-8'
262 and whose value is a list of characters.
264 The first character is used for the first level considered as low
265 level, and so on. If there are more levels than characters given
266 here, the list will be repeated.
268 Note that this variable doesn't affect plain lists
269 representation."
270 :group 'org-export-ascii
271 :version "24.4"
272 :package-version '(Org . "8.0")
273 :type '(list
274 (cons :tag "Bullet characters for low level headlines"
275 (const :tag "ASCII charset" ascii)
276 (repeat character))
277 (cons :tag "Bullet characters for low level headlines"
278 (const :tag "Latin-1 charset" latin1)
279 (repeat character))
280 (cons :tag "Bullet characters for low level headlines"
281 (const :tag "UTF-8 charset" utf-8)
282 (repeat character))))
284 (defcustom org-ascii-links-to-notes t
285 "Non-nil means convert links to notes before the next headline.
286 When nil, the link will be exported in place. If the line
287 becomes long in this way, it will be wrapped."
288 :group 'org-export-ascii
289 :version "24.4"
290 :package-version '(Org . "8.0")
291 :type 'boolean)
293 (defcustom org-ascii-table-keep-all-vertical-lines nil
294 "Non-nil means keep all vertical lines in ASCII tables.
295 When nil, vertical lines will be removed except for those needed
296 for column grouping."
297 :group 'org-export-ascii
298 :version "24.4"
299 :package-version '(Org . "8.0")
300 :type 'boolean)
302 (defcustom org-ascii-table-widen-columns t
303 "Non-nil means widen narrowed columns for export.
304 When nil, narrowed columns will look in ASCII export just like in
305 Org mode, i.e. with \"=>\" as ellipsis."
306 :group 'org-export-ascii
307 :version "24.4"
308 :package-version '(Org . "8.0")
309 :type 'boolean)
311 (defcustom org-ascii-table-use-ascii-art nil
312 "Non-nil means table.el tables are turned into ascii-art.
314 It only makes sense when export charset is `utf-8'. It is nil by
315 default since it requires ascii-art-to-unicode.el package. You
316 can download it here:
318 http://gnuvola.org/software/j/aa2u/ascii-art-to-unicode.el."
319 :group 'org-export-ascii
320 :version "24.4"
321 :package-version '(Org . "8.0")
322 :type 'boolean)
324 (defcustom org-ascii-caption-above nil
325 "When non-nil, place caption string before the element.
326 Otherwise, place it right after it."
327 :group 'org-export-ascii
328 :version "24.4"
329 :package-version '(Org . "8.0")
330 :type 'boolean)
332 (defcustom org-ascii-verbatim-format "`%s'"
333 "Format string used for verbatim text and inline code."
334 :group 'org-export-ascii
335 :version "24.4"
336 :package-version '(Org . "8.0")
337 :type 'string)
339 (defcustom org-ascii-format-drawer-function nil
340 "Function called to format a drawer in ASCII.
342 The function must accept three parameters:
343 NAME the drawer name, like \"LOGBOOK\"
344 CONTENTS the contents of the drawer.
345 WIDTH the text width within the drawer.
347 The function should return either the string to be exported or
348 nil to ignore the drawer.
350 For example, the variable could be set to the following function
351 in order to mimic default behaviour:
353 \(defun org-ascii-format-drawer-default (name contents width)
354 \"Format a drawer element for ASCII export.\"
355 contents)"
356 :group 'org-export-ascii
357 :version "24.4"
358 :package-version '(Org . "8.0")
359 :type 'function)
361 (defcustom org-ascii-format-inlinetask-function nil
362 "Function called to format an inlinetask in ASCII.
364 The function must accept six parameters:
365 TODO the todo keyword, as a string
366 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
367 PRIORITY the inlinetask priority, as a string
368 NAME the inlinetask name, as a string.
369 TAGS the inlinetask tags, as a list of strings.
370 CONTENTS the contents of the inlinetask, as a string.
372 The function should return either the string to be exported or
373 nil to ignore the inline task.
375 For example, the variable could be set to the following function
376 in order to mimic default behaviour:
378 \(defun org-ascii-format-inlinetask-default
379 \(todo type priority name tags contents\)
380 \"Format an inline task element for ASCII export.\"
381 \(let* \(\(utf8p \(eq \(plist-get info :ascii-charset\) 'utf-8\)\)
382 \(width org-ascii-inlinetask-width\)
383 \(org-ascii--indent-string
384 \(concat
385 ;; Top line, with an additional blank line if not in UTF-8.
386 \(make-string width \(if utf8p ?━ ?_\)\) \"\\n\"
387 \(unless utf8p \(concat \(make-string width ? \) \"\\n\"\)\)
388 ;; Add title. Fill it if wider than inlinetask.
389 \(let \(\(title \(org-ascii--build-title inlinetask info width\)\)\)
390 \(if \(<= \(length title\) width\) title
391 \(org-ascii--fill-string title width info\)\)\)
392 \"\\n\"
393 ;; If CONTENTS is not empty, insert it along with
394 ;; a separator.
395 \(when \(org-string-nw-p contents\)
396 \(concat \(make-string width \(if utf8p ?─ ?-\)\) \"\\n\" contents\)\)
397 ;; Bottom line.
398 \(make-string width \(if utf8p ?━ ?_\)\)\)
399 ;; Flush the inlinetask to the right.
400 \(- \(plist-get info :ascii-width\)
401 \(plist-get info :ascii-margin\)
402 \(plist-get info :ascii-inner-margin\)
403 \(org-ascii--current-text-width inlinetask info\)\)"
404 :group 'org-export-ascii
405 :version "24.4"
406 :package-version '(Org . "8.0")
407 :type 'function)
411 ;;; Internal Functions
413 ;; Internal functions fall into three categories.
415 ;; The first one is about text formatting. The core function is
416 ;; `org-ascii--current-text-width', which determines the current
417 ;; text width allowed to a given element. In other words, it helps
418 ;; keeping each line width within maximum text width defined in
419 ;; `org-ascii-text-width'. Once this information is known,
420 ;; `org-ascii--fill-string', `org-ascii--justify-string',
421 ;; `org-ascii--box-string' and `org-ascii--indent-string' can
422 ;; operate on a given output string.
424 ;; The second category contains functions handling elements listings,
425 ;; triggered by "#+TOC:" keyword. As such, `org-ascii--build-toc'
426 ;; returns a complete table of contents, `org-ascii--list-listings'
427 ;; returns a list of referenceable src-block elements, and
428 ;; `org-ascii--list-tables' does the same for table elements.
430 ;; The third category includes general helper functions.
431 ;; `org-ascii--build-title' creates the title for a given headline
432 ;; or inlinetask element. `org-ascii--build-caption' returns the
433 ;; caption string associated to a table or a src-block.
434 ;; `org-ascii--describe-links' creates notes about links for
435 ;; insertion at the end of a section. It uses
436 ;; `org-ascii--unique-links' to get the list of links to describe.
437 ;; Eventually, `org-ascii--translate' translates a string according
438 ;; to language and charset specification.
441 (defun org-ascii--fill-string (s text-width info &optional justify)
442 "Fill a string with specified text-width and return it.
444 S is the string being filled. TEXT-WIDTH is an integer
445 specifying maximum length of a line. INFO is the plist used as
446 a communication channel.
448 Optional argument JUSTIFY can specify any type of justification
449 among `left', `center', `right' or `full'. A nil value is
450 equivalent to `left'. For a justification that doesn't also fill
451 string, see `org-ascii--justify-string'.
453 Return nil if S isn't a string."
454 ;; Don't fill paragraph when break should be preserved.
455 (cond ((not (stringp s)) nil)
456 ((plist-get info :preserve-breaks) s)
457 (t (let ((double-space-p sentence-end-double-space))
458 (with-temp-buffer
459 (let ((fill-column text-width)
460 (use-hard-newlines t)
461 (sentence-end-double-space double-space-p))
462 (insert s)
463 (fill-region (point-min) (point-max) justify))
464 (buffer-string))))))
466 (defun org-ascii--justify-string (s text-width how)
467 "Justify string S.
468 TEXT-WIDTH is an integer specifying maximum length of a line.
469 HOW determines the type of justification: it can be `left',
470 `right', `full' or `center'."
471 (with-temp-buffer
472 (insert s)
473 (goto-char (point-min))
474 (let ((fill-column text-width)
475 ;; Disable `adaptive-fill-mode' so it doesn't prevent
476 ;; filling lines matching `adaptive-fill-regexp'.
477 (adaptive-fill-mode nil))
478 (while (< (point) (point-max))
479 (justify-current-line how)
480 (forward-line)))
481 (buffer-string)))
483 (defun org-ascii--indent-string (s width)
484 "Indent string S by WIDTH white spaces.
485 Empty lines are not indented."
486 (when (stringp s)
487 (replace-regexp-in-string
488 "\\(^\\)\\(?:.*\\S-\\)" (make-string width ? ) s nil nil 1)))
490 (defun org-ascii--box-string (s info)
491 "Return string S with a partial box to its left.
492 INFO is a plist used as a communicaton channel."
493 (let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
494 (format (if utf8p "╭────\n%s\n╰────" ",----\n%s\n`----")
495 (replace-regexp-in-string
496 "^" (if utf8p "│ " "| ")
497 ;; Remove last newline character.
498 (replace-regexp-in-string "\n[ \t]*\\'" "" s)))))
500 (defun org-ascii--current-text-width (element info)
501 "Return maximum text width for ELEMENT's contents.
502 INFO is a plist used as a communication channel."
503 (case (org-element-type element)
504 ;; Elements with an absolute width: `headline' and `inlinetask'.
505 (inlinetask org-ascii-inlinetask-width)
506 ('headline
507 (- org-ascii-text-width
508 (let ((low-level-rank (org-export-low-level-p element info)))
509 (if low-level-rank (* low-level-rank 2) org-ascii-global-margin))))
510 ;; Elements with a relative width: store maximum text width in
511 ;; TOTAL-WIDTH.
512 (otherwise
513 (let* ((genealogy (cons element (org-export-get-genealogy element)))
514 ;; Total width is determined by the presence, or not, of an
515 ;; inline task among ELEMENT parents.
516 (total-width
517 (if (loop for parent in genealogy
518 thereis (eq (org-element-type parent) 'inlinetask))
519 org-ascii-inlinetask-width
520 ;; No inlinetask: Remove global margin from text width.
521 (- org-ascii-text-width
522 org-ascii-global-margin
523 (let ((parent (org-export-get-parent-headline element)))
524 ;; Inner margin doesn't apply to text before first
525 ;; headline.
526 (if (not parent) 0
527 (let ((low-level-rank
528 (org-export-low-level-p parent info)))
529 ;; Inner margin doesn't apply to contents of
530 ;; low level headlines, since they've got their
531 ;; own indentation mechanism.
532 (if low-level-rank (* low-level-rank 2)
533 org-ascii-inner-margin))))))))
534 (- total-width
535 ;; Each `quote-block', `quote-section' and `verse-block' above
536 ;; narrows text width by twice the standard margin size.
537 (+ (* (loop for parent in genealogy
538 when (memq (org-element-type parent)
539 '(quote-block quote-section verse-block))
540 count parent)
541 2 org-ascii-quote-margin)
542 ;; Text width within a plain-list is restricted by
543 ;; indentation of current item. If that's the case,
544 ;; compute it with the help of `:structure' property from
545 ;; parent item, if any.
546 (let ((parent-item
547 (if (eq (org-element-type element) 'item) element
548 (loop for parent in genealogy
549 when (eq (org-element-type parent) 'item)
550 return parent))))
551 (if (not parent-item) 0
552 ;; Compute indentation offset of the current item,
553 ;; that is the sum of the difference between its
554 ;; indentation and the indentation of the top item in
555 ;; the list and current item bullet's length. Also
556 ;; remove checkbox length, and tag length (for
557 ;; description lists) or bullet length.
558 (let ((struct (org-element-property :structure parent-item))
559 (beg-item (org-element-property :begin parent-item)))
560 (+ (- (org-list-get-ind beg-item struct)
561 (org-list-get-ind
562 (org-list-get-top-point struct) struct))
563 (length (org-ascii--checkbox parent-item info))
564 (length
565 (or (org-list-get-tag beg-item struct)
566 (org-list-get-bullet beg-item struct)))))))))))))
568 (defun org-ascii--build-title
569 (element info text-width &optional underline notags toc)
570 "Format ELEMENT title and return it.
572 ELEMENT is either an `headline' or `inlinetask' element. INFO is
573 a plist used as a communication channel. TEXT-WIDTH is an
574 integer representing the maximum length of a line.
576 When optional argument UNDERLINE is non-nil, underline title,
577 without the tags, according to `org-ascii-underline'
578 specifications.
580 If optional argument NOTAGS is non-nil, no tags will be added to
581 the title.
583 When optional argument TOC is non-nil, use optional title if
584 possible. It doesn't apply to `inlinetask' elements."
585 (let* ((headlinep (eq (org-element-type element) 'headline))
586 (numbers
587 ;; Numbering is specific to headlines.
588 (and headlinep (org-export-numbered-headline-p element info)
589 ;; All tests passed: build numbering string.
590 (concat
591 (mapconcat
592 'number-to-string
593 (org-export-get-headline-number element info) ".")
594 " ")))
595 (text
596 (org-trim
597 (org-export-data
598 (if (and toc headlinep) (org-export-get-alt-title element info)
599 (org-element-property :title element))
600 info)))
601 (todo
602 (and (plist-get info :with-todo-keywords)
603 (let ((todo (org-element-property :todo-keyword element)))
604 (and todo (concat (org-export-data todo info) " ")))))
605 (tags (and (not notags)
606 (plist-get info :with-tags)
607 (let ((tag-list (org-export-get-tags element info)))
608 (and tag-list
609 (format ":%s:"
610 (mapconcat 'identity tag-list ":"))))))
611 (priority
612 (and (plist-get info :with-priority)
613 (let ((char (org-element-property :priority element)))
614 (and char (format "(#%c) " char)))))
615 (first-part (concat numbers todo priority text)))
616 (concat
617 first-part
618 ;; Align tags, if any.
619 (when tags
620 (format
621 (format " %%%ds"
622 (max (- text-width (1+ (length first-part))) (length tags)))
623 tags))
624 ;; Maybe underline text, if ELEMENT type is `headline' and an
625 ;; underline character has been defined.
626 (when (and underline headlinep)
627 (let ((under-char
628 (nth (1- (org-export-get-relative-level element info))
629 (cdr (assq (plist-get info :ascii-charset)
630 org-ascii-underline)))))
631 (and under-char
632 (concat "\n"
633 (make-string (length first-part) under-char))))))))
635 (defun org-ascii--has-caption-p (element info)
636 "Non-nil when ELEMENT has a caption affiliated keyword.
637 INFO is a plist used as a communication channel. This function
638 is meant to be used as a predicate for `org-export-get-ordinal'."
639 (org-element-property :caption element))
641 (defun org-ascii--build-caption (element info)
642 "Return caption string for ELEMENT, if applicable.
644 INFO is a plist used as a communication channel.
646 The caption string contains the sequence number of ELEMENT along
647 with its real caption. Return nil when ELEMENT has no affiliated
648 caption keyword."
649 (let ((caption (org-export-get-caption element)))
650 (when caption
651 ;; Get sequence number of current src-block among every
652 ;; src-block with a caption.
653 (let ((reference
654 (org-export-get-ordinal
655 element info nil 'org-ascii--has-caption-p))
656 (title-fmt (org-ascii--translate
657 (case (org-element-type element)
658 (table "Table %d:")
659 (src-block "Listing %d:"))
660 info)))
661 (org-ascii--fill-string
662 (concat (format title-fmt reference)
664 (org-export-data caption info))
665 (org-ascii--current-text-width element info) info)))))
667 (defun org-ascii--build-toc (info &optional n keyword)
668 "Return a table of contents.
670 INFO is a plist used as a communication channel.
672 Optional argument N, when non-nil, is an integer specifying the
673 depth of the table.
675 Optional argument KEYWORD specifies the TOC keyword, if any, from
676 which the table of contents generation has been initiated."
677 (let ((title (org-ascii--translate "Table of Contents" info)))
678 (concat
679 title "\n"
680 (make-string (length title)
681 (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))
682 "\n\n"
683 (let ((text-width
684 (if keyword (org-ascii--current-text-width keyword info)
685 (- org-ascii-text-width org-ascii-global-margin))))
686 (mapconcat
687 (lambda (headline)
688 (let* ((level (org-export-get-relative-level headline info))
689 (indent (* (1- level) 3)))
690 (concat
691 (unless (zerop indent) (concat (make-string (1- indent) ?.) " "))
692 (org-ascii--build-title
693 headline info (- text-width indent) nil
694 (or (not (plist-get info :with-tags))
695 (eq (plist-get info :with-tags) 'not-in-toc))
696 'toc))))
697 (org-export-collect-headlines info n) "\n")))))
699 (defun org-ascii--list-listings (keyword info)
700 "Return a list of listings.
702 KEYWORD is the keyword that initiated the list of listings
703 generation. INFO is a plist used as a communication channel."
704 (let ((title (org-ascii--translate "List of Listings" info)))
705 (concat
706 title "\n"
707 (make-string (length title)
708 (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))
709 "\n\n"
710 (let ((text-width
711 (if keyword (org-ascii--current-text-width keyword info)
712 (- org-ascii-text-width org-ascii-global-margin)))
713 ;; Use a counter instead of retreiving ordinal of each
714 ;; src-block.
715 (count 0))
716 (mapconcat
717 (lambda (src-block)
718 ;; Store initial text so its length can be computed. This is
719 ;; used to properly align caption right to it in case of
720 ;; filling (like contents of a description list item).
721 (let ((initial-text
722 (format (org-ascii--translate "Listing %d:" info)
723 (incf count))))
724 (concat
725 initial-text " "
726 (org-trim
727 (org-ascii--indent-string
728 (org-ascii--fill-string
729 ;; Use short name in priority, if available.
730 (let ((caption (or (org-export-get-caption src-block t)
731 (org-export-get-caption src-block))))
732 (org-export-data caption info))
733 (- text-width (length initial-text)) info)
734 (length initial-text))))))
735 (org-export-collect-listings info) "\n")))))
737 (defun org-ascii--list-tables (keyword info)
738 "Return a list of tables.
740 KEYWORD is the keyword that initiated the list of tables
741 generation. INFO is a plist used as a communication channel."
742 (let ((title (org-ascii--translate "List of Tables" info)))
743 (concat
744 title "\n"
745 (make-string (length title)
746 (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))
747 "\n\n"
748 (let ((text-width
749 (if keyword (org-ascii--current-text-width keyword info)
750 (- org-ascii-text-width org-ascii-global-margin)))
751 ;; Use a counter instead of retreiving ordinal of each
752 ;; src-block.
753 (count 0))
754 (mapconcat
755 (lambda (table)
756 ;; Store initial text so its length can be computed. This is
757 ;; used to properly align caption right to it in case of
758 ;; filling (like contents of a description list item).
759 (let ((initial-text
760 (format (org-ascii--translate "Table %d:" info)
761 (incf count))))
762 (concat
763 initial-text " "
764 (org-trim
765 (org-ascii--indent-string
766 (org-ascii--fill-string
767 ;; Use short name in priority, if available.
768 (let ((caption (or (org-export-get-caption table t)
769 (org-export-get-caption table))))
770 (org-export-data caption info))
771 (- text-width (length initial-text)) info)
772 (length initial-text))))))
773 (org-export-collect-tables info) "\n")))))
775 (defun org-ascii--unique-links (element info)
776 "Return a list of unique link references in ELEMENT.
778 ELEMENT is either a headline element or a section element. INFO
779 is a plist used as a communication channel."
780 (let* (seen
781 (unique-link-p
782 (function
783 ;; Return LINK if it wasn't referenced so far, or nil.
784 ;; Update SEEN links along the way.
785 (lambda (link)
786 (let ((footprint
787 (cons (org-element-property :raw-link link)
788 (org-element-contents link))))
789 ;; Ignore LINK if it hasn't been translated already.
790 ;; It can happen if it is located in an affiliated
791 ;; keyword that was ignored.
792 (when (and (org-string-nw-p
793 (gethash link (plist-get info :exported-data)))
794 (not (member footprint seen)))
795 (push footprint seen) link)))))
796 ;; If at a section, find parent headline, if any, in order to
797 ;; count links that might be in the title.
798 (headline
799 (if (eq (org-element-type element) 'headline) element
800 (or (org-export-get-parent-headline element) element))))
801 ;; Get all links in HEADLINE.
802 (org-element-map headline 'link
803 (lambda (l) (funcall unique-link-p l)) info nil nil t)))
805 (defun org-ascii--describe-links (links width info)
806 "Return a string describing a list of links.
808 LINKS is a list of link type objects, as returned by
809 `org-ascii--unique-links'. WIDTH is the text width allowed for
810 the output string. INFO is a plist used as a communication
811 channel."
812 (mapconcat
813 (lambda (link)
814 (let ((type (org-element-property :type link))
815 (anchor (let ((desc (org-element-contents link)))
816 (if desc (org-export-data desc info)
817 (org-element-property :raw-link link)))))
818 (cond
819 ;; Coderefs, radio links and fuzzy links are ignored.
820 ((member type '("coderef" "radio" "fuzzy")) nil)
821 ;; Id and custom-id links: Headlines refer to their numbering.
822 ((member type '("custom-id" "id"))
823 (let ((dest (org-export-resolve-id-link link info)))
824 (concat
825 (org-ascii--fill-string
826 (format
827 "[%s] %s"
828 anchor
829 (if (not dest) (org-ascii--translate "Unknown reference" info)
830 (format
831 (org-ascii--translate "See section %s" info)
832 (mapconcat 'number-to-string
833 (org-export-get-headline-number dest info) "."))))
834 width info) "\n\n")))
835 ;; Do not add a link that cannot be resolved and doesn't have
836 ;; any description: destination is already visible in the
837 ;; paragraph.
838 ((not (org-element-contents link)) nil)
840 (concat
841 (org-ascii--fill-string
842 (format "[%s] %s" anchor (org-element-property :raw-link link))
843 width info)
844 "\n\n")))))
845 links ""))
847 (defun org-ascii--checkbox (item info)
848 "Return checkbox string for ITEM or nil.
849 INFO is a plist used as a communication channel."
850 (let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
851 (case (org-element-property :checkbox item)
852 (on (if utf8p "☑ " "[X] "))
853 (off (if utf8p "☐ " "[ ] "))
854 (trans (if utf8p "☒ " "[-] ")))))
858 ;;; Template
860 (defun org-ascii-template--document-title (info)
861 "Return document title, as a string.
862 INFO is a plist used as a communication channel."
863 (let* ((text-width org-ascii-text-width)
864 ;; Links in the title will not be resolved later, so we make
865 ;; sure their path is located right after them.
866 (org-ascii-links-to-notes nil)
867 (title (org-export-data (plist-get info :title) info))
868 (author (and (plist-get info :with-author)
869 (let ((auth (plist-get info :author)))
870 (and auth (org-export-data auth info)))))
871 (email (and (plist-get info :with-email)
872 (org-export-data (plist-get info :email) info)))
873 (date (and (plist-get info :with-date)
874 (org-export-data (org-export-get-date info) info))))
875 ;; There are two types of title blocks depending on the presence
876 ;; of a title to display.
877 (if (string= title "")
878 ;; Title block without a title. DATE is positioned at the top
879 ;; right of the document, AUTHOR to the top left and EMAIL
880 ;; just below.
881 (cond
882 ((and (org-string-nw-p date) (org-string-nw-p author))
883 (concat
884 author
885 (make-string (- text-width (length date) (length author)) ? )
886 date
887 (when (org-string-nw-p email) (concat "\n" email))
888 "\n\n\n"))
889 ((and (org-string-nw-p date) (org-string-nw-p email))
890 (concat
891 email
892 (make-string (- text-width (length date) (length email)) ? )
893 date "\n\n\n"))
894 ((org-string-nw-p date)
895 (concat
896 (org-ascii--justify-string date text-width 'right)
897 "\n\n\n"))
898 ((and (org-string-nw-p author) (org-string-nw-p email))
899 (concat author "\n" email "\n\n\n"))
900 ((org-string-nw-p author) (concat author "\n\n\n"))
901 ((org-string-nw-p email) (concat email "\n\n\n")))
902 ;; Title block with a title. Document's TITLE, along with the
903 ;; AUTHOR and its EMAIL are both overlined and an underlined,
904 ;; centered. Date is just below, also centered.
905 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8))
906 ;; Format TITLE. It may be filled if it is too wide,
907 ;; that is wider than the two thirds of the total width.
908 (title-len (min (length title) (/ (* 2 text-width) 3)))
909 (formatted-title (org-ascii--fill-string title title-len info))
910 (line
911 (make-string
912 (min (+ (max title-len (length author) (length email)) 2)
913 text-width) (if utf8p ?━ ?_))))
914 (org-ascii--justify-string
915 (concat line "\n"
916 (unless utf8p "\n")
917 (upcase formatted-title)
918 (cond
919 ((and (org-string-nw-p author) (org-string-nw-p email))
920 (concat (if utf8p "\n\n\n" "\n\n") author "\n" email))
921 ((org-string-nw-p author)
922 (concat (if utf8p "\n\n\n" "\n\n") author))
923 ((org-string-nw-p email)
924 (concat (if utf8p "\n\n\n" "\n\n") email)))
925 "\n" line
926 (when (org-string-nw-p date) (concat "\n\n\n" date))
927 "\n\n\n") text-width 'center)))))
929 (defun org-ascii-inner-template (contents info)
930 "Return complete document string after ASCII conversion.
931 CONTENTS is the transcoded contents string. INFO is a plist
932 holding export options."
933 (org-element-normalize-string
934 (org-ascii--indent-string
935 (concat
936 ;; 1. Document's body.
937 contents
938 ;; 2. Footnote definitions.
939 (let ((definitions (org-export-collect-footnote-definitions
940 (plist-get info :parse-tree) info))
941 ;; Insert full links right inside the footnote definition
942 ;; as they have no chance to be inserted later.
943 (org-ascii-links-to-notes nil))
944 (when definitions
945 (concat
946 "\n\n\n"
947 (let ((title (org-ascii--translate "Footnotes" info)))
948 (concat
949 title "\n"
950 (make-string
951 (length title)
952 (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))))
953 "\n\n"
954 (let ((text-width (- org-ascii-text-width org-ascii-global-margin)))
955 (mapconcat
956 (lambda (ref)
957 (let ((id (format "[%s] " (car ref))))
958 ;; Distinguish between inline definitions and
959 ;; full-fledged definitions.
960 (org-trim
961 (let ((def (nth 2 ref)))
962 (if (eq (org-element-type def) 'org-data)
963 ;; Full-fledged definition: footnote ID is
964 ;; inserted inside the first parsed paragraph
965 ;; (FIRST), if any, to be sure filling will
966 ;; take it into consideration.
967 (let ((first (car (org-element-contents def))))
968 (if (not (eq (org-element-type first) 'paragraph))
969 (concat id "\n" (org-export-data def info))
970 (push id (nthcdr 2 first))
971 (org-export-data def info)))
972 ;; Fill paragraph once footnote ID is inserted
973 ;; in order to have a correct length for first
974 ;; line.
975 (org-ascii--fill-string
976 (concat id (org-export-data def info))
977 text-width info))))))
978 definitions "\n\n"))))))
979 org-ascii-global-margin)))
981 (defun org-ascii-template (contents info)
982 "Return complete document string after ASCII conversion.
983 CONTENTS is the transcoded contents string. INFO is a plist
984 holding export options."
985 (concat
986 ;; 1. Build title block.
987 (org-ascii--indent-string
988 (concat (org-ascii-template--document-title info)
989 ;; 2. Table of contents.
990 (let ((depth (plist-get info :with-toc)))
991 (when depth
992 (concat
993 (org-ascii--build-toc info (and (wholenump depth) depth))
994 "\n\n\n"))))
995 org-ascii-global-margin)
996 ;; 3. Document's body.
997 contents
998 ;; 4. Creator. Ignore `comment' value as there are no comments in
999 ;; ASCII. Justify it to the bottom right.
1000 (org-ascii--indent-string
1001 (let ((creator-info (plist-get info :with-creator))
1002 (text-width (- org-ascii-text-width org-ascii-global-margin)))
1003 (unless (or (not creator-info) (eq creator-info 'comment))
1004 (concat
1005 "\n\n\n"
1006 (org-ascii--fill-string
1007 (plist-get info :creator) text-width info 'right))))
1008 org-ascii-global-margin)))
1010 (defun org-ascii--translate (s info)
1011 "Translate string S according to specified language and charset.
1012 INFO is a plist used as a communication channel."
1013 (let ((charset (intern (format ":%s" (plist-get info :ascii-charset)))))
1014 (org-export-translate s charset info)))
1018 ;;; Transcode Functions
1020 ;;;; Bold
1022 (defun org-ascii-bold (bold contents info)
1023 "Transcode BOLD from Org to ASCII.
1024 CONTENTS is the text with bold markup. INFO is a plist holding
1025 contextual information."
1026 (format "*%s*" contents))
1029 ;;;; Center Block
1031 (defun org-ascii-center-block (center-block contents info)
1032 "Transcode a CENTER-BLOCK element from Org to ASCII.
1033 CONTENTS holds the contents of the block. INFO is a plist
1034 holding contextual information."
1035 (org-ascii--justify-string
1036 contents (org-ascii--current-text-width center-block info) 'center))
1039 ;;;; Clock
1041 (defun org-ascii-clock (clock contents info)
1042 "Transcode a CLOCK object from Org to ASCII.
1043 CONTENTS is nil. INFO is a plist holding contextual
1044 information."
1045 (concat org-clock-string " "
1046 (org-translate-time
1047 (org-element-property :raw-value
1048 (org-element-property :value clock)))
1049 (let ((time (org-element-property :duration clock)))
1050 (and time
1051 (concat " => "
1052 (apply 'format
1053 "%2s:%02s"
1054 (org-split-string time ":")))))))
1057 ;;;; Code
1059 (defun org-ascii-code (code contents info)
1060 "Return a CODE object from Org to ASCII.
1061 CONTENTS is nil. INFO is a plist holding contextual
1062 information."
1063 (format org-ascii-verbatim-format (org-element-property :value code)))
1066 ;;;; Drawer
1068 (defun org-ascii-drawer (drawer contents info)
1069 "Transcode a DRAWER element from Org to ASCII.
1070 CONTENTS holds the contents of the block. INFO is a plist
1071 holding contextual information."
1072 (let ((name (org-element-property :drawer-name drawer))
1073 (width (org-ascii--current-text-width drawer info)))
1074 (if (functionp org-ascii-format-drawer-function)
1075 (funcall org-ascii-format-drawer-function name contents width)
1076 ;; If there's no user defined function: simply
1077 ;; display contents of the drawer.
1078 contents)))
1081 ;;;; Dynamic Block
1083 (defun org-ascii-dynamic-block (dynamic-block contents info)
1084 "Transcode a DYNAMIC-BLOCK element from Org to ASCII.
1085 CONTENTS holds the contents of the block. INFO is a plist
1086 holding contextual information."
1087 contents)
1090 ;;;; Entity
1092 (defun org-ascii-entity (entity contents info)
1093 "Transcode an ENTITY object from Org to ASCII.
1094 CONTENTS are the definition itself. INFO is a plist holding
1095 contextual information."
1096 (org-element-property
1097 (intern (concat ":" (symbol-name (plist-get info :ascii-charset))))
1098 entity))
1101 ;;;; Example Block
1103 (defun org-ascii-example-block (example-block contents info)
1104 "Transcode a EXAMPLE-BLOCK element from Org to ASCII.
1105 CONTENTS is nil. INFO is a plist holding contextual information."
1106 (org-ascii--box-string
1107 (org-export-format-code-default example-block info) info))
1110 ;;;; Export Snippet
1112 (defun org-ascii-export-snippet (export-snippet contents info)
1113 "Transcode a EXPORT-SNIPPET object from Org to ASCII.
1114 CONTENTS is nil. INFO is a plist holding contextual information."
1115 (when (eq (org-export-snippet-backend export-snippet) 'ascii)
1116 (org-element-property :value export-snippet)))
1119 ;;;; Export Block
1121 (defun org-ascii-export-block (export-block contents info)
1122 "Transcode a EXPORT-BLOCK element from Org to ASCII.
1123 CONTENTS is nil. INFO is a plist holding contextual information."
1124 (when (string= (org-element-property :type export-block) "ASCII")
1125 (org-remove-indentation (org-element-property :value export-block))))
1128 ;;;; Fixed Width
1130 (defun org-ascii-fixed-width (fixed-width contents info)
1131 "Transcode a FIXED-WIDTH element from Org to ASCII.
1132 CONTENTS is nil. INFO is a plist holding contextual information."
1133 (org-ascii--box-string
1134 (org-remove-indentation
1135 (org-element-property :value fixed-width)) info))
1138 ;;;; Footnote Definition
1140 ;; Footnote Definitions are ignored. They are compiled at the end of
1141 ;; the document, by `org-ascii-inner-template'.
1144 ;;;; Footnote Reference
1146 (defun org-ascii-footnote-reference (footnote-reference contents info)
1147 "Transcode a FOOTNOTE-REFERENCE element from Org to ASCII.
1148 CONTENTS is nil. INFO is a plist holding contextual information."
1149 (format "[%s]" (org-export-get-footnote-number footnote-reference info)))
1152 ;;;; Headline
1154 (defun org-ascii-headline (headline contents info)
1155 "Transcode a HEADLINE element from Org to ASCII.
1156 CONTENTS holds the contents of the headline. INFO is a plist
1157 holding contextual information."
1158 ;; Don't export footnote section, which will be handled at the end
1159 ;; of the template.
1160 (unless (org-element-property :footnote-section-p headline)
1161 (let* ((low-level-rank (org-export-low-level-p headline info))
1162 (width (org-ascii--current-text-width headline info))
1163 ;; Blank lines between headline and its contents.
1164 ;; `org-ascii-headline-spacing', when set, overwrites
1165 ;; original buffer's spacing.
1166 (pre-blanks
1167 (make-string
1168 (if org-ascii-headline-spacing (car org-ascii-headline-spacing)
1169 (org-element-property :pre-blank headline)) ?\n))
1170 ;; Even if HEADLINE has no section, there might be some
1171 ;; links in its title that we shouldn't forget to describe.
1172 (links
1173 (unless (or (eq (caar (org-element-contents headline)) 'section))
1174 (let ((title (org-element-property :title headline)))
1175 (when (consp title)
1176 (org-ascii--describe-links
1177 (org-ascii--unique-links title info) width info))))))
1178 ;; Deep subtree: export it as a list item.
1179 (if low-level-rank
1180 (concat
1181 ;; Bullet.
1182 (let ((bullets (cdr (assq (plist-get info :ascii-charset)
1183 org-ascii-bullets))))
1184 (char-to-string
1185 (nth (mod (1- low-level-rank) (length bullets)) bullets)))
1187 ;; Title.
1188 (org-ascii--build-title headline info width) "\n"
1189 ;; Contents, indented by length of bullet.
1190 pre-blanks
1191 (org-ascii--indent-string
1192 (concat contents
1193 (when (org-string-nw-p links) (concat "\n\n" links)))
1195 ;; Else: Standard headline.
1196 (concat
1197 (org-ascii--build-title headline info width 'underline)
1198 "\n" pre-blanks
1199 (concat (when (org-string-nw-p links) links) contents))))))
1202 ;;;; Horizontal Rule
1204 (defun org-ascii-horizontal-rule (horizontal-rule contents info)
1205 "Transcode an HORIZONTAL-RULE object from Org to ASCII.
1206 CONTENTS is nil. INFO is a plist holding contextual
1207 information."
1208 (let ((text-width (org-ascii--current-text-width horizontal-rule info))
1209 (spec-width
1210 (org-export-read-attribute :attr_ascii horizontal-rule :width)))
1211 (org-ascii--justify-string
1212 (make-string (if (and spec-width (string-match "^[0-9]+$" spec-width))
1213 (string-to-number spec-width)
1214 text-width)
1215 (if (eq (plist-get info :ascii-charset) 'utf-8) ?― ?-))
1216 text-width 'center)))
1219 ;;;; Inline Src Block
1221 (defun org-ascii-inline-src-block (inline-src-block contents info)
1222 "Transcode an INLINE-SRC-BLOCK element from Org to ASCII.
1223 CONTENTS holds the contents of the item. INFO is a plist holding
1224 contextual information."
1225 (format org-ascii-verbatim-format
1226 (org-element-property :value inline-src-block)))
1229 ;;;; Inlinetask
1231 (defun org-ascii-inlinetask (inlinetask contents info)
1232 "Transcode an INLINETASK element from Org to ASCII.
1233 CONTENTS holds the contents of the block. INFO is a plist
1234 holding contextual information."
1235 (let ((width (org-ascii--current-text-width inlinetask info)))
1236 ;; If `org-ascii-format-inlinetask-function' is provided, call it
1237 ;; with appropriate arguments.
1238 (if (functionp org-ascii-format-inlinetask-function)
1239 (funcall org-ascii-format-inlinetask-function
1240 ;; todo.
1241 (and (plist-get info :with-todo-keywords)
1242 (let ((todo (org-element-property
1243 :todo-keyword inlinetask)))
1244 (and todo (org-export-data todo info))))
1245 ;; todo-type
1246 (org-element-property :todo-type inlinetask)
1247 ;; priority
1248 (and (plist-get info :with-priority)
1249 (org-element-property :priority inlinetask))
1250 ;; title
1251 (org-export-data (org-element-property :title inlinetask) info)
1252 ;; tags
1253 (and (plist-get info :with-tags)
1254 (org-element-property :tags inlinetask))
1255 ;; contents and width
1256 contents width)
1257 ;; Otherwise, use a default template.
1258 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
1259 (org-ascii--indent-string
1260 (concat
1261 ;; Top line, with an additional blank line if not in UTF-8.
1262 (make-string width (if utf8p ?━ ?_)) "\n"
1263 (unless utf8p (concat (make-string width ? ) "\n"))
1264 ;; Add title. Fill it if wider than inlinetask.
1265 (let ((title (org-ascii--build-title inlinetask info width)))
1266 (if (<= (length title) width) title
1267 (org-ascii--fill-string title width info)))
1268 "\n"
1269 ;; If CONTENTS is not empty, insert it along with
1270 ;; a separator.
1271 (when (org-string-nw-p contents)
1272 (concat (make-string width (if utf8p ?─ ?-)) "\n" contents))
1273 ;; Bottom line.
1274 (make-string width (if utf8p ?━ ?_)))
1275 ;; Flush the inlinetask to the right.
1276 (- org-ascii-text-width org-ascii-global-margin
1277 (if (not (org-export-get-parent-headline inlinetask)) 0
1278 org-ascii-inner-margin)
1279 (org-ascii--current-text-width inlinetask info)))))))
1282 ;;;; Italic
1284 (defun org-ascii-italic (italic contents info)
1285 "Transcode italic from Org to ASCII.
1286 CONTENTS is the text with italic markup. INFO is a plist holding
1287 contextual information."
1288 (format "/%s/" contents))
1291 ;;;; Item
1293 (defun org-ascii-item (item contents info)
1294 "Transcode an ITEM element from Org to ASCII.
1295 CONTENTS holds the contents of the item. INFO is a plist holding
1296 contextual information."
1297 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8))
1298 (checkbox (org-ascii--checkbox item info))
1299 (list-type (org-element-property :type (org-export-get-parent item)))
1300 (bullet
1301 ;; First parent of ITEM is always the plain-list. Get
1302 ;; `:type' property from it.
1303 (org-list-bullet-string
1304 (case list-type
1305 (descriptive
1306 (concat checkbox
1307 (org-export-data (org-element-property :tag item) info)
1308 ": "))
1309 (ordered
1310 ;; Return correct number for ITEM, paying attention to
1311 ;; counters.
1312 (let* ((struct (org-element-property :structure item))
1313 (bul (org-element-property :bullet item))
1314 (num (number-to-string
1315 (car (last (org-list-get-item-number
1316 (org-element-property :begin item)
1317 struct
1318 (org-list-prevs-alist struct)
1319 (org-list-parents-alist struct)))))))
1320 (replace-regexp-in-string "[0-9]+" num bul)))
1321 (t (let ((bul (org-element-property :bullet item)))
1322 ;; Change bullets into more visible form if UTF-8 is active.
1323 (if (not utf8p) bul
1324 (replace-regexp-in-string
1325 "-" "•"
1326 (replace-regexp-in-string
1327 "+" "⁃"
1328 (replace-regexp-in-string "*" "‣" bul))))))))))
1329 (concat
1330 bullet
1331 (unless (eq list-type 'descriptive) checkbox)
1332 ;; Contents: Pay attention to indentation. Note: check-boxes are
1333 ;; already taken care of at the paragraph level so they don't
1334 ;; interfere with indentation.
1335 (let ((contents (org-ascii--indent-string contents (length bullet))))
1336 (if (eq (org-element-type (car (org-element-contents item))) 'paragraph)
1337 (org-trim contents)
1338 (concat "\n" contents))))))
1341 ;;;; Keyword
1343 (defun org-ascii-keyword (keyword contents info)
1344 "Transcode a KEYWORD element from Org to ASCII.
1345 CONTENTS is nil. INFO is a plist holding contextual
1346 information."
1347 (let ((key (org-element-property :key keyword))
1348 (value (org-element-property :value keyword)))
1349 (cond
1350 ((string= key "ASCII") value)
1351 ((string= key "TOC")
1352 (let ((value (downcase value)))
1353 (cond
1354 ((string-match "\\<headlines\\>" value)
1355 (let ((depth (or (and (string-match "[0-9]+" value)
1356 (string-to-number (match-string 0 value)))
1357 (plist-get info :with-toc))))
1358 (org-ascii--build-toc
1359 info (and (wholenump depth) depth) keyword)))
1360 ((string= "tables" value)
1361 (org-ascii--list-tables keyword info))
1362 ((string= "listings" value)
1363 (org-ascii--list-listings keyword info))))))))
1366 ;;;; Latex Environment
1368 (defun org-ascii-latex-environment (latex-environment contents info)
1369 "Transcode a LATEX-ENVIRONMENT element from Org to ASCII.
1370 CONTENTS is nil. INFO is a plist holding contextual
1371 information."
1372 (when (plist-get info :with-latex)
1373 (org-remove-indentation (org-element-property :value latex-environment))))
1376 ;;;; Latex Fragment
1378 (defun org-ascii-latex-fragment (latex-fragment contents info)
1379 "Transcode a LATEX-FRAGMENT object from Org to ASCII.
1380 CONTENTS is nil. INFO is a plist holding contextual
1381 information."
1382 (when (plist-get info :with-latex)
1383 (org-element-property :value latex-fragment)))
1386 ;;;; Line Break
1388 (defun org-ascii-line-break (line-break contents info)
1389 "Transcode a LINE-BREAK object from Org to ASCII.
1390 CONTENTS is nil. INFO is a plist holding contextual
1391 information." hard-newline)
1394 ;;;; Link
1396 (defun org-ascii-link (link desc info)
1397 "Transcode a LINK object from Org to ASCII.
1399 DESC is the description part of the link, or the empty string.
1400 INFO is a plist holding contextual information."
1401 (let ((raw-link (org-element-property :raw-link link))
1402 (type (org-element-property :type link)))
1403 (cond
1404 ((string= type "coderef")
1405 (let ((ref (org-element-property :path link)))
1406 (format (org-export-get-coderef-format ref desc)
1407 (org-export-resolve-coderef ref info))))
1408 ;; Do not apply a special syntax on radio links. Though, use
1409 ;; transcoded target's contents as output.
1410 ((string= type "radio")
1411 (let ((destination (org-export-resolve-radio-link link info)))
1412 (when destination
1413 (org-export-data (org-element-contents destination) info))))
1414 ;; Do not apply a special syntax on fuzzy links pointing to
1415 ;; targets.
1416 ((string= type "fuzzy")
1417 (let ((destination (org-export-resolve-fuzzy-link link info)))
1418 (if (org-string-nw-p desc) desc
1419 (when destination
1420 (let ((number
1421 (org-export-get-ordinal
1422 destination info nil 'org-ascii--has-caption-p)))
1423 (when number
1424 (if (atom number) (number-to-string number)
1425 (mapconcat 'number-to-string number "."))))))))
1427 (if (not (org-string-nw-p desc)) (format "[%s]" raw-link)
1428 (concat
1429 (format "[%s]" desc)
1430 (unless org-ascii-links-to-notes (format " (%s)" raw-link))))))))
1433 ;;;; Node Properties
1435 (defun org-ascii-node-property (node-property contents info)
1436 "Transcode a NODE-PROPERTY element from Org to ASCII.
1437 CONTENTS is nil. INFO is a plist holding contextual
1438 information."
1439 (format "%s:%s"
1440 (org-element-property :key node-property)
1441 (let ((value (org-element-property :value node-property)))
1442 (if value (concat " " value) ""))))
1445 ;;;; Paragraph
1447 (defun org-ascii-paragraph (paragraph contents info)
1448 "Transcode a PARAGRAPH element from Org to ASCII.
1449 CONTENTS is the contents of the paragraph, as a string. INFO is
1450 the plist used as a communication channel."
1451 (let ((contents (if (not (wholenump org-ascii-indented-line-width)) contents
1452 (concat
1453 (make-string org-ascii-indented-line-width ? )
1454 (replace-regexp-in-string "\\`[ \t]+" "" contents)))))
1455 (org-ascii--fill-string
1456 contents (org-ascii--current-text-width paragraph info) info)))
1459 ;;;; Plain List
1461 (defun org-ascii-plain-list (plain-list contents info)
1462 "Transcode a PLAIN-LIST element from Org to ASCII.
1463 CONTENTS is the contents of the list. INFO is a plist holding
1464 contextual information."
1465 contents)
1468 ;;;; Plain Text
1470 (defun org-ascii-plain-text (text info)
1471 "Transcode a TEXT string from Org to ASCII.
1472 INFO is a plist used as a communication channel."
1473 (let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
1474 (when (and utf8p (plist-get info :with-smart-quotes))
1475 (setq text (org-export-activate-smart-quotes text :utf-8 info)))
1476 (if (not (plist-get info :with-special-strings)) text
1477 (setq text (replace-regexp-in-string "\\\\-" "" text))
1478 (if (not utf8p) text
1479 ;; Usual replacements in utf-8 with proper option set.
1480 (replace-regexp-in-string
1481 "\\.\\.\\." "…"
1482 (replace-regexp-in-string
1483 "--" "–"
1484 (replace-regexp-in-string "---" "—" text)))))))
1487 ;;;; Planning
1489 (defun org-ascii-planning (planning contents info)
1490 "Transcode a PLANNING element from Org to ASCII.
1491 CONTENTS is nil. INFO is a plist used as a communication
1492 channel."
1493 (mapconcat
1494 'identity
1495 (delq nil
1496 (list (let ((closed (org-element-property :closed planning)))
1497 (when closed
1498 (concat org-closed-string " "
1499 (org-translate-time
1500 (org-element-property :raw-value closed)))))
1501 (let ((deadline (org-element-property :deadline planning)))
1502 (when deadline
1503 (concat org-deadline-string " "
1504 (org-translate-time
1505 (org-element-property :raw-value deadline)))))
1506 (let ((scheduled (org-element-property :scheduled planning)))
1507 (when scheduled
1508 (concat org-scheduled-string " "
1509 (org-translate-time
1510 (org-element-property :raw-value scheduled)))))))
1511 " "))
1514 ;;;; Property Drawer
1516 (defun org-ascii-property-drawer (property-drawer contents info)
1517 "Transcode a PROPERTY-DRAWER element from Org to ASCII.
1518 CONTENTS holds the contents of the drawer. INFO is a plist
1519 holding contextual information."
1520 (org-string-nw-p contents))
1523 ;;;; Quote Block
1525 (defun org-ascii-quote-block (quote-block contents info)
1526 "Transcode a QUOTE-BLOCK element from Org to ASCII.
1527 CONTENTS holds the contents of the block. INFO is a plist
1528 holding contextual information."
1529 (org-ascii--indent-string contents org-ascii-quote-margin))
1532 ;;;; Quote Section
1534 (defun org-ascii-quote-section (quote-section contents info)
1535 "Transcode a QUOTE-SECTION element from Org to ASCII.
1536 CONTENTS is nil. INFO is a plist holding contextual information."
1537 (let ((width (org-ascii--current-text-width quote-section info))
1538 (value
1539 (org-export-data
1540 (org-remove-indentation (org-element-property :value quote-section))
1541 info)))
1542 (org-ascii--indent-string
1543 value
1544 (+ org-ascii-quote-margin
1545 ;; Don't apply inner margin if parent headline is low level.
1546 (let ((headline (org-export-get-parent-headline quote-section)))
1547 (if (org-export-low-level-p headline info) 0
1548 org-ascii-inner-margin))))))
1551 ;;;; Radio Target
1553 (defun org-ascii-radio-target (radio-target contents info)
1554 "Transcode a RADIO-TARGET object from Org to ASCII.
1555 CONTENTS is the contents of the target. INFO is a plist holding
1556 contextual information."
1557 contents)
1560 ;;;; Section
1562 (defun org-ascii-section (section contents info)
1563 "Transcode a SECTION element from Org to ASCII.
1564 CONTENTS is the contents of the section. INFO is a plist holding
1565 contextual information."
1566 (org-ascii--indent-string
1567 (concat
1568 contents
1569 (when org-ascii-links-to-notes
1570 ;; Add list of links at the end of SECTION.
1571 (let ((links (org-ascii--describe-links
1572 (org-ascii--unique-links section info)
1573 (org-ascii--current-text-width section info) info)))
1574 ;; Separate list of links and section contents.
1575 (when (org-string-nw-p links) (concat "\n\n" links)))))
1576 ;; Do not apply inner margin if parent headline is low level.
1577 (let ((headline (org-export-get-parent-headline section)))
1578 (if (or (not headline) (org-export-low-level-p headline info)) 0
1579 org-ascii-inner-margin))))
1582 ;;;; Special Block
1584 (defun org-ascii-special-block (special-block contents info)
1585 "Transcode a SPECIAL-BLOCK element from Org to ASCII.
1586 CONTENTS holds the contents of the block. INFO is a plist
1587 holding contextual information."
1588 contents)
1591 ;;;; Src Block
1593 (defun org-ascii-src-block (src-block contents info)
1594 "Transcode a SRC-BLOCK element from Org to ASCII.
1595 CONTENTS holds the contents of the item. INFO is a plist holding
1596 contextual information."
1597 (let ((caption (org-ascii--build-caption src-block info))
1598 (code (org-export-format-code-default src-block info)))
1599 (if (equal code "") ""
1600 (concat
1601 (when (and caption org-ascii-caption-above) (concat caption "\n"))
1602 (org-ascii--box-string code info)
1603 (when (and caption (not org-ascii-caption-above))
1604 (concat "\n" caption))))))
1607 ;;;; Statistics Cookie
1609 (defun org-ascii-statistics-cookie (statistics-cookie contents info)
1610 "Transcode a STATISTICS-COOKIE object from Org to ASCII.
1611 CONTENTS is nil. INFO is a plist holding contextual information."
1612 (org-element-property :value statistics-cookie))
1615 ;;;; Subscript
1617 (defun org-ascii-subscript (subscript contents info)
1618 "Transcode a SUBSCRIPT object from Org to ASCII.
1619 CONTENTS is the contents of the object. INFO is a plist holding
1620 contextual information."
1621 (if (org-element-property :use-brackets-p subscript)
1622 (format "_{%s}" contents)
1623 (format "_%s" contents)))
1626 ;;;; Superscript
1628 (defun org-ascii-superscript (superscript contents info)
1629 "Transcode a SUPERSCRIPT object from Org to ASCII.
1630 CONTENTS is the contents of the object. INFO is a plist holding
1631 contextual information."
1632 (if (org-element-property :use-brackets-p superscript)
1633 (format "_{%s}" contents)
1634 (format "_%s" contents)))
1637 ;;;; Strike-through
1639 (defun org-ascii-strike-through (strike-through contents info)
1640 "Transcode STRIKE-THROUGH from Org to ASCII.
1641 CONTENTS is text with strike-through markup. INFO is a plist
1642 holding contextual information."
1643 (format "+%s+" contents))
1646 ;;;; Table
1648 (defun org-ascii-table (table contents info)
1649 "Transcode a TABLE element from Org to ASCII.
1650 CONTENTS is the contents of the table. INFO is a plist holding
1651 contextual information."
1652 (let ((caption (org-ascii--build-caption table info)))
1653 (concat
1654 ;; Possibly add a caption string above.
1655 (when (and caption org-ascii-caption-above) (concat caption "\n"))
1656 ;; Insert table. Note: "table.el" tables are left unmodified.
1657 (cond ((eq (org-element-property :type table) 'org) contents)
1658 ((and org-ascii-table-use-ascii-art
1659 (eq (plist-get info :ascii-charset) 'utf-8)
1660 (require 'ascii-art-to-unicode nil t))
1661 (with-temp-buffer
1662 (insert (org-remove-indentation
1663 (org-element-property :value table)))
1664 (goto-char (point-min))
1665 (aa2u)
1666 (goto-char (point-max))
1667 (skip-chars-backward " \r\t\n")
1668 (buffer-substring (point-min) (point))))
1669 (t (org-remove-indentation (org-element-property :value table))))
1670 ;; Possible add a caption string below.
1671 (and (not org-ascii-caption-above) caption))))
1674 ;;;; Table Cell
1676 (defun org-ascii--table-cell-width (table-cell info)
1677 "Return width of TABLE-CELL.
1679 INFO is a plist used as a communication channel.
1681 Width of a cell is determined either by a width cookie in the
1682 same column as the cell, or by the maximum cell's length in that
1683 column.
1685 When `org-ascii-table-widen-columns' is non-nil, width cookies
1686 are ignored."
1687 (let* ((row (org-export-get-parent table-cell))
1688 (table (org-export-get-parent row))
1689 (col (let ((cells (org-element-contents row)))
1690 (- (length cells) (length (memq table-cell cells)))))
1691 (cache
1692 (or (plist-get info :ascii-table-cell-width-cache)
1693 (plist-get (setq info
1694 (plist-put info :ascii-table-cell-width-cache
1695 (make-hash-table :test 'equal)))
1696 :ascii-table-cell-width-cache)))
1697 (key (cons table col)))
1698 (or (gethash key cache)
1699 (puthash
1701 (or (and (not org-ascii-table-widen-columns)
1702 (org-export-table-cell-width table-cell info))
1703 (let* ((max-width 0))
1704 (org-element-map table 'table-row
1705 (lambda (row)
1706 (setq max-width
1707 (max (length
1708 (org-export-data
1709 (org-element-contents
1710 (elt (org-element-contents row) col))
1711 info))
1712 max-width)))
1713 info)
1714 max-width))
1715 cache))))
1717 (defun org-ascii-table-cell (table-cell contents info)
1718 "Transcode a TABLE-CELL object from Org to ASCII.
1719 CONTENTS is the cell contents. INFO is a plist used as
1720 a communication channel."
1721 ;; Determine column width. When `org-ascii-table-widen-columns'
1722 ;; is nil and some width cookie has set it, use that value.
1723 ;; Otherwise, compute the maximum width among transcoded data of
1724 ;; each cell in the column.
1725 (let ((width (org-ascii--table-cell-width table-cell info)))
1726 ;; When contents are too large, truncate them.
1727 (unless (or org-ascii-table-widen-columns (<= (length contents) width))
1728 (setq contents (concat (substring contents 0 (- width 2)) "=>")))
1729 ;; Align contents correctly within the cell.
1730 (let* ((indent-tabs-mode nil)
1731 (data
1732 (when contents
1733 (org-ascii--justify-string
1734 contents width
1735 (org-export-table-cell-alignment table-cell info)))))
1736 (setq contents (concat data (make-string (- width (length data)) ? ))))
1737 ;; Return cell.
1738 (concat (format " %s " contents)
1739 (when (memq 'right (org-export-table-cell-borders table-cell info))
1740 (if (eq (plist-get info :ascii-charset) 'utf-8) "│" "|")))))
1743 ;;;; Table Row
1745 (defun org-ascii-table-row (table-row contents info)
1746 "Transcode a TABLE-ROW element from Org to ASCII.
1747 CONTENTS is the row contents. INFO is a plist used as
1748 a communication channel."
1749 (when (eq (org-element-property :type table-row) 'standard)
1750 (let ((build-hline
1751 (function
1752 (lambda (lcorner horiz vert rcorner)
1753 (concat
1754 (apply
1755 'concat
1756 (org-element-map table-row 'table-cell
1757 (lambda (cell)
1758 (let ((width (org-ascii--table-cell-width cell info))
1759 (borders (org-export-table-cell-borders cell info)))
1760 (concat
1761 ;; In order to know if CELL starts the row, do
1762 ;; not compare it with the first cell in the
1763 ;; row as there might be a special column.
1764 ;; Instead, compare it with first exportable
1765 ;; cell, obtained with `org-element-map'.
1766 (when (and (memq 'left borders)
1767 (eq (org-element-map table-row 'table-cell
1768 'identity info t)
1769 cell))
1770 lcorner)
1771 (make-string (+ 2 width) (string-to-char horiz))
1772 (cond
1773 ((not (memq 'right borders)) nil)
1774 ((eq (car (last (org-element-contents table-row))) cell)
1775 rcorner)
1776 (t vert)))))
1777 info)) "\n"))))
1778 (utf8p (eq (plist-get info :ascii-charset) 'utf-8))
1779 (borders (org-export-table-cell-borders
1780 (org-element-map table-row 'table-cell 'identity info t)
1781 info)))
1782 (concat (cond
1783 ((and (memq 'top borders) (or utf8p (memq 'above borders)))
1784 (if utf8p (funcall build-hline "┍" "━" "┯" "┑")
1785 (funcall build-hline "+" "-" "+" "+")))
1786 ((memq 'above borders)
1787 (if utf8p (funcall build-hline "├" "─" "┼" "┤")
1788 (funcall build-hline "+" "-" "+" "+"))))
1789 (when (memq 'left borders) (if utf8p "│" "|"))
1790 contents "\n"
1791 (when (and (memq 'bottom borders) (or utf8p (memq 'below borders)))
1792 (if utf8p (funcall build-hline "┕" "━" "┷" "┙")
1793 (funcall build-hline "+" "-" "+" "+")))))))
1796 ;;;; Timestamp
1798 (defun org-ascii-timestamp (timestamp contents info)
1799 "Transcode a TIMESTAMP object from Org to ASCII.
1800 CONTENTS is nil. INFO is a plist holding contextual information."
1801 (org-ascii-plain-text (org-timestamp-translate timestamp) info))
1804 ;;;; Underline
1806 (defun org-ascii-underline (underline contents info)
1807 "Transcode UNDERLINE from Org to ASCII.
1808 CONTENTS is the text with underline markup. INFO is a plist
1809 holding contextual information."
1810 (format "_%s_" contents))
1813 ;;;; Verbatim
1815 (defun org-ascii-verbatim (verbatim contents info)
1816 "Return a VERBATIM object from Org to ASCII.
1817 CONTENTS is nil. INFO is a plist holding contextual information."
1818 (format org-ascii-verbatim-format
1819 (org-element-property :value verbatim)))
1822 ;;;; Verse Block
1824 (defun org-ascii-verse-block (verse-block contents info)
1825 "Transcode a VERSE-BLOCK element from Org to ASCII.
1826 CONTENTS is verse block contents. INFO is a plist holding
1827 contextual information."
1828 (let ((verse-width (org-ascii--current-text-width verse-block info)))
1829 (org-ascii--indent-string
1830 (org-ascii--justify-string contents verse-width 'left)
1831 org-ascii-quote-margin)))
1835 ;;; Filters
1837 (defun org-ascii-filter-headline-blank-lines (headline back-end info)
1838 "Filter controlling number of blank lines after a headline.
1840 HEADLINE is a string representing a transcoded headline.
1841 BACK-END is symbol specifying back-end used for export. INFO is
1842 plist containing the communication channel.
1844 This function only applies to `ascii' back-end. See
1845 `org-ascii-headline-spacing' for information."
1846 (if (not org-ascii-headline-spacing) headline
1847 (let ((blanks (make-string (1+ (cdr org-ascii-headline-spacing)) ?\n)))
1848 (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" blanks headline))))
1850 (defun org-ascii-filter-paragraph-spacing (tree back-end info)
1851 "Filter controlling number of blank lines between paragraphs.
1853 TREE is the parse tree. BACK-END is the symbol specifying
1854 back-end used for export. INFO is a plist used as
1855 a communication channel.
1857 See `org-ascii-paragraph-spacing' for information."
1858 (when (wholenump org-ascii-paragraph-spacing)
1859 (org-element-map tree 'paragraph
1860 (lambda (p)
1861 (when (eq (org-element-type (org-export-get-next-element p info))
1862 'paragraph)
1863 (org-element-put-property
1864 p :post-blank org-ascii-paragraph-spacing)))))
1865 tree)
1867 (defun org-ascii-filter-comment-spacing (tree backend info)
1868 "Filter removing blank lines between comments.
1869 TREE is the parse tree. BACK-END is the symbol specifying
1870 back-end used for export. INFO is a plist used as
1871 a communication channel."
1872 (org-element-map tree '(comment comment-block)
1873 (lambda (c)
1874 (when (memq (org-element-type (org-export-get-next-element c info))
1875 '(comment comment-block))
1876 (org-element-put-property c :post-blank 0))))
1877 tree)
1881 ;;; End-user functions
1883 ;;;###autoload
1884 (defun org-ascii-export-as-ascii
1885 (&optional async subtreep visible-only body-only ext-plist)
1886 "Export current buffer to a text buffer.
1888 If narrowing is active in the current buffer, only export its
1889 narrowed part.
1891 If a region is active, export that region.
1893 A non-nil optional argument ASYNC means the process should happen
1894 asynchronously. The resulting buffer should be accessible
1895 through the `org-export-stack' interface.
1897 When optional argument SUBTREEP is non-nil, export the sub-tree
1898 at point, extracting information from the headline properties
1899 first.
1901 When optional argument VISIBLE-ONLY is non-nil, don't export
1902 contents of hidden elements.
1904 When optional argument BODY-ONLY is non-nil, strip title and
1905 table of contents from output.
1907 EXT-PLIST, when provided, is a property list with external
1908 parameters overriding Org default settings, but still inferior to
1909 file-local settings.
1911 Export is done in a buffer named \"*Org ASCII Export*\", which
1912 will be displayed when `org-export-show-temporary-export-buffer'
1913 is non-nil."
1914 (interactive)
1915 (org-export-to-buffer 'ascii "*Org ASCII Export*"
1916 async subtreep visible-only body-only ext-plist (lambda () (text-mode))))
1918 ;;;###autoload
1919 (defun org-ascii-export-to-ascii
1920 (&optional async subtreep visible-only body-only ext-plist)
1921 "Export current buffer to a text file.
1923 If narrowing is active in the current buffer, only export its
1924 narrowed part.
1926 If a region is active, export that region.
1928 A non-nil optional argument ASYNC means the process should happen
1929 asynchronously. The resulting file should be accessible through
1930 the `org-export-stack' interface.
1932 When optional argument SUBTREEP is non-nil, export the sub-tree
1933 at point, extracting information from the headline properties
1934 first.
1936 When optional argument VISIBLE-ONLY is non-nil, don't export
1937 contents of hidden elements.
1939 When optional argument BODY-ONLY is non-nil, strip title and
1940 table of contents from output.
1942 EXT-PLIST, when provided, is a property list with external
1943 parameters overriding Org default settings, but still inferior to
1944 file-local settings.
1946 Return output file's name."
1947 (interactive)
1948 (let ((file (org-export-output-file-name ".txt" subtreep)))
1949 (org-export-to-file 'ascii file
1950 async subtreep visible-only body-only ext-plist)))
1952 ;;;###autoload
1953 (defun org-ascii-publish-to-ascii (plist filename pub-dir)
1954 "Publish an Org file to ASCII.
1956 FILENAME is the filename of the Org file to be published. PLIST
1957 is the property list for the given project. PUB-DIR is the
1958 publishing directory.
1960 Return output file name."
1961 (org-publish-org-to
1962 'ascii filename ".txt" `(:ascii-charset ascii ,@plist) pub-dir))
1964 ;;;###autoload
1965 (defun org-ascii-publish-to-latin1 (plist filename pub-dir)
1966 "Publish an Org file to Latin-1.
1968 FILENAME is the filename of the Org file to be published. PLIST
1969 is the property list for the given project. PUB-DIR is the
1970 publishing directory.
1972 Return output file name."
1973 (org-publish-org-to
1974 'ascii filename ".txt" `(:ascii-charset latin1 ,@plist) pub-dir))
1976 ;;;###autoload
1977 (defun org-ascii-publish-to-utf8 (plist filename pub-dir)
1978 "Publish an org file to UTF-8.
1980 FILENAME is the filename of the Org file to be published. PLIST
1981 is the property list for the given project. PUB-DIR is the
1982 publishing directory.
1984 Return output file name."
1985 (org-publish-org-to
1986 'ascii filename ".txt" `(:ascii-charset utf-8 ,@plist) pub-dir))
1989 (provide 'ox-ascii)
1991 ;; Local variables:
1992 ;; generated-autoload-file: "org-loaddefs.el"
1993 ;; coding: utf-8-emacs
1994 ;; End:
1996 ;;; ox-ascii.el ends here