ox-ascii: Tiny fix
[org-mode.git] / lisp / ox-ascii.el
blobb4efa538fe6b04cb995ea17e9534555f4bd9a3b5
1 ;;; ox-ascii.el --- ASCII Back-End for Org Export Engine
3 ;; Copyright (C) 2012-2014 Free Software Foundation, Inc.
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; This library implements an ASCII back-end for Org generic exporter.
26 ;; See Org manual for more information.
28 ;;; Code:
30 (eval-when-compile (require 'cl))
31 (require 'ox)
32 (require 'ox-publish)
34 (declare-function aa2u "ext:ascii-art-to-unicode" ())
36 ;;; Define Back-End
38 ;; The following setting won't allow to modify preferred charset
39 ;; through a buffer keyword or an option item, but, since the property
40 ;; will appear in communication channel nonetheless, it allows to
41 ;; override `org-ascii-charset' variable on the fly by the ext-plist
42 ;; mechanism.
44 ;; We also install a filter for headlines and sections, in order to
45 ;; control blank lines separating them in output string.
47 (org-export-define-backend 'ascii
48 '((bold . org-ascii-bold)
49 (center-block . org-ascii-center-block)
50 (clock . org-ascii-clock)
51 (code . org-ascii-code)
52 (comment . (lambda (&rest args) ""))
53 (comment-block . (lambda (&rest args) ""))
54 (drawer . org-ascii-drawer)
55 (dynamic-block . org-ascii-dynamic-block)
56 (entity . org-ascii-entity)
57 (example-block . org-ascii-example-block)
58 (export-block . org-ascii-export-block)
59 (export-snippet . org-ascii-export-snippet)
60 (fixed-width . org-ascii-fixed-width)
61 (footnote-reference . org-ascii-footnote-reference)
62 (headline . org-ascii-headline)
63 (horizontal-rule . org-ascii-horizontal-rule)
64 (inline-src-block . org-ascii-inline-src-block)
65 (inlinetask . org-ascii-inlinetask)
66 (inner-template . org-ascii-inner-template)
67 (italic . org-ascii-italic)
68 (item . org-ascii-item)
69 (keyword . org-ascii-keyword)
70 (latex-environment . org-ascii-latex-environment)
71 (latex-fragment . org-ascii-latex-fragment)
72 (line-break . org-ascii-line-break)
73 (link . org-ascii-link)
74 (paragraph . org-ascii-paragraph)
75 (plain-list . org-ascii-plain-list)
76 (plain-text . org-ascii-plain-text)
77 (planning . org-ascii-planning)
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 width, unless it is located at the beginning of
196 a section, in which case indentation is removed from that line.
197 If it is the symbol `auto' preserve indentation from original
198 document."
199 :group 'org-export-ascii
200 :version "24.4"
201 :package-version '(Org . "8.0")
202 :type '(choice
203 (integer :tag "Number of white spaces characters")
204 (const :tag "Preserve original width" auto)))
206 (defcustom org-ascii-paragraph-spacing 'auto
207 "Number of white lines between paragraphs.
208 If the value is an integer, add this number of blank lines
209 between contiguous paragraphs. If is it the symbol `auto', keep
210 the same number of blank lines as in the original document."
211 :group 'org-export-ascii
212 :version "24.4"
213 :package-version '(Org . "8.0")
214 :type '(choice
215 (integer :tag "Number of blank lines")
216 (const :tag "Preserve original spacing" auto)))
218 (defcustom org-ascii-charset 'ascii
219 "The charset allowed to represent various elements and objects.
220 Possible values are:
221 `ascii' Only use plain ASCII characters
222 `latin1' Include Latin-1 characters
223 `utf-8' Use all UTF-8 characters"
224 :group 'org-export-ascii
225 :version "24.4"
226 :package-version '(Org . "8.0")
227 :type '(choice
228 (const :tag "ASCII" ascii)
229 (const :tag "Latin-1" latin1)
230 (const :tag "UTF-8" utf-8)))
232 (defcustom org-ascii-underline '((ascii ?= ?~ ?-)
233 (latin1 ?= ?~ ?-)
234 (utf-8 ?═ ?─ ?╌ ?┄ ?┈))
235 "Characters for underlining headings in ASCII export.
237 Alist whose key is a symbol among `ascii', `latin1' and `utf-8'
238 and whose value is a list of characters.
240 For each supported charset, this variable associates a sequence
241 of underline characters. In a sequence, the characters will be
242 used in order for headlines level 1, 2, ... If no character is
243 available for a given level, the headline won't be underlined."
244 :group 'org-export-ascii
245 :version "24.4"
246 :package-version '(Org . "8.0")
247 :type '(list
248 (cons :tag "Underline characters sequence"
249 (const :tag "ASCII charset" ascii)
250 (repeat character))
251 (cons :tag "Underline characters sequence"
252 (const :tag "Latin-1 charset" latin1)
253 (repeat character))
254 (cons :tag "Underline characters sequence"
255 (const :tag "UTF-8 charset" utf-8)
256 (repeat character))))
258 (defcustom org-ascii-bullets '((ascii ?* ?+ ?-)
259 (latin1 ?§ ?¶)
260 (utf-8 ?◊))
261 "Bullet characters for headlines converted to lists in ASCII export.
263 Alist whose key is a symbol among `ascii', `latin1' and `utf-8'
264 and whose value is a list of characters.
266 The first character is used for the first level considered as low
267 level, and so on. If there are more levels than characters given
268 here, the list will be repeated.
270 Note that this variable doesn't affect plain lists
271 representation."
272 :group 'org-export-ascii
273 :version "24.4"
274 :package-version '(Org . "8.0")
275 :type '(list
276 (cons :tag "Bullet characters for low level headlines"
277 (const :tag "ASCII charset" ascii)
278 (repeat character))
279 (cons :tag "Bullet characters for low level headlines"
280 (const :tag "Latin-1 charset" latin1)
281 (repeat character))
282 (cons :tag "Bullet characters for low level headlines"
283 (const :tag "UTF-8 charset" utf-8)
284 (repeat character))))
286 (defcustom org-ascii-links-to-notes t
287 "Non-nil means convert links to notes before the next headline.
288 When nil, the link will be exported in place. If the line
289 becomes long in this way, it will be wrapped."
290 :group 'org-export-ascii
291 :version "24.4"
292 :package-version '(Org . "8.0")
293 :type 'boolean)
295 (defcustom org-ascii-table-keep-all-vertical-lines nil
296 "Non-nil means keep all vertical lines in ASCII tables.
297 When nil, vertical lines will be removed except for those needed
298 for column grouping."
299 :group 'org-export-ascii
300 :version "24.4"
301 :package-version '(Org . "8.0")
302 :type 'boolean)
304 (defcustom org-ascii-table-widen-columns t
305 "Non-nil means widen narrowed columns for export.
306 When nil, narrowed columns will look in ASCII export just like in
307 Org mode, i.e. with \"=>\" as ellipsis."
308 :group 'org-export-ascii
309 :version "24.4"
310 :package-version '(Org . "8.0")
311 :type 'boolean)
313 (defcustom org-ascii-table-use-ascii-art nil
314 "Non-nil means table.el tables are turned into ascii-art.
316 It only makes sense when export charset is `utf-8'. It is nil by
317 default since it requires ascii-art-to-unicode.el package. You
318 can download it here:
320 http://gnuvola.org/software/j/aa2u/ascii-art-to-unicode.el."
321 :group 'org-export-ascii
322 :version "24.4"
323 :package-version '(Org . "8.0")
324 :type 'boolean)
326 (defcustom org-ascii-caption-above nil
327 "When non-nil, place caption string before the element.
328 Otherwise, place it right after it."
329 :group 'org-export-ascii
330 :version "24.4"
331 :package-version '(Org . "8.0")
332 :type 'boolean)
334 (defcustom org-ascii-verbatim-format "`%s'"
335 "Format string used for verbatim text and inline code."
336 :group 'org-export-ascii
337 :version "24.4"
338 :package-version '(Org . "8.0")
339 :type 'string)
341 (defcustom org-ascii-format-drawer-function
342 (lambda (name contents width) contents)
343 "Function called to format a drawer in ASCII.
345 The function must accept three parameters:
346 NAME the drawer name, like \"LOGBOOK\"
347 CONTENTS the contents of the drawer.
348 WIDTH the text width within the drawer.
350 The function should return either the string to be exported or
351 nil to ignore the drawer.
353 The default value simply returns the value of CONTENTS."
354 :group 'org-export-ascii
355 :version "24.4"
356 :package-version '(Org . "8.0")
357 :type 'function)
359 (defcustom org-ascii-format-inlinetask-function
360 'org-ascii-format-inlinetask-default
361 "Function called to format an inlinetask in ASCII.
363 The function must accept nine parameters:
364 TODO the todo keyword, as a string
365 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
366 PRIORITY the inlinetask priority, as a string
367 NAME the inlinetask name, as a string.
368 TAGS the inlinetask tags, as a list of strings.
369 CONTENTS the contents of the inlinetask, as a string.
370 WIDTH the width of the inlinetask, as a number.
371 INLINETASK the inlinetask itself.
372 INFO the info channel.
374 The function should return either the string to be exported or
375 nil to ignore the inline task."
376 :group 'org-export-ascii
377 :version "24.4"
378 :package-version '(Org . "8.3")
379 :type 'function)
383 ;;; Internal Functions
385 ;; Internal functions fall into three categories.
387 ;; The first one is about text formatting. The core function is
388 ;; `org-ascii--current-text-width', which determines the current
389 ;; text width allowed to a given element. In other words, it helps
390 ;; keeping each line width within maximum text width defined in
391 ;; `org-ascii-text-width'. Once this information is known,
392 ;; `org-ascii--fill-string', `org-ascii--justify-string',
393 ;; `org-ascii--box-string' and `org-ascii--indent-string' can
394 ;; operate on a given output string.
396 ;; The second category contains functions handling elements listings,
397 ;; triggered by "#+TOC:" keyword. As such, `org-ascii--build-toc'
398 ;; returns a complete table of contents, `org-ascii--list-listings'
399 ;; returns a list of referenceable src-block elements, and
400 ;; `org-ascii--list-tables' does the same for table elements.
402 ;; The third category includes general helper functions.
403 ;; `org-ascii--build-title' creates the title for a given headline
404 ;; or inlinetask element. `org-ascii--build-caption' returns the
405 ;; caption string associated to a table or a src-block.
406 ;; `org-ascii--describe-links' creates notes about links for
407 ;; insertion at the end of a section. It uses
408 ;; `org-ascii--unique-links' to get the list of links to describe.
409 ;; Eventually, `org-ascii--translate' translates a string according
410 ;; to language and charset specification.
413 (defun org-ascii--fill-string (s text-width info &optional justify)
414 "Fill a string with specified text-width and return it.
416 S is the string being filled. TEXT-WIDTH is an integer
417 specifying maximum length of a line. INFO is the plist used as
418 a communication channel.
420 Optional argument JUSTIFY can specify any type of justification
421 among `left', `center', `right' or `full'. A nil value is
422 equivalent to `left'. For a justification that doesn't also fill
423 string, see `org-ascii--justify-string'.
425 Return nil if S isn't a string."
426 ;; Don't fill paragraph when break should be preserved.
427 (cond ((not (stringp s)) nil)
428 ((plist-get info :preserve-breaks) s)
429 (t (let ((double-space-p sentence-end-double-space))
430 (with-temp-buffer
431 (let ((fill-column text-width)
432 (use-hard-newlines t)
433 (sentence-end-double-space double-space-p))
434 (insert s)
435 (fill-region (point-min) (point-max) justify))
436 (buffer-string))))))
438 (defun org-ascii--justify-string (s text-width how)
439 "Justify string S.
440 TEXT-WIDTH is an integer specifying maximum length of a line.
441 HOW determines the type of justification: it can be `left',
442 `right', `full' or `center'."
443 (with-temp-buffer
444 (insert s)
445 (goto-char (point-min))
446 (let ((fill-column text-width)
447 ;; Disable `adaptive-fill-mode' so it doesn't prevent
448 ;; filling lines matching `adaptive-fill-regexp'.
449 (adaptive-fill-mode nil))
450 (while (< (point) (point-max))
451 (justify-current-line how)
452 (forward-line)))
453 (buffer-string)))
455 (defun org-ascii--indent-string (s width)
456 "Indent string S by WIDTH white spaces.
457 Empty lines are not indented."
458 (when (stringp s)
459 (replace-regexp-in-string
460 "\\(^\\)[ \t]*\\S-" (make-string width ?\s) s nil nil 1)))
462 (defun org-ascii--box-string (s info)
463 "Return string S with a partial box to its left.
464 INFO is a plist used as a communication channel."
465 (let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
466 (format (if utf8p "╭────\n%s\n╰────" ",----\n%s\n`----")
467 (replace-regexp-in-string
468 "^" (if utf8p "│ " "| ")
469 ;; Remove last newline character.
470 (replace-regexp-in-string "\n[ \t]*\\'" "" s)))))
472 (defun org-ascii--current-text-width (element info)
473 "Return maximum text width for ELEMENT's contents.
474 INFO is a plist used as a communication channel."
475 (case (org-element-type element)
476 ;; Elements with an absolute width: `headline' and `inlinetask'.
477 (inlinetask org-ascii-inlinetask-width)
478 (headline
479 (- org-ascii-text-width
480 (let ((low-level-rank (org-export-low-level-p element info)))
481 (if low-level-rank (* low-level-rank 2) org-ascii-global-margin))))
482 ;; Elements with a relative width: store maximum text width in
483 ;; TOTAL-WIDTH.
484 (otherwise
485 (let* ((genealogy (cons element (org-export-get-genealogy element)))
486 ;; Total width is determined by the presence, or not, of an
487 ;; inline task among ELEMENT parents.
488 (total-width
489 (if (loop for parent in genealogy
490 thereis (eq (org-element-type parent) 'inlinetask))
491 org-ascii-inlinetask-width
492 ;; No inlinetask: Remove global margin from text width.
493 (- org-ascii-text-width
494 org-ascii-global-margin
495 (let ((parent (org-export-get-parent-headline element)))
496 ;; Inner margin doesn't apply to text before first
497 ;; headline.
498 (if (not parent) 0
499 (let ((low-level-rank
500 (org-export-low-level-p parent info)))
501 ;; Inner margin doesn't apply to contents of
502 ;; low level headlines, since they've got their
503 ;; own indentation mechanism.
504 (if low-level-rank (* low-level-rank 2)
505 org-ascii-inner-margin))))))))
506 (- total-width
507 ;; Each `quote-block', `quote-section' and `verse-block' above
508 ;; narrows text width by twice the standard margin size.
509 (+ (* (loop for parent in genealogy
510 when (memq (org-element-type parent)
511 '(quote-block quote-section verse-block))
512 count parent)
513 2 org-ascii-quote-margin)
514 ;; Text width within a plain-list is restricted by
515 ;; indentation of current item. If that's the case,
516 ;; compute it with the help of `:structure' property from
517 ;; parent item, if any.
518 (let ((parent-item
519 (if (eq (org-element-type element) 'item) element
520 (loop for parent in genealogy
521 when (eq (org-element-type parent) 'item)
522 return parent))))
523 (if (not parent-item) 0
524 ;; Compute indentation offset of the current item,
525 ;; that is the sum of the difference between its
526 ;; indentation and the indentation of the top item in
527 ;; the list and current item bullet's length. Also
528 ;; remove checkbox length, and tag length (for
529 ;; description lists) or bullet length.
530 (let ((struct (org-element-property :structure parent-item))
531 (beg-item (org-element-property :begin parent-item)))
532 (+ (- (org-list-get-ind beg-item struct)
533 (org-list-get-ind
534 (org-list-get-top-point struct) struct))
535 (string-width (or (org-ascii--checkbox parent-item info)
536 ""))
537 (string-width
538 (or (org-list-get-tag beg-item struct)
539 (org-list-get-bullet beg-item struct)))))))))))))
541 (defun org-ascii--build-title
542 (element info text-width &optional underline notags toc)
543 "Format ELEMENT title and return it.
545 ELEMENT is either an `headline' or `inlinetask' element. INFO is
546 a plist used as a communication channel. TEXT-WIDTH is an
547 integer representing the maximum length of a line.
549 When optional argument UNDERLINE is non-nil, underline title,
550 without the tags, according to `org-ascii-underline'
551 specifications.
553 If optional argument NOTAGS is non-nil, no tags will be added to
554 the title.
556 When optional argument TOC is non-nil, use optional title if
557 possible. It doesn't apply to `inlinetask' elements."
558 (let* ((headlinep (eq (org-element-type element) 'headline))
559 (numbers
560 ;; Numbering is specific to headlines.
561 (and headlinep (org-export-numbered-headline-p element info)
562 ;; All tests passed: build numbering string.
563 (concat
564 (mapconcat
565 'number-to-string
566 (org-export-get-headline-number element info) ".")
567 " ")))
568 (text
569 (org-trim
570 (org-export-data
571 (if (and toc headlinep) (org-export-get-alt-title element info)
572 (org-element-property :title element))
573 info)))
574 (todo
575 (and (plist-get info :with-todo-keywords)
576 (let ((todo (org-element-property :todo-keyword element)))
577 (and todo (concat (org-export-data todo info) " ")))))
578 (tags (and (not notags)
579 (plist-get info :with-tags)
580 (let ((tag-list (org-export-get-tags element info)))
581 (and tag-list
582 (format ":%s:"
583 (mapconcat 'identity tag-list ":"))))))
584 (priority
585 (and (plist-get info :with-priority)
586 (let ((char (org-element-property :priority element)))
587 (and char (format "(#%c) " char)))))
588 (first-part (concat numbers todo priority text)))
589 (concat
590 first-part
591 ;; Align tags, if any.
592 (when tags
593 (format
594 (format " %%%ds"
595 (max (- text-width (1+ (string-width first-part)))
596 (string-width tags)))
597 tags))
598 ;; Maybe underline text, if ELEMENT type is `headline' and an
599 ;; underline character has been defined.
600 (when (and underline headlinep)
601 (let ((under-char
602 (nth (1- (org-export-get-relative-level element info))
603 (cdr (assq (plist-get info :ascii-charset)
604 org-ascii-underline)))))
605 (and under-char
606 (concat "\n"
607 (make-string (/ (string-width first-part)
608 (char-width under-char))
609 under-char))))))))
611 (defun org-ascii--has-caption-p (element info)
612 "Non-nil when ELEMENT has a caption affiliated keyword.
613 INFO is a plist used as a communication channel. This function
614 is meant to be used as a predicate for `org-export-get-ordinal'."
615 (org-element-property :caption element))
617 (defun org-ascii--build-caption (element info)
618 "Return caption string for ELEMENT, if applicable.
620 INFO is a plist used as a communication channel.
622 The caption string contains the sequence number of ELEMENT along
623 with its real caption. Return nil when ELEMENT has no affiliated
624 caption keyword."
625 (let ((caption (org-export-get-caption element)))
626 (when caption
627 ;; Get sequence number of current src-block among every
628 ;; src-block with a caption.
629 (let ((reference
630 (org-export-get-ordinal
631 element info nil 'org-ascii--has-caption-p))
632 (title-fmt (org-ascii--translate
633 (case (org-element-type element)
634 (table "Table %d:")
635 (src-block "Listing %d:"))
636 info)))
637 (org-ascii--fill-string
638 (concat (format title-fmt reference)
640 (org-export-data caption info))
641 (org-ascii--current-text-width element info) info)))))
643 (defun org-ascii--build-toc (info &optional n keyword)
644 "Return a table of contents.
646 INFO is a plist used as a communication channel.
648 Optional argument N, when non-nil, is an integer specifying the
649 depth of the table.
651 Optional argument KEYWORD specifies the TOC keyword, if any, from
652 which the table of contents generation has been initiated."
653 (let ((title (org-ascii--translate "Table of Contents" info)))
654 (concat
655 title "\n"
656 (make-string (string-width title)
657 (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))
658 "\n\n"
659 (let ((text-width
660 (if keyword (org-ascii--current-text-width keyword info)
661 (- org-ascii-text-width org-ascii-global-margin))))
662 (mapconcat
663 (lambda (headline)
664 (let* ((level (org-export-get-relative-level headline info))
665 (indent (* (1- level) 3)))
666 (concat
667 (unless (zerop indent) (concat (make-string (1- indent) ?.) " "))
668 (org-ascii--build-title
669 headline info (- text-width indent) nil
670 (or (not (plist-get info :with-tags))
671 (eq (plist-get info :with-tags) 'not-in-toc))
672 'toc))))
673 (org-export-collect-headlines info n) "\n")))))
675 (defun org-ascii--list-listings (keyword info)
676 "Return a list of listings.
678 KEYWORD is the keyword that initiated the list of listings
679 generation. INFO is a plist used as a communication channel."
680 (let ((title (org-ascii--translate "List of Listings" info)))
681 (concat
682 title "\n"
683 (make-string (string-width title)
684 (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))
685 "\n\n"
686 (let ((text-width
687 (if keyword (org-ascii--current-text-width keyword info)
688 (- org-ascii-text-width org-ascii-global-margin)))
689 ;; Use a counter instead of retrieving ordinal of each
690 ;; src-block.
691 (count 0))
692 (mapconcat
693 (lambda (src-block)
694 ;; Store initial text so its length can be computed. This is
695 ;; used to properly align caption right to it in case of
696 ;; filling (like contents of a description list item).
697 (let* ((initial-text
698 (format (org-ascii--translate "Listing %d:" info)
699 (incf count)))
700 (initial-width (string-width initial-text)))
701 (concat
702 initial-text " "
703 (org-trim
704 (org-ascii--indent-string
705 (org-ascii--fill-string
706 ;; Use short name in priority, if available.
707 (let ((caption (or (org-export-get-caption src-block t)
708 (org-export-get-caption src-block))))
709 (org-export-data caption info))
710 (- text-width initial-width) info)
711 initial-width)))))
712 (org-export-collect-listings info) "\n")))))
714 (defun org-ascii--list-tables (keyword info)
715 "Return a list of tables.
717 KEYWORD is the keyword that initiated the list of tables
718 generation. INFO is a plist used as a communication channel."
719 (let ((title (org-ascii--translate "List of Tables" info)))
720 (concat
721 title "\n"
722 (make-string (string-width title)
723 (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))
724 "\n\n"
725 (let ((text-width
726 (if keyword (org-ascii--current-text-width keyword info)
727 (- org-ascii-text-width org-ascii-global-margin)))
728 ;; Use a counter instead of retrieving ordinal of each
729 ;; src-block.
730 (count 0))
731 (mapconcat
732 (lambda (table)
733 ;; Store initial text so its length can be computed. This is
734 ;; used to properly align caption right to it in case of
735 ;; filling (like contents of a description list item).
736 (let* ((initial-text
737 (format (org-ascii--translate "Table %d:" info)
738 (incf count)))
739 (initial-width (string-width initial-text)))
740 (concat
741 initial-text " "
742 (org-trim
743 (org-ascii--indent-string
744 (org-ascii--fill-string
745 ;; Use short name in priority, if available.
746 (let ((caption (or (org-export-get-caption table t)
747 (org-export-get-caption table))))
748 (org-export-data caption info))
749 (- text-width initial-width) info)
750 initial-width)))))
751 (org-export-collect-tables info) "\n")))))
753 (defun org-ascii--unique-links (element info)
754 "Return a list of unique link references in ELEMENT.
755 ELEMENT is either a headline element or a section element. INFO
756 is a plist used as a communication channel."
757 (let* (seen
758 (unique-link-p
759 (function
760 ;; Return LINK if it wasn't referenced so far, or nil.
761 ;; Update SEEN links along the way.
762 (lambda (link)
763 (let ((footprint
764 ;; Normalize description in footprints.
765 (cons (org-element-property :raw-link link)
766 (let ((contents (org-element-contents link)))
767 (and contents
768 (replace-regexp-in-string
769 "[ \r\t\n]+" " "
770 (org-trim
771 (org-element-interpret-data contents))))))))
772 ;; Ignore LINK if it hasn't been translated already.
773 ;; It can happen if it is located in an affiliated
774 ;; keyword that was ignored.
775 (when (and (org-string-nw-p
776 (gethash link (plist-get info :exported-data)))
777 (not (member footprint seen)))
778 (push footprint seen) link)))))
779 ;; If at a section, find parent headline, if any, in order to
780 ;; count links that might be in the title.
781 (headline
782 (if (eq (org-element-type element) 'headline) element
783 (or (org-export-get-parent-headline element) element))))
784 ;; Get all links in HEADLINE.
785 (org-element-map headline 'link
786 (lambda (l) (funcall unique-link-p l)) info nil nil t)))
788 (defun org-ascii--describe-links (links width info)
789 "Return a string describing a list of links.
791 LINKS is a list of link type objects, as returned by
792 `org-ascii--unique-links'. WIDTH is the text width allowed for
793 the output string. INFO is a plist used as a communication
794 channel."
795 (mapconcat
796 (lambda (link)
797 (let ((type (org-element-property :type link))
798 (anchor (let ((desc (org-element-contents link)))
799 (if desc (org-export-data desc info)
800 (org-element-property :raw-link link)))))
801 (cond
802 ;; Coderefs, radio links and fuzzy links are ignored.
803 ((member type '("coderef" "radio" "fuzzy")) nil)
804 ;; Id and custom-id links: Headlines refer to their numbering.
805 ((member type '("custom-id" "id"))
806 (let ((dest (org-export-resolve-id-link link info)))
807 (concat
808 (org-ascii--fill-string
809 (format
810 "[%s] %s"
811 anchor
812 (if (not dest) (org-ascii--translate "Unknown reference" info)
813 (format
814 (org-ascii--translate "See section %s" info)
815 (mapconcat 'number-to-string
816 (org-export-get-headline-number dest info) "."))))
817 width info) "\n\n")))
818 ;; Do not add a link that cannot be resolved and doesn't have
819 ;; any description: destination is already visible in the
820 ;; paragraph.
821 ((not (org-element-contents link)) nil)
823 (concat
824 (org-ascii--fill-string
825 (format "[%s] %s" anchor (org-element-property :raw-link link))
826 width info)
827 "\n\n")))))
828 links ""))
830 (defun org-ascii--checkbox (item info)
831 "Return checkbox string for ITEM or nil.
832 INFO is a plist used as a communication channel."
833 (let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
834 (case (org-element-property :checkbox item)
835 (on (if utf8p "☑ " "[X] "))
836 (off (if utf8p "☐ " "[ ] "))
837 (trans (if utf8p "☒ " "[-] ")))))
841 ;;; Template
843 (defun org-ascii-template--document-title (info)
844 "Return document title, as a string.
845 INFO is a plist used as a communication channel."
846 (let* ((text-width org-ascii-text-width)
847 ;; Links in the title will not be resolved later, so we make
848 ;; sure their path is located right after them.
849 (org-ascii-links-to-notes nil)
850 (title (org-export-data (plist-get info :title) info))
851 (author (and (plist-get info :with-author)
852 (let ((auth (plist-get info :author)))
853 (and auth (org-export-data auth info)))))
854 (email (and (plist-get info :with-email)
855 (org-export-data (plist-get info :email) info)))
856 (date (and (plist-get info :with-date)
857 (org-export-data (org-export-get-date info) info))))
858 ;; There are two types of title blocks depending on the presence
859 ;; of a title to display.
860 (if (string= title "")
861 ;; Title block without a title. DATE is positioned at the top
862 ;; right of the document, AUTHOR to the top left and EMAIL
863 ;; just below.
864 (cond
865 ((and (org-string-nw-p date) (org-string-nw-p author))
866 (concat
867 author
868 (make-string (- text-width (string-width date) (string-width author))
869 ?\s)
870 date
871 (when (org-string-nw-p email) (concat "\n" email))
872 "\n\n\n"))
873 ((and (org-string-nw-p date) (org-string-nw-p email))
874 (concat
875 email
876 (make-string (- text-width (string-width date) (string-width email))
877 ?\s)
878 date "\n\n\n"))
879 ((org-string-nw-p date)
880 (concat
881 (org-ascii--justify-string date text-width 'right)
882 "\n\n\n"))
883 ((and (org-string-nw-p author) (org-string-nw-p email))
884 (concat author "\n" email "\n\n\n"))
885 ((org-string-nw-p author) (concat author "\n\n\n"))
886 ((org-string-nw-p email) (concat email "\n\n\n")))
887 ;; Title block with a title. Document's TITLE, along with the
888 ;; AUTHOR and its EMAIL are both overlined and an underlined,
889 ;; centered. Date is just below, also centered.
890 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8))
891 ;; Format TITLE. It may be filled if it is too wide,
892 ;; that is wider than the two thirds of the total width.
893 (title-len (min (length title) (/ (* 2 text-width) 3)))
894 (formatted-title (org-ascii--fill-string title title-len info))
895 (line
896 (make-string
897 (min (+ (max title-len
898 (string-width (or author ""))
899 (string-width (or email "")))
901 text-width) (if utf8p ?━ ?_))))
902 (org-ascii--justify-string
903 (concat line "\n"
904 (unless utf8p "\n")
905 (upcase formatted-title)
906 (cond
907 ((and (org-string-nw-p author) (org-string-nw-p email))
908 (concat (if utf8p "\n\n\n" "\n\n") author "\n" email))
909 ((org-string-nw-p author)
910 (concat (if utf8p "\n\n\n" "\n\n") author))
911 ((org-string-nw-p email)
912 (concat (if utf8p "\n\n\n" "\n\n") email)))
913 "\n" line
914 (when (org-string-nw-p date) (concat "\n\n\n" date))
915 "\n\n\n") text-width 'center)))))
917 (defun org-ascii-inner-template (contents info)
918 "Return complete document string after ASCII conversion.
919 CONTENTS is the transcoded contents string. INFO is a plist
920 holding export options."
921 (org-element-normalize-string
922 (org-ascii--indent-string
923 (concat
924 ;; 1. Document's body.
925 contents
926 ;; 2. Footnote definitions.
927 (let ((definitions (org-export-collect-footnote-definitions
928 (plist-get info :parse-tree) info))
929 ;; Insert full links right inside the footnote definition
930 ;; as they have no chance to be inserted later.
931 (org-ascii-links-to-notes nil))
932 (when definitions
933 (concat
934 "\n\n\n"
935 (let ((title (org-ascii--translate "Footnotes" info)))
936 (concat
937 title "\n"
938 (make-string
939 (string-width title)
940 (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))))
941 "\n\n"
942 (let ((text-width (- org-ascii-text-width org-ascii-global-margin)))
943 (mapconcat
944 (lambda (ref)
945 (let ((id (format "[%s] " (car ref))))
946 ;; Distinguish between inline definitions and
947 ;; full-fledged definitions.
948 (org-trim
949 (let ((def (nth 2 ref)))
950 (if (eq (org-element-type def) 'org-data)
951 ;; Full-fledged definition: footnote ID is
952 ;; inserted inside the first parsed paragraph
953 ;; (FIRST), if any, to be sure filling will
954 ;; take it into consideration.
955 (let ((first (car (org-element-contents def))))
956 (if (not (eq (org-element-type first) 'paragraph))
957 (concat id "\n" (org-export-data def info))
958 (push id (nthcdr 2 first))
959 (org-export-data def info)))
960 ;; Fill paragraph once footnote ID is inserted
961 ;; in order to have a correct length for first
962 ;; line.
963 (org-ascii--fill-string
964 (concat id (org-export-data def info))
965 text-width info))))))
966 definitions "\n\n"))))))
967 org-ascii-global-margin)))
969 (defun org-ascii-template (contents info)
970 "Return complete document string after ASCII conversion.
971 CONTENTS is the transcoded contents string. INFO is a plist
972 holding export options."
973 (concat
974 ;; 1. Build title block.
975 (org-ascii--indent-string
976 (concat (org-ascii-template--document-title info)
977 ;; 2. Table of contents.
978 (let ((depth (plist-get info :with-toc)))
979 (when depth
980 (concat
981 (org-ascii--build-toc info (and (wholenump depth) depth))
982 "\n\n\n"))))
983 org-ascii-global-margin)
984 ;; 3. Document's body.
985 contents
986 ;; 4. Creator. Ignore `comment' value as there are no comments in
987 ;; ASCII. Justify it to the bottom right.
988 (org-ascii--indent-string
989 (let ((creator-info (plist-get info :with-creator))
990 (text-width (- org-ascii-text-width org-ascii-global-margin)))
991 (unless (or (not creator-info) (eq creator-info 'comment))
992 (concat
993 "\n\n\n"
994 (org-ascii--fill-string
995 (plist-get info :creator) text-width info 'right))))
996 org-ascii-global-margin)))
998 (defun org-ascii--translate (s info)
999 "Translate string S according to specified language and charset.
1000 INFO is a plist used as a communication channel."
1001 (let ((charset (intern (format ":%s" (plist-get info :ascii-charset)))))
1002 (org-export-translate s charset info)))
1006 ;;; Transcode Functions
1008 ;;;; Bold
1010 (defun org-ascii-bold (bold contents info)
1011 "Transcode BOLD from Org to ASCII.
1012 CONTENTS is the text with bold markup. INFO is a plist holding
1013 contextual information."
1014 (format "*%s*" contents))
1017 ;;;; Center Block
1019 (defun org-ascii-center-block (center-block contents info)
1020 "Transcode a CENTER-BLOCK element from Org to ASCII.
1021 CONTENTS holds the contents of the block. INFO is a plist
1022 holding contextual information."
1023 (org-ascii--justify-string
1024 contents (org-ascii--current-text-width center-block info) 'center))
1027 ;;;; Clock
1029 (defun org-ascii-clock (clock contents info)
1030 "Transcode a CLOCK object from Org to ASCII.
1031 CONTENTS is nil. INFO is a plist holding contextual
1032 information."
1033 (concat org-clock-string " "
1034 (org-translate-time
1035 (org-element-property :raw-value
1036 (org-element-property :value clock)))
1037 (let ((time (org-element-property :duration clock)))
1038 (and time
1039 (concat " => "
1040 (apply 'format
1041 "%2s:%02s"
1042 (org-split-string time ":")))))))
1045 ;;;; Code
1047 (defun org-ascii-code (code contents info)
1048 "Return a CODE object from Org to ASCII.
1049 CONTENTS is nil. INFO is a plist holding contextual
1050 information."
1051 (format org-ascii-verbatim-format (org-element-property :value code)))
1054 ;;;; Drawer
1056 (defun org-ascii-drawer (drawer contents info)
1057 "Transcode a DRAWER element from Org to ASCII.
1058 CONTENTS holds the contents of the block. INFO is a plist
1059 holding contextual information."
1060 (let ((name (org-element-property :drawer-name drawer))
1061 (width (org-ascii--current-text-width drawer info)))
1062 (funcall org-ascii-format-drawer-function name contents width)))
1065 ;;;; Dynamic Block
1067 (defun org-ascii-dynamic-block (dynamic-block contents info)
1068 "Transcode a DYNAMIC-BLOCK element from Org to ASCII.
1069 CONTENTS holds the contents of the block. INFO is a plist
1070 holding contextual information."
1071 contents)
1074 ;;;; Entity
1076 (defun org-ascii-entity (entity contents info)
1077 "Transcode an ENTITY object from Org to ASCII.
1078 CONTENTS are the definition itself. INFO is a plist holding
1079 contextual information."
1080 (org-element-property
1081 (intern (concat ":" (symbol-name (plist-get info :ascii-charset))))
1082 entity))
1085 ;;;; Example Block
1087 (defun org-ascii-example-block (example-block contents info)
1088 "Transcode a EXAMPLE-BLOCK element from Org to ASCII.
1089 CONTENTS is nil. INFO is a plist holding contextual information."
1090 (org-ascii--box-string
1091 (org-export-format-code-default example-block info) info))
1094 ;;;; Export Snippet
1096 (defun org-ascii-export-snippet (export-snippet contents info)
1097 "Transcode a EXPORT-SNIPPET object from Org to ASCII.
1098 CONTENTS is nil. INFO is a plist holding contextual information."
1099 (when (eq (org-export-snippet-backend export-snippet) 'ascii)
1100 (org-element-property :value export-snippet)))
1103 ;;;; Export Block
1105 (defun org-ascii-export-block (export-block contents info)
1106 "Transcode a EXPORT-BLOCK element from Org to ASCII.
1107 CONTENTS is nil. INFO is a plist holding contextual information."
1108 (when (string= (org-element-property :type export-block) "ASCII")
1109 (org-remove-indentation (org-element-property :value export-block))))
1112 ;;;; Fixed Width
1114 (defun org-ascii-fixed-width (fixed-width contents info)
1115 "Transcode a FIXED-WIDTH element from Org to ASCII.
1116 CONTENTS is nil. INFO is a plist holding contextual information."
1117 (org-ascii--box-string
1118 (org-remove-indentation
1119 (org-element-property :value fixed-width)) info))
1122 ;;;; Footnote Definition
1124 ;; Footnote Definitions are ignored. They are compiled at the end of
1125 ;; the document, by `org-ascii-inner-template'.
1128 ;;;; Footnote Reference
1130 (defun org-ascii-footnote-reference (footnote-reference contents info)
1131 "Transcode a FOOTNOTE-REFERENCE element from Org to ASCII.
1132 CONTENTS is nil. INFO is a plist holding contextual information."
1133 (format "[%s]" (org-export-get-footnote-number footnote-reference info)))
1136 ;;;; Headline
1138 (defun org-ascii-headline (headline contents info)
1139 "Transcode a HEADLINE element from Org to ASCII.
1140 CONTENTS holds the contents of the headline. INFO is a plist
1141 holding contextual information."
1142 ;; Don't export footnote section, which will be handled at the end
1143 ;; of the template.
1144 (unless (org-element-property :footnote-section-p headline)
1145 (let* ((low-level-rank (org-export-low-level-p headline info))
1146 (width (org-ascii--current-text-width headline info))
1147 ;; Blank lines between headline and its contents.
1148 ;; `org-ascii-headline-spacing', when set, overwrites
1149 ;; original buffer's spacing.
1150 (pre-blanks
1151 (make-string
1152 (if org-ascii-headline-spacing (car org-ascii-headline-spacing)
1153 (org-element-property :pre-blank headline)) ?\n))
1154 ;; Even if HEADLINE has no section, there might be some
1155 ;; links in its title that we shouldn't forget to describe.
1156 (links
1157 (unless (or (eq (caar (org-element-contents headline)) 'section))
1158 (let ((title (org-element-property :title headline)))
1159 (when (consp title)
1160 (org-ascii--describe-links
1161 (org-ascii--unique-links title info) width info))))))
1162 ;; Deep subtree: export it as a list item.
1163 (if low-level-rank
1164 (concat
1165 ;; Bullet.
1166 (let ((bullets (cdr (assq (plist-get info :ascii-charset)
1167 org-ascii-bullets))))
1168 (char-to-string
1169 (nth (mod (1- low-level-rank) (length bullets)) bullets)))
1171 ;; Title.
1172 (org-ascii--build-title headline info width) "\n"
1173 ;; Contents, indented by length of bullet.
1174 pre-blanks
1175 (org-ascii--indent-string
1176 (concat contents
1177 (when (org-string-nw-p links) (concat "\n\n" links)))
1179 ;; Else: Standard headline.
1180 (concat
1181 (org-ascii--build-title headline info width 'underline)
1182 "\n" pre-blanks
1183 (concat (when (org-string-nw-p links) links) contents))))))
1186 ;;;; Horizontal Rule
1188 (defun org-ascii-horizontal-rule (horizontal-rule contents info)
1189 "Transcode an HORIZONTAL-RULE object from Org to ASCII.
1190 CONTENTS is nil. INFO is a plist holding contextual
1191 information."
1192 (let ((text-width (org-ascii--current-text-width horizontal-rule info))
1193 (spec-width
1194 (org-export-read-attribute :attr_ascii horizontal-rule :width)))
1195 (org-ascii--justify-string
1196 (make-string (if (and spec-width (string-match "^[0-9]+$" spec-width))
1197 (string-to-number spec-width)
1198 text-width)
1199 (if (eq (plist-get info :ascii-charset) 'utf-8) ?― ?-))
1200 text-width 'center)))
1203 ;;;; Inline Src Block
1205 (defun org-ascii-inline-src-block (inline-src-block contents info)
1206 "Transcode an INLINE-SRC-BLOCK element from Org to ASCII.
1207 CONTENTS holds the contents of the item. INFO is a plist holding
1208 contextual information."
1209 (format org-ascii-verbatim-format
1210 (org-element-property :value inline-src-block)))
1213 ;;;; Inlinetask
1215 (defun org-ascii-format-inlinetask-default
1216 (todo type priority name tags contents width inlinetask info)
1217 "Format an inline task element for ASCII export.
1218 See `org-ascii-format-inlinetask-function' for a description
1219 of the parameters."
1220 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8))
1221 (width (or width org-ascii-inlinetask-width)))
1222 (org-ascii--indent-string
1223 (concat
1224 ;; Top line, with an additional blank line if not in UTF-8.
1225 (make-string width (if utf8p ?━ ?_)) "\n"
1226 (unless utf8p (concat (make-string width ? ) "\n"))
1227 ;; Add title. Fill it if wider than inlinetask.
1228 (let ((title (org-ascii--build-title inlinetask info width)))
1229 (if (<= (string-width title) width) title
1230 (org-ascii--fill-string title width info)))
1231 "\n"
1232 ;; If CONTENTS is not empty, insert it along with
1233 ;; a separator.
1234 (when (org-string-nw-p contents)
1235 (concat (make-string width (if utf8p ?─ ?-)) "\n" contents))
1236 ;; Bottom line.
1237 (make-string width (if utf8p ?━ ?_)))
1238 ;; Flush the inlinetask to the right.
1239 (- org-ascii-text-width org-ascii-global-margin
1240 (if (not (org-export-get-parent-headline inlinetask)) 0
1241 org-ascii-inner-margin)
1242 (org-ascii--current-text-width inlinetask info)))))
1244 (defun org-ascii-inlinetask (inlinetask contents info)
1245 "Transcode an INLINETASK element from Org to ASCII.
1246 CONTENTS holds the contents of the block. INFO is a plist
1247 holding contextual information."
1248 (let ((width (org-ascii--current-text-width inlinetask info)))
1249 (funcall org-ascii-format-inlinetask-function
1250 ;; todo.
1251 (and (plist-get info :with-todo-keywords)
1252 (let ((todo (org-element-property
1253 :todo-keyword inlinetask)))
1254 (and todo (org-export-data todo info))))
1255 ;; todo-type
1256 (org-element-property :todo-type inlinetask)
1257 ;; priority
1258 (and (plist-get info :with-priority)
1259 (org-element-property :priority inlinetask))
1260 ;; title
1261 (org-export-data (org-element-property :title inlinetask) info)
1262 ;; tags
1263 (and (plist-get info :with-tags)
1264 (org-element-property :tags inlinetask))
1265 ;; contents and width
1266 contents width inlinetask info)))
1269 ;;;; Italic
1271 (defun org-ascii-italic (italic contents info)
1272 "Transcode italic from Org to ASCII.
1273 CONTENTS is the text with italic markup. INFO is a plist holding
1274 contextual information."
1275 (format "/%s/" contents))
1278 ;;;; Item
1280 (defun org-ascii-item (item contents info)
1281 "Transcode an ITEM element from Org to ASCII.
1282 CONTENTS holds the contents of the item. INFO is a plist holding
1283 contextual information."
1284 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8))
1285 (checkbox (org-ascii--checkbox item info))
1286 (list-type (org-element-property :type (org-export-get-parent item)))
1287 (bullet
1288 ;; First parent of ITEM is always the plain-list. Get
1289 ;; `:type' property from it.
1290 (org-list-bullet-string
1291 (case list-type
1292 (descriptive
1293 (concat checkbox
1294 (org-export-data (org-element-property :tag item) info)
1295 ": "))
1296 (ordered
1297 ;; Return correct number for ITEM, paying attention to
1298 ;; counters.
1299 (let* ((struct (org-element-property :structure item))
1300 (bul (org-element-property :bullet item))
1301 (num (number-to-string
1302 (car (last (org-list-get-item-number
1303 (org-element-property :begin item)
1304 struct
1305 (org-list-prevs-alist struct)
1306 (org-list-parents-alist struct)))))))
1307 (replace-regexp-in-string "[0-9]+" num bul)))
1308 (t (let ((bul (org-element-property :bullet item)))
1309 ;; Change bullets into more visible form if UTF-8 is active.
1310 (if (not utf8p) bul
1311 (replace-regexp-in-string
1312 "-" "•"
1313 (replace-regexp-in-string
1314 "+" "⁃"
1315 (replace-regexp-in-string "*" "‣" bul))))))))))
1316 (concat
1317 bullet
1318 (unless (eq list-type 'descriptive) checkbox)
1319 ;; Contents: Pay attention to indentation. Note: check-boxes are
1320 ;; already taken care of at the paragraph level so they don't
1321 ;; interfere with indentation.
1322 (let ((contents (org-ascii--indent-string contents (string-width bullet))))
1323 (if (eq (org-element-type (car (org-element-contents item))) 'paragraph)
1324 (org-trim contents)
1325 (concat "\n" contents))))))
1328 ;;;; Keyword
1330 (defun org-ascii-keyword (keyword contents info)
1331 "Transcode a KEYWORD element from Org to ASCII.
1332 CONTENTS is nil. INFO is a plist holding contextual
1333 information."
1334 (let ((key (org-element-property :key keyword))
1335 (value (org-element-property :value keyword)))
1336 (cond
1337 ((string= key "ASCII") value)
1338 ((string= key "TOC")
1339 (let ((value (downcase value)))
1340 (cond
1341 ((string-match "\\<headlines\\>" value)
1342 (let ((depth (or (and (string-match "[0-9]+" value)
1343 (string-to-number (match-string 0 value)))
1344 (plist-get info :with-toc))))
1345 (org-ascii--build-toc
1346 info (and (wholenump depth) depth) keyword)))
1347 ((string= "tables" value)
1348 (org-ascii--list-tables keyword info))
1349 ((string= "listings" value)
1350 (org-ascii--list-listings keyword info))))))))
1353 ;;;; Latex Environment
1355 (defun org-ascii-latex-environment (latex-environment contents info)
1356 "Transcode a LATEX-ENVIRONMENT element from Org to ASCII.
1357 CONTENTS is nil. INFO is a plist holding contextual
1358 information."
1359 (when (plist-get info :with-latex)
1360 (org-remove-indentation (org-element-property :value latex-environment))))
1363 ;;;; Latex Fragment
1365 (defun org-ascii-latex-fragment (latex-fragment contents info)
1366 "Transcode a LATEX-FRAGMENT object from Org to ASCII.
1367 CONTENTS is nil. INFO is a plist holding contextual
1368 information."
1369 (when (plist-get info :with-latex)
1370 (org-element-property :value latex-fragment)))
1373 ;;;; Line Break
1375 (defun org-ascii-line-break (line-break contents info)
1376 "Transcode a LINE-BREAK object from Org to ASCII.
1377 CONTENTS is nil. INFO is a plist holding contextual
1378 information." hard-newline)
1381 ;;;; Link
1383 (defun org-ascii-link (link desc info)
1384 "Transcode a LINK object from Org to ASCII.
1386 DESC is the description part of the link, or the empty string.
1387 INFO is a plist holding contextual information."
1388 (let ((raw-link (org-element-property :raw-link link))
1389 (type (org-element-property :type link)))
1390 (cond
1391 ((string= type "coderef")
1392 (let ((ref (org-element-property :path link)))
1393 (format (org-export-get-coderef-format ref desc)
1394 (org-export-resolve-coderef ref info))))
1395 ;; Do not apply a special syntax on radio links. Though, use
1396 ;; transcoded target's contents as output.
1397 ((string= type "radio") desc)
1398 ;; Do not apply a special syntax on fuzzy links pointing to
1399 ;; targets.
1400 ((string= type "fuzzy")
1401 (let ((destination (org-export-resolve-fuzzy-link link info)))
1402 (if (org-string-nw-p desc) desc
1403 (when destination
1404 (let ((number
1405 (org-export-get-ordinal
1406 destination info nil 'org-ascii--has-caption-p)))
1407 (when number
1408 (if (atom number) (number-to-string number)
1409 (mapconcat 'number-to-string number "."))))))))
1411 (if (not (org-string-nw-p desc)) (format "[%s]" raw-link)
1412 (concat
1413 (format "[%s]" desc)
1414 (unless org-ascii-links-to-notes (format " (%s)" raw-link))))))))
1417 ;;;; Paragraph
1419 (defun org-ascii-paragraph (paragraph contents info)
1420 "Transcode a PARAGRAPH element from Org to ASCII.
1421 CONTENTS is the contents of the paragraph, as a string. INFO is
1422 the plist used as a communication channel."
1423 (org-ascii--fill-string
1424 (if (not (wholenump org-ascii-indented-line-width)) contents
1425 (concat
1426 ;; Do not indent first paragraph in a section.
1427 (unless (and (not (org-export-get-previous-element paragraph info))
1428 (eq (org-element-type (org-export-get-parent paragraph))
1429 'section))
1430 (make-string org-ascii-indented-line-width ?\s))
1431 (replace-regexp-in-string "\\`[ \t]+" "" contents)))
1432 (org-ascii--current-text-width paragraph info) info))
1435 ;;;; Plain List
1437 (defun org-ascii-plain-list (plain-list contents info)
1438 "Transcode a PLAIN-LIST element from Org to ASCII.
1439 CONTENTS is the contents of the list. INFO is a plist holding
1440 contextual information."
1441 contents)
1444 ;;;; Plain Text
1446 (defun org-ascii-plain-text (text info)
1447 "Transcode a TEXT string from Org to ASCII.
1448 INFO is a plist used as a communication channel."
1449 (let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
1450 (when (and utf8p (plist-get info :with-smart-quotes))
1451 (setq text (org-export-activate-smart-quotes text :utf-8 info)))
1452 (if (not (plist-get info :with-special-strings)) text
1453 (setq text (replace-regexp-in-string "\\\\-" "" text))
1454 (if (not utf8p) text
1455 ;; Usual replacements in utf-8 with proper option set.
1456 (replace-regexp-in-string
1457 "\\.\\.\\." "…"
1458 (replace-regexp-in-string
1459 "--" "–"
1460 (replace-regexp-in-string "---" "—" text)))))))
1463 ;;;; Planning
1465 (defun org-ascii-planning (planning contents info)
1466 "Transcode a PLANNING element from Org to ASCII.
1467 CONTENTS is nil. INFO is a plist used as a communication
1468 channel."
1469 (mapconcat
1470 'identity
1471 (delq nil
1472 (list (let ((closed (org-element-property :closed planning)))
1473 (when closed
1474 (concat org-closed-string " "
1475 (org-translate-time
1476 (org-element-property :raw-value closed)))))
1477 (let ((deadline (org-element-property :deadline planning)))
1478 (when deadline
1479 (concat org-deadline-string " "
1480 (org-translate-time
1481 (org-element-property :raw-value deadline)))))
1482 (let ((scheduled (org-element-property :scheduled planning)))
1483 (when scheduled
1484 (concat org-scheduled-string " "
1485 (org-translate-time
1486 (org-element-property :raw-value scheduled)))))))
1487 " "))
1490 ;;;; Quote Block
1492 (defun org-ascii-quote-block (quote-block contents info)
1493 "Transcode a QUOTE-BLOCK element from Org to ASCII.
1494 CONTENTS holds the contents of the block. INFO is a plist
1495 holding contextual information."
1496 (org-ascii--indent-string contents org-ascii-quote-margin))
1499 ;;;; Quote Section
1501 (defun org-ascii-quote-section (quote-section contents info)
1502 "Transcode a QUOTE-SECTION element from Org to ASCII.
1503 CONTENTS is nil. INFO is a plist holding contextual information."
1504 (let ((width (org-ascii--current-text-width quote-section info))
1505 (value
1506 (org-export-data
1507 (org-remove-indentation (org-element-property :value quote-section))
1508 info)))
1509 (org-ascii--indent-string
1510 value
1511 (+ org-ascii-quote-margin
1512 ;; Don't apply inner margin if parent headline is low level.
1513 (let ((headline (org-export-get-parent-headline quote-section)))
1514 (if (org-export-low-level-p headline info) 0
1515 org-ascii-inner-margin))))))
1518 ;;;; Radio Target
1520 (defun org-ascii-radio-target (radio-target contents info)
1521 "Transcode a RADIO-TARGET object from Org to ASCII.
1522 CONTENTS is the contents of the target. INFO is a plist holding
1523 contextual information."
1524 contents)
1527 ;;;; Section
1529 (defun org-ascii-section (section contents info)
1530 "Transcode a SECTION element from Org to ASCII.
1531 CONTENTS is the contents of the section. INFO is a plist holding
1532 contextual information."
1533 (org-ascii--indent-string
1534 (concat
1535 contents
1536 (when org-ascii-links-to-notes
1537 ;; Add list of links at the end of SECTION.
1538 (let ((links (org-ascii--describe-links
1539 (org-ascii--unique-links section info)
1540 (org-ascii--current-text-width section info) info)))
1541 ;; Separate list of links and section contents.
1542 (when (org-string-nw-p links) (concat "\n\n" links)))))
1543 ;; Do not apply inner margin if parent headline is low level.
1544 (let ((headline (org-export-get-parent-headline section)))
1545 (if (or (not headline) (org-export-low-level-p headline info)) 0
1546 org-ascii-inner-margin))))
1549 ;;;; Special Block
1551 (defun org-ascii-special-block (special-block contents info)
1552 "Transcode a SPECIAL-BLOCK element from Org to ASCII.
1553 CONTENTS holds the contents of the block. INFO is a plist
1554 holding contextual information."
1555 contents)
1558 ;;;; Src Block
1560 (defun org-ascii-src-block (src-block contents info)
1561 "Transcode a SRC-BLOCK element from Org to ASCII.
1562 CONTENTS holds the contents of the item. INFO is a plist holding
1563 contextual information."
1564 (let ((caption (org-ascii--build-caption src-block info))
1565 (code (org-export-format-code-default src-block info)))
1566 (if (equal code "") ""
1567 (concat
1568 (when (and caption org-ascii-caption-above) (concat caption "\n"))
1569 (org-ascii--box-string code info)
1570 (when (and caption (not org-ascii-caption-above))
1571 (concat "\n" caption))))))
1574 ;;;; Statistics Cookie
1576 (defun org-ascii-statistics-cookie (statistics-cookie contents info)
1577 "Transcode a STATISTICS-COOKIE object from Org to ASCII.
1578 CONTENTS is nil. INFO is a plist holding contextual information."
1579 (org-element-property :value statistics-cookie))
1582 ;;;; Subscript
1584 (defun org-ascii-subscript (subscript contents info)
1585 "Transcode a SUBSCRIPT object from Org to ASCII.
1586 CONTENTS is the contents of the object. INFO is a plist holding
1587 contextual information."
1588 (if (org-element-property :use-brackets-p subscript)
1589 (format "_{%s}" contents)
1590 (format "_%s" contents)))
1593 ;;;; Superscript
1595 (defun org-ascii-superscript (superscript contents info)
1596 "Transcode a SUPERSCRIPT object from Org to ASCII.
1597 CONTENTS is the contents of the object. INFO is a plist holding
1598 contextual information."
1599 (if (org-element-property :use-brackets-p superscript)
1600 (format "^{%s}" contents)
1601 (format "^%s" contents)))
1604 ;;;; Strike-through
1606 (defun org-ascii-strike-through (strike-through contents info)
1607 "Transcode STRIKE-THROUGH from Org to ASCII.
1608 CONTENTS is text with strike-through markup. INFO is a plist
1609 holding contextual information."
1610 (format "+%s+" contents))
1613 ;;;; Table
1615 (defun org-ascii-table (table contents info)
1616 "Transcode a TABLE element from Org to ASCII.
1617 CONTENTS is the contents of the table. INFO is a plist holding
1618 contextual information."
1619 (let ((caption (org-ascii--build-caption table info)))
1620 (concat
1621 ;; Possibly add a caption string above.
1622 (when (and caption org-ascii-caption-above) (concat caption "\n"))
1623 ;; Insert table. Note: "table.el" tables are left unmodified.
1624 (cond ((eq (org-element-property :type table) 'org) contents)
1625 ((and org-ascii-table-use-ascii-art
1626 (eq (plist-get info :ascii-charset) 'utf-8)
1627 (require 'ascii-art-to-unicode nil t))
1628 (with-temp-buffer
1629 (insert (org-remove-indentation
1630 (org-element-property :value table)))
1631 (goto-char (point-min))
1632 (aa2u)
1633 (goto-char (point-max))
1634 (skip-chars-backward " \r\t\n")
1635 (buffer-substring (point-min) (point))))
1636 (t (org-remove-indentation (org-element-property :value table))))
1637 ;; Possible add a caption string below.
1638 (and (not org-ascii-caption-above) caption))))
1641 ;;;; Table Cell
1643 (defun org-ascii--table-cell-width (table-cell info)
1644 "Return width of TABLE-CELL.
1646 INFO is a plist used as a communication channel.
1648 Width of a cell is determined either by a width cookie in the
1649 same column as the cell, or by the maximum cell's length in that
1650 column.
1652 When `org-ascii-table-widen-columns' is non-nil, width cookies
1653 are ignored."
1654 (let* ((row (org-export-get-parent table-cell))
1655 (table (org-export-get-parent row))
1656 (col (let ((cells (org-element-contents row)))
1657 (- (length cells) (length (memq table-cell cells)))))
1658 (cache
1659 (or (plist-get info :ascii-table-cell-width-cache)
1660 (plist-get (setq info
1661 (plist-put info :ascii-table-cell-width-cache
1662 (make-hash-table :test 'equal)))
1663 :ascii-table-cell-width-cache)))
1664 (key (cons table col)))
1665 (or (gethash key cache)
1666 (puthash
1668 (or (and (not org-ascii-table-widen-columns)
1669 (org-export-table-cell-width table-cell info))
1670 (let* ((max-width 0))
1671 (org-element-map table 'table-row
1672 (lambda (row)
1673 (setq max-width
1674 (max (string-width
1675 (org-export-data
1676 (org-element-contents
1677 (elt (org-element-contents row) col))
1678 info))
1679 max-width)))
1680 info)
1681 max-width))
1682 cache))))
1684 (defun org-ascii-table-cell (table-cell contents info)
1685 "Transcode a TABLE-CELL object from Org to ASCII.
1686 CONTENTS is the cell contents. INFO is a plist used as
1687 a communication channel."
1688 ;; Determine column width. When `org-ascii-table-widen-columns'
1689 ;; is nil and some width cookie has set it, use that value.
1690 ;; Otherwise, compute the maximum width among transcoded data of
1691 ;; each cell in the column.
1692 (let ((width (org-ascii--table-cell-width table-cell info)))
1693 ;; When contents are too large, truncate them.
1694 (unless (or org-ascii-table-widen-columns
1695 (<= (string-width (or contents "")) width))
1696 (setq contents (concat (substring contents 0 (- width 2)) "=>")))
1697 ;; Align contents correctly within the cell.
1698 (let* ((indent-tabs-mode nil)
1699 (data
1700 (when contents
1701 (org-ascii--justify-string
1702 contents width
1703 (org-export-table-cell-alignment table-cell info)))))
1704 (setq contents
1705 (concat data
1706 (make-string (- width (string-width (or data ""))) ?\s))))
1707 ;; Return cell.
1708 (concat (format " %s " contents)
1709 (when (memq 'right (org-export-table-cell-borders table-cell info))
1710 (if (eq (plist-get info :ascii-charset) 'utf-8) "│" "|")))))
1713 ;;;; Table Row
1715 (defun org-ascii-table-row (table-row contents info)
1716 "Transcode a TABLE-ROW element from Org to ASCII.
1717 CONTENTS is the row contents. INFO is a plist used as
1718 a communication channel."
1719 (when (eq (org-element-property :type table-row) 'standard)
1720 (let ((build-hline
1721 (function
1722 (lambda (lcorner horiz vert rcorner)
1723 (concat
1724 (apply
1725 'concat
1726 (org-element-map table-row 'table-cell
1727 (lambda (cell)
1728 (let ((width (org-ascii--table-cell-width cell info))
1729 (borders (org-export-table-cell-borders cell info)))
1730 (concat
1731 ;; In order to know if CELL starts the row, do
1732 ;; not compare it with the first cell in the
1733 ;; row as there might be a special column.
1734 ;; Instead, compare it with first exportable
1735 ;; cell, obtained with `org-element-map'.
1736 (when (and (memq 'left borders)
1737 (eq (org-element-map table-row 'table-cell
1738 'identity info t)
1739 cell))
1740 lcorner)
1741 (make-string (+ 2 width) (string-to-char horiz))
1742 (cond
1743 ((not (memq 'right borders)) nil)
1744 ((eq (car (last (org-element-contents table-row))) cell)
1745 rcorner)
1746 (t vert)))))
1747 info)) "\n"))))
1748 (utf8p (eq (plist-get info :ascii-charset) 'utf-8))
1749 (borders (org-export-table-cell-borders
1750 (org-element-map table-row 'table-cell 'identity info t)
1751 info)))
1752 (concat (cond
1753 ((and (memq 'top borders) (or utf8p (memq 'above borders)))
1754 (if utf8p (funcall build-hline "┍" "━" "┯" "┑")
1755 (funcall build-hline "+" "-" "+" "+")))
1756 ((memq 'above borders)
1757 (if utf8p (funcall build-hline "├" "─" "┼" "┤")
1758 (funcall build-hline "+" "-" "+" "+"))))
1759 (when (memq 'left borders) (if utf8p "│" "|"))
1760 contents "\n"
1761 (when (and (memq 'bottom borders) (or utf8p (memq 'below borders)))
1762 (if utf8p (funcall build-hline "┕" "━" "┷" "┙")
1763 (funcall build-hline "+" "-" "+" "+")))))))
1766 ;;;; Timestamp
1768 (defun org-ascii-timestamp (timestamp contents info)
1769 "Transcode a TIMESTAMP object from Org to ASCII.
1770 CONTENTS is nil. INFO is a plist holding contextual information."
1771 (org-ascii-plain-text (org-timestamp-translate timestamp) info))
1774 ;;;; Underline
1776 (defun org-ascii-underline (underline contents info)
1777 "Transcode UNDERLINE from Org to ASCII.
1778 CONTENTS is the text with underline markup. INFO is a plist
1779 holding contextual information."
1780 (format "_%s_" contents))
1783 ;;;; Verbatim
1785 (defun org-ascii-verbatim (verbatim contents info)
1786 "Return a VERBATIM object from Org to ASCII.
1787 CONTENTS is nil. INFO is a plist holding contextual information."
1788 (format org-ascii-verbatim-format
1789 (org-element-property :value verbatim)))
1792 ;;;; Verse Block
1794 (defun org-ascii-verse-block (verse-block contents info)
1795 "Transcode a VERSE-BLOCK element from Org to ASCII.
1796 CONTENTS is verse block contents. INFO is a plist holding
1797 contextual information."
1798 (let ((verse-width (org-ascii--current-text-width verse-block info)))
1799 (org-ascii--indent-string
1800 (org-ascii--justify-string contents verse-width 'left)
1801 org-ascii-quote-margin)))
1805 ;;; Filters
1807 (defun org-ascii-filter-headline-blank-lines (headline back-end info)
1808 "Filter controlling number of blank lines after a headline.
1810 HEADLINE is a string representing a transcoded headline.
1811 BACK-END is symbol specifying back-end used for export. INFO is
1812 plist containing the communication channel.
1814 This function only applies to `ascii' back-end. See
1815 `org-ascii-headline-spacing' for information."
1816 (if (not org-ascii-headline-spacing) headline
1817 (let ((blanks (make-string (1+ (cdr org-ascii-headline-spacing)) ?\n)))
1818 (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" blanks headline))))
1820 (defun org-ascii-filter-paragraph-spacing (tree back-end info)
1821 "Filter controlling number of blank lines between paragraphs.
1823 TREE is the parse tree. BACK-END is the symbol specifying
1824 back-end used for export. INFO is a plist used as
1825 a communication channel.
1827 See `org-ascii-paragraph-spacing' for information."
1828 (when (wholenump org-ascii-paragraph-spacing)
1829 (org-element-map tree 'paragraph
1830 (lambda (p)
1831 (when (eq (org-element-type (org-export-get-next-element p info))
1832 'paragraph)
1833 (org-element-put-property
1834 p :post-blank org-ascii-paragraph-spacing)))))
1835 tree)
1837 (defun org-ascii-filter-comment-spacing (tree backend info)
1838 "Filter removing blank lines between comments.
1839 TREE is the parse tree. BACK-END is the symbol specifying
1840 back-end used for export. INFO is a plist used as
1841 a communication channel."
1842 (org-element-map tree '(comment comment-block)
1843 (lambda (c)
1844 (when (memq (org-element-type (org-export-get-next-element c info))
1845 '(comment comment-block))
1846 (org-element-put-property c :post-blank 0))))
1847 tree)
1851 ;;; End-user functions
1853 ;;;###autoload
1854 (defun org-ascii-export-as-ascii
1855 (&optional async subtreep visible-only body-only ext-plist)
1856 "Export current buffer to a text buffer.
1858 If narrowing is active in the current buffer, only export its
1859 narrowed part.
1861 If a region is active, export that region.
1863 A non-nil optional argument ASYNC means the process should happen
1864 asynchronously. The resulting buffer should be accessible
1865 through the `org-export-stack' interface.
1867 When optional argument SUBTREEP is non-nil, export the sub-tree
1868 at point, extracting information from the headline properties
1869 first.
1871 When optional argument VISIBLE-ONLY is non-nil, don't export
1872 contents of hidden elements.
1874 When optional argument BODY-ONLY is non-nil, strip title and
1875 table of contents from output.
1877 EXT-PLIST, when provided, is a property list with external
1878 parameters overriding Org default settings, but still inferior to
1879 file-local settings.
1881 Export is done in a buffer named \"*Org ASCII Export*\", which
1882 will be displayed when `org-export-show-temporary-export-buffer'
1883 is non-nil."
1884 (interactive)
1885 (org-export-to-buffer 'ascii "*Org ASCII Export*"
1886 async subtreep visible-only body-only ext-plist (lambda () (text-mode))))
1888 ;;;###autoload
1889 (defun org-ascii-export-to-ascii
1890 (&optional async subtreep visible-only body-only ext-plist)
1891 "Export current buffer to a text file.
1893 If narrowing is active in the current buffer, only export its
1894 narrowed part.
1896 If a region is active, export that region.
1898 A non-nil optional argument ASYNC means the process should happen
1899 asynchronously. The resulting file should be accessible through
1900 the `org-export-stack' interface.
1902 When optional argument SUBTREEP is non-nil, export the sub-tree
1903 at point, extracting information from the headline properties
1904 first.
1906 When optional argument VISIBLE-ONLY is non-nil, don't export
1907 contents of hidden elements.
1909 When optional argument BODY-ONLY is non-nil, strip title and
1910 table of contents from output.
1912 EXT-PLIST, when provided, is a property list with external
1913 parameters overriding Org default settings, but still inferior to
1914 file-local settings.
1916 Return output file's name."
1917 (interactive)
1918 (let ((file (org-export-output-file-name ".txt" subtreep)))
1919 (org-export-to-file 'ascii file
1920 async subtreep visible-only body-only ext-plist)))
1922 ;;;###autoload
1923 (defun org-ascii-publish-to-ascii (plist filename pub-dir)
1924 "Publish an Org file to ASCII.
1926 FILENAME is the filename of the Org file to be published. PLIST
1927 is the property list for the given project. PUB-DIR is the
1928 publishing directory.
1930 Return output file name."
1931 (org-publish-org-to
1932 'ascii filename ".txt" `(:ascii-charset ascii ,@plist) pub-dir))
1934 ;;;###autoload
1935 (defun org-ascii-publish-to-latin1 (plist filename pub-dir)
1936 "Publish an Org file to Latin-1.
1938 FILENAME is the filename of the Org file to be published. PLIST
1939 is the property list for the given project. PUB-DIR is the
1940 publishing directory.
1942 Return output file name."
1943 (org-publish-org-to
1944 'ascii filename ".txt" `(:ascii-charset latin1 ,@plist) pub-dir))
1946 ;;;###autoload
1947 (defun org-ascii-publish-to-utf8 (plist filename pub-dir)
1948 "Publish an org file to UTF-8.
1950 FILENAME is the filename of the Org file to be published. PLIST
1951 is the property list for the given project. PUB-DIR is the
1952 publishing directory.
1954 Return output file name."
1955 (org-publish-org-to
1956 'ascii filename ".txt" `(:ascii-charset utf-8 ,@plist) pub-dir))
1959 (provide 'ox-ascii)
1961 ;; Local variables:
1962 ;; generated-autoload-file: "org-loaddefs.el"
1963 ;; coding: utf-8-emacs
1964 ;; End:
1966 ;;; ox-ascii.el ends here