Merge branch 'maint'
[org-mode/org-kjn.git] / lisp / ox-ascii.el
blob858e3f05c3725afffb62223ea181341dcc7f9140
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 (node-property . org-ascii-node-property)
75 (paragraph . org-ascii-paragraph)
76 (plain-list . org-ascii-plain-list)
77 (plain-text . org-ascii-plain-text)
78 (planning . org-ascii-planning)
79 (property-drawer . org-ascii-property-drawer)
80 (quote-block . org-ascii-quote-block)
81 (radio-target . org-ascii-radio-target)
82 (section . org-ascii-section)
83 (special-block . org-ascii-special-block)
84 (src-block . org-ascii-src-block)
85 (statistics-cookie . org-ascii-statistics-cookie)
86 (strike-through . org-ascii-strike-through)
87 (subscript . org-ascii-subscript)
88 (superscript . org-ascii-superscript)
89 (table . org-ascii-table)
90 (table-cell . org-ascii-table-cell)
91 (table-row . org-ascii-table-row)
92 (target . org-ascii-target)
93 (template . org-ascii-template)
94 (timestamp . org-ascii-timestamp)
95 (underline . org-ascii-underline)
96 (verbatim . org-ascii-verbatim)
97 (verse-block . org-ascii-verse-block))
98 :export-block "ASCII"
99 :menu-entry
100 '(?t "Export to Plain Text"
101 ((?A "As ASCII buffer"
102 (lambda (a s v b)
103 (org-ascii-export-as-ascii a s v b '(:ascii-charset ascii))))
104 (?a "As ASCII file"
105 (lambda (a s v b)
106 (org-ascii-export-to-ascii a s v b '(:ascii-charset ascii))))
107 (?L "As Latin1 buffer"
108 (lambda (a s v b)
109 (org-ascii-export-as-ascii a s v b '(:ascii-charset latin1))))
110 (?l "As Latin1 file"
111 (lambda (a s v b)
112 (org-ascii-export-to-ascii a s v b '(:ascii-charset latin1))))
113 (?U "As UTF-8 buffer"
114 (lambda (a s v b)
115 (org-ascii-export-as-ascii a s v b '(:ascii-charset utf-8))))
116 (?u "As UTF-8 file"
117 (lambda (a s v b)
118 (org-ascii-export-to-ascii a s v b '(:ascii-charset utf-8))))))
119 :filters-alist '((:filter-headline . org-ascii-filter-headline-blank-lines)
120 (:filter-parse-tree org-ascii-filter-paragraph-spacing
121 org-ascii-filter-comment-spacing)
122 (:filter-section . org-ascii-filter-headline-blank-lines))
123 :options-alist '((:ascii-charset nil nil org-ascii-charset)))
127 ;;; User Configurable Variables
129 (defgroup org-export-ascii nil
130 "Options for exporting Org mode files to ASCII."
131 :tag "Org Export ASCII"
132 :group 'org-export)
134 (defcustom org-ascii-text-width 72
135 "Maximum width of exported text.
136 This number includes margin size, as set in
137 `org-ascii-global-margin'."
138 :group 'org-export-ascii
139 :version "24.4"
140 :package-version '(Org . "8.0")
141 :type 'integer)
143 (defcustom org-ascii-global-margin 0
144 "Width of the left margin, in number of characters."
145 :group 'org-export-ascii
146 :version "24.4"
147 :package-version '(Org . "8.0")
148 :type 'integer)
150 (defcustom org-ascii-inner-margin 2
151 "Width of the inner margin, in number of characters.
152 Inner margin is applied between each headline."
153 :group 'org-export-ascii
154 :version "24.4"
155 :package-version '(Org . "8.0")
156 :type 'integer)
158 (defcustom org-ascii-quote-margin 6
159 "Width of margin used for quoting text, in characters.
160 This margin is applied on both sides of the text."
161 :group 'org-export-ascii
162 :version "24.4"
163 :package-version '(Org . "8.0")
164 :type 'integer)
166 (defcustom org-ascii-inlinetask-width 30
167 "Width of inline tasks, in number of characters.
168 This number ignores any margin."
169 :group 'org-export-ascii
170 :version "24.4"
171 :package-version '(Org . "8.0")
172 :type 'integer)
174 (defcustom org-ascii-headline-spacing '(1 . 2)
175 "Number of blank lines inserted around headlines.
177 This variable can be set to a cons cell. In that case, its car
178 represents the number of blank lines present before headline
179 contents whereas its cdr reflects the number of blank lines after
180 contents.
182 A nil value replicates the number of blank lines found in the
183 original Org buffer at the same place."
184 :group 'org-export-ascii
185 :version "24.4"
186 :package-version '(Org . "8.0")
187 :type '(choice
188 (const :tag "Replicate original spacing" nil)
189 (cons :tag "Set an uniform spacing"
190 (integer :tag "Number of blank lines before contents")
191 (integer :tag "Number of blank lines after contents"))))
193 (defcustom org-ascii-indented-line-width 'auto
194 "Additional indentation width for the first line in a paragraph.
195 If the value is an integer, indent the first line of each
196 paragraph by this width, unless it is located at the beginning of
197 a section, in which case indentation is removed from that line.
198 If it is the symbol `auto' preserve indentation from original
199 document."
200 :group 'org-export-ascii
201 :version "24.4"
202 :package-version '(Org . "8.0")
203 :type '(choice
204 (integer :tag "Number of white spaces characters")
205 (const :tag "Preserve original width" auto)))
207 (defcustom org-ascii-paragraph-spacing 'auto
208 "Number of white lines between paragraphs.
209 If the value is an integer, add this number of blank lines
210 between contiguous paragraphs. If is it the symbol `auto', keep
211 the same number of blank lines as in the original document."
212 :group 'org-export-ascii
213 :version "24.4"
214 :package-version '(Org . "8.0")
215 :type '(choice
216 (integer :tag "Number of blank lines")
217 (const :tag "Preserve original spacing" auto)))
219 (defcustom org-ascii-charset 'ascii
220 "The charset allowed to represent various elements and objects.
221 Possible values are:
222 `ascii' Only use plain ASCII characters
223 `latin1' Include Latin-1 characters
224 `utf-8' Use all UTF-8 characters"
225 :group 'org-export-ascii
226 :version "24.4"
227 :package-version '(Org . "8.0")
228 :type '(choice
229 (const :tag "ASCII" ascii)
230 (const :tag "Latin-1" latin1)
231 (const :tag "UTF-8" utf-8)))
233 (defcustom org-ascii-underline '((ascii ?= ?~ ?-)
234 (latin1 ?= ?~ ?-)
235 (utf-8 ?═ ?─ ?╌ ?┄ ?┈))
236 "Characters for underlining headings in ASCII export.
238 Alist whose key is a symbol among `ascii', `latin1' and `utf-8'
239 and whose value is a list of characters.
241 For each supported charset, this variable associates a sequence
242 of underline characters. In a sequence, the characters will be
243 used in order for headlines level 1, 2, ... If no character is
244 available for a given level, the headline won't be underlined."
245 :group 'org-export-ascii
246 :version "24.4"
247 :package-version '(Org . "8.0")
248 :type '(list
249 (cons :tag "Underline characters sequence"
250 (const :tag "ASCII charset" ascii)
251 (repeat character))
252 (cons :tag "Underline characters sequence"
253 (const :tag "Latin-1 charset" latin1)
254 (repeat character))
255 (cons :tag "Underline characters sequence"
256 (const :tag "UTF-8 charset" utf-8)
257 (repeat character))))
259 (defcustom org-ascii-bullets '((ascii ?* ?+ ?-)
260 (latin1 ?§ ?¶)
261 (utf-8 ?◊))
262 "Bullet characters for headlines converted to lists in ASCII export.
264 Alist whose key is a symbol among `ascii', `latin1' and `utf-8'
265 and whose value is a list of characters.
267 The first character is used for the first level considered as low
268 level, and so on. If there are more levels than characters given
269 here, the list will be repeated.
271 Note that this variable doesn't affect plain lists
272 representation."
273 :group 'org-export-ascii
274 :version "24.4"
275 :package-version '(Org . "8.0")
276 :type '(list
277 (cons :tag "Bullet characters for low level headlines"
278 (const :tag "ASCII charset" ascii)
279 (repeat character))
280 (cons :tag "Bullet characters for low level headlines"
281 (const :tag "Latin-1 charset" latin1)
282 (repeat character))
283 (cons :tag "Bullet characters for low level headlines"
284 (const :tag "UTF-8 charset" utf-8)
285 (repeat character))))
287 (defcustom org-ascii-links-to-notes t
288 "Non-nil means convert links to notes before the next headline.
289 When nil, the link will be exported in place. If the line
290 becomes long in this way, it will be wrapped."
291 :group 'org-export-ascii
292 :version "24.4"
293 :package-version '(Org . "8.0")
294 :type 'boolean)
296 (defcustom org-ascii-table-keep-all-vertical-lines nil
297 "Non-nil means keep all vertical lines in ASCII tables.
298 When nil, vertical lines will be removed except for those needed
299 for column grouping."
300 :group 'org-export-ascii
301 :version "24.4"
302 :package-version '(Org . "8.0")
303 :type 'boolean)
305 (defcustom org-ascii-table-widen-columns t
306 "Non-nil means widen narrowed columns for export.
307 When nil, narrowed columns will look in ASCII export just like in
308 Org mode, i.e. with \"=>\" as ellipsis."
309 :group 'org-export-ascii
310 :version "24.4"
311 :package-version '(Org . "8.0")
312 :type 'boolean)
314 (defcustom org-ascii-table-use-ascii-art nil
315 "Non-nil means table.el tables are turned into ascii-art.
317 It only makes sense when export charset is `utf-8'. It is nil by
318 default since it requires ascii-art-to-unicode.el package. You
319 can download it here:
321 http://gnuvola.org/software/j/aa2u/ascii-art-to-unicode.el."
322 :group 'org-export-ascii
323 :version "24.4"
324 :package-version '(Org . "8.0")
325 :type 'boolean)
327 (defcustom org-ascii-caption-above nil
328 "When non-nil, place caption string before the element.
329 Otherwise, place it right after it."
330 :group 'org-export-ascii
331 :version "24.4"
332 :package-version '(Org . "8.0")
333 :type 'boolean)
335 (defcustom org-ascii-verbatim-format "`%s'"
336 "Format string used for verbatim text and inline code."
337 :group 'org-export-ascii
338 :version "24.4"
339 :package-version '(Org . "8.0")
340 :type 'string)
342 (defcustom org-ascii-format-drawer-function
343 (lambda (name contents width) contents)
344 "Function called to format a drawer in ASCII.
346 The function must accept three parameters:
347 NAME the drawer name, like \"LOGBOOK\"
348 CONTENTS the contents of the drawer.
349 WIDTH the text width within the drawer.
351 The function should return either the string to be exported or
352 nil to ignore the drawer.
354 The default value simply returns the value of CONTENTS."
355 :group 'org-export-ascii
356 :version "24.4"
357 :package-version '(Org . "8.0")
358 :type 'function)
360 (defcustom org-ascii-format-inlinetask-function
361 'org-ascii-format-inlinetask-default
362 "Function called to format an inlinetask in ASCII.
364 The function must accept nine 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.
371 WIDTH the width of the inlinetask, as a number.
372 INLINETASK the inlinetask itself.
373 INFO the info channel.
375 The function should return either the string to be exported or
376 nil to ignore the inline task."
377 :group 'org-export-ascii
378 :version "24.4"
379 :package-version '(Org . "8.3")
380 :type 'function)
384 ;;; Internal Functions
386 ;; Internal functions fall into three categories.
388 ;; The first one is about text formatting. The core function is
389 ;; `org-ascii--current-text-width', which determines the current
390 ;; text width allowed to a given element. In other words, it helps
391 ;; keeping each line width within maximum text width defined in
392 ;; `org-ascii-text-width'. Once this information is known,
393 ;; `org-ascii--fill-string', `org-ascii--justify-string',
394 ;; `org-ascii--box-string' and `org-ascii--indent-string' can
395 ;; operate on a given output string.
397 ;; The second category contains functions handling elements listings,
398 ;; triggered by "#+TOC:" keyword. As such, `org-ascii--build-toc'
399 ;; returns a complete table of contents, `org-ascii--list-listings'
400 ;; returns a list of referenceable src-block elements, and
401 ;; `org-ascii--list-tables' does the same for table elements.
403 ;; The third category includes general helper functions.
404 ;; `org-ascii--build-title' creates the title for a given headline
405 ;; or inlinetask element. `org-ascii--build-caption' returns the
406 ;; caption string associated to a table or a src-block.
407 ;; `org-ascii--describe-links' creates notes about links for
408 ;; insertion at the end of a section. It uses
409 ;; `org-ascii--unique-links' to get the list of links to describe.
410 ;; Eventually, `org-ascii--translate' translates a string according
411 ;; to language and charset specification.
414 (defun org-ascii--fill-string (s text-width info &optional justify)
415 "Fill a string with specified text-width and return it.
417 S is the string being filled. TEXT-WIDTH is an integer
418 specifying maximum length of a line. INFO is the plist used as
419 a communication channel.
421 Optional argument JUSTIFY can specify any type of justification
422 among `left', `center', `right' or `full'. A nil value is
423 equivalent to `left'. For a justification that doesn't also fill
424 string, see `org-ascii--justify-string'.
426 Return nil if S isn't a string."
427 ;; Don't fill paragraph when break should be preserved.
428 (cond ((not (stringp s)) nil)
429 ((plist-get info :preserve-breaks) s)
430 (t (let ((double-space-p sentence-end-double-space))
431 (with-temp-buffer
432 (let ((fill-column text-width)
433 (use-hard-newlines t)
434 (sentence-end-double-space double-space-p))
435 (insert s)
436 (fill-region (point-min) (point-max) justify))
437 (buffer-string))))))
439 (defun org-ascii--justify-string (s text-width how)
440 "Justify string S.
441 TEXT-WIDTH is an integer specifying maximum length of a line.
442 HOW determines the type of justification: it can be `left',
443 `right', `full' or `center'."
444 (with-temp-buffer
445 (insert s)
446 (goto-char (point-min))
447 (let ((fill-column text-width)
448 ;; Disable `adaptive-fill-mode' so it doesn't prevent
449 ;; filling lines matching `adaptive-fill-regexp'.
450 (adaptive-fill-mode nil))
451 (while (< (point) (point-max))
452 (justify-current-line how)
453 (forward-line)))
454 (buffer-string)))
456 (defun org-ascii--indent-string (s width)
457 "Indent string S by WIDTH white spaces.
458 Empty lines are not indented."
459 (when (stringp s)
460 (replace-regexp-in-string
461 "\\(^\\)[ \t]*\\S-" (make-string width ?\s) s nil nil 1)))
463 (defun org-ascii--box-string (s info)
464 "Return string S with a partial box to its left.
465 INFO is a plist used as a communication channel."
466 (let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
467 (format (if utf8p "╭────\n%s\n╰────" ",----\n%s\n`----")
468 (replace-regexp-in-string
469 "^" (if utf8p "│ " "| ")
470 ;; Remove last newline character.
471 (replace-regexp-in-string "\n[ \t]*\\'" "" s)))))
473 (defun org-ascii--current-text-width (element info)
474 "Return maximum text width for ELEMENT's contents.
475 INFO is a plist used as a communication channel."
476 (case (org-element-type element)
477 ;; Elements with an absolute width: `headline' and `inlinetask'.
478 (inlinetask org-ascii-inlinetask-width)
479 ('headline
480 (- org-ascii-text-width
481 (let ((low-level-rank (org-export-low-level-p element info)))
482 (if low-level-rank (* low-level-rank 2) org-ascii-global-margin))))
483 ;; Elements with a relative width: store maximum text width in
484 ;; TOTAL-WIDTH.
485 (otherwise
486 (let* ((genealogy (cons element (org-export-get-genealogy element)))
487 ;; Total width is determined by the presence, or not, of an
488 ;; inline task among ELEMENT parents.
489 (total-width
490 (if (loop for parent in genealogy
491 thereis (eq (org-element-type parent) 'inlinetask))
492 org-ascii-inlinetask-width
493 ;; No inlinetask: Remove global margin from text width.
494 (- org-ascii-text-width
495 org-ascii-global-margin
496 (let ((parent (org-export-get-parent-headline element)))
497 ;; Inner margin doesn't apply to text before first
498 ;; headline.
499 (if (not parent) 0
500 (let ((low-level-rank
501 (org-export-low-level-p parent info)))
502 ;; Inner margin doesn't apply to contents of
503 ;; low level headlines, since they've got their
504 ;; own indentation mechanism.
505 (if low-level-rank (* low-level-rank 2)
506 org-ascii-inner-margin))))))))
507 (- total-width
508 ;; Each `quote-block' and `verse-block' above narrows text
509 ;; width by twice the standard margin size.
510 (+ (* (loop for parent in genealogy
511 when (memq (org-element-type parent)
512 '(quote-block verse-block))
513 count parent)
514 2 org-ascii-quote-margin)
515 ;; Text width within a plain-list is restricted by
516 ;; indentation of current item. If that's the case,
517 ;; compute it with the help of `:structure' property from
518 ;; parent item, if any.
519 (let ((parent-item
520 (if (eq (org-element-type element) 'item) element
521 (loop for parent in genealogy
522 when (eq (org-element-type parent) 'item)
523 return parent))))
524 (if (not parent-item) 0
525 ;; Compute indentation offset of the current item,
526 ;; that is the sum of the difference between its
527 ;; indentation and the indentation of the top item in
528 ;; the list and current item bullet's length. Also
529 ;; remove checkbox length, and tag length (for
530 ;; description lists) or bullet length.
531 (let ((struct (org-element-property :structure parent-item))
532 (beg-item (org-element-property :begin parent-item)))
533 (+ (- (org-list-get-ind beg-item struct)
534 (org-list-get-ind
535 (org-list-get-top-point struct) struct))
536 (string-width (or (org-ascii--checkbox parent-item info)
537 ""))
538 (string-width
539 (or (org-list-get-tag beg-item struct)
540 (org-list-get-bullet beg-item struct)))))))))))))
542 (defun org-ascii--build-title
543 (element info text-width &optional underline notags toc)
544 "Format ELEMENT title and return it.
546 ELEMENT is either an `headline' or `inlinetask' element. INFO is
547 a plist used as a communication channel. TEXT-WIDTH is an
548 integer representing the maximum length of a line.
550 When optional argument UNDERLINE is non-nil, underline title,
551 without the tags, according to `org-ascii-underline'
552 specifications.
554 If optional argument NOTAGS is non-nil, no tags will be added to
555 the title.
557 When optional argument TOC is non-nil, use optional title if
558 possible. It doesn't apply to `inlinetask' elements."
559 (let* ((headlinep (eq (org-element-type element) 'headline))
560 (numbers
561 ;; Numbering is specific to headlines.
562 (and headlinep (org-export-numbered-headline-p element info)
563 ;; All tests passed: build numbering string.
564 (concat
565 (mapconcat
566 'number-to-string
567 (org-export-get-headline-number element info) ".")
568 " ")))
569 (text
570 (org-trim
571 (org-export-data
572 (if (and toc headlinep) (org-export-get-alt-title element info)
573 (org-element-property :title element))
574 info)))
575 (todo
576 (and (plist-get info :with-todo-keywords)
577 (let ((todo (org-element-property :todo-keyword element)))
578 (and todo (concat (org-export-data todo info) " ")))))
579 (tags (and (not notags)
580 (plist-get info :with-tags)
581 (let ((tag-list (org-export-get-tags element info)))
582 (and tag-list
583 (format ":%s:"
584 (mapconcat 'identity tag-list ":"))))))
585 (priority
586 (and (plist-get info :with-priority)
587 (let ((char (org-element-property :priority element)))
588 (and char (format "(#%c) " char)))))
589 (first-part (concat numbers todo priority text)))
590 (concat
591 first-part
592 ;; Align tags, if any.
593 (when tags
594 (format
595 (format " %%%ds"
596 (max (- text-width (1+ (string-width first-part)))
597 (string-width tags)))
598 tags))
599 ;; Maybe underline text, if ELEMENT type is `headline' and an
600 ;; underline character has been defined.
601 (when (and underline headlinep)
602 (let ((under-char
603 (nth (1- (org-export-get-relative-level element info))
604 (cdr (assq (plist-get info :ascii-charset)
605 org-ascii-underline)))))
606 (and under-char
607 (concat "\n"
608 (make-string (/ (string-width first-part)
609 (char-width under-char))
610 under-char))))))))
612 (defun org-ascii--has-caption-p (element info)
613 "Non-nil when ELEMENT has a caption affiliated keyword.
614 INFO is a plist used as a communication channel. This function
615 is meant to be used as a predicate for `org-export-get-ordinal'."
616 (org-element-property :caption element))
618 (defun org-ascii--build-caption (element info)
619 "Return caption string for ELEMENT, if applicable.
621 INFO is a plist used as a communication channel.
623 The caption string contains the sequence number of ELEMENT along
624 with its real caption. Return nil when ELEMENT has no affiliated
625 caption keyword."
626 (let ((caption (org-export-get-caption element)))
627 (when caption
628 ;; Get sequence number of current src-block among every
629 ;; src-block with a caption.
630 (let ((reference
631 (org-export-get-ordinal
632 element info nil 'org-ascii--has-caption-p))
633 (title-fmt (org-ascii--translate
634 (case (org-element-type element)
635 (table "Table %d:")
636 (src-block "Listing %d:"))
637 info)))
638 (org-ascii--fill-string
639 (concat (format title-fmt reference)
641 (org-export-data caption info))
642 (org-ascii--current-text-width element info) info)))))
644 (defun org-ascii--build-toc (info &optional n keyword)
645 "Return a table of contents.
647 INFO is a plist used as a communication channel.
649 Optional argument N, when non-nil, is an integer specifying the
650 depth of the table.
652 Optional argument KEYWORD specifies the TOC keyword, if any, from
653 which the table of contents generation has been initiated."
654 (let ((title (org-ascii--translate "Table of Contents" info)))
655 (concat
656 title "\n"
657 (make-string (string-width title)
658 (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))
659 "\n\n"
660 (let ((text-width
661 (if keyword (org-ascii--current-text-width keyword info)
662 (- org-ascii-text-width org-ascii-global-margin))))
663 (mapconcat
664 (lambda (headline)
665 (let* ((level (org-export-get-relative-level headline info))
666 (indent (* (1- level) 3)))
667 (concat
668 (unless (zerop indent) (concat (make-string (1- indent) ?.) " "))
669 (org-ascii--build-title
670 headline info (- text-width indent) nil
671 (or (not (plist-get info :with-tags))
672 (eq (plist-get info :with-tags) 'not-in-toc))
673 'toc))))
674 (org-export-collect-headlines info n) "\n")))))
676 (defun org-ascii--list-listings (keyword info)
677 "Return a list of listings.
679 KEYWORD is the keyword that initiated the list of listings
680 generation. INFO is a plist used as a communication channel."
681 (let ((title (org-ascii--translate "List of Listings" info)))
682 (concat
683 title "\n"
684 (make-string (string-width title)
685 (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))
686 "\n\n"
687 (let ((text-width
688 (if keyword (org-ascii--current-text-width keyword info)
689 (- org-ascii-text-width org-ascii-global-margin)))
690 ;; Use a counter instead of retrieving ordinal of each
691 ;; src-block.
692 (count 0))
693 (mapconcat
694 (lambda (src-block)
695 ;; Store initial text so its length can be computed. This is
696 ;; used to properly align caption right to it in case of
697 ;; filling (like contents of a description list item).
698 (let* ((initial-text
699 (format (org-ascii--translate "Listing %d:" info)
700 (incf count)))
701 (initial-width (string-width initial-text)))
702 (concat
703 initial-text " "
704 (org-trim
705 (org-ascii--indent-string
706 (org-ascii--fill-string
707 ;; Use short name in priority, if available.
708 (let ((caption (or (org-export-get-caption src-block t)
709 (org-export-get-caption src-block))))
710 (org-export-data caption info))
711 (- text-width initial-width) info)
712 initial-width)))))
713 (org-export-collect-listings info) "\n")))))
715 (defun org-ascii--list-tables (keyword info)
716 "Return a list of tables.
718 KEYWORD is the keyword that initiated the list of tables
719 generation. INFO is a plist used as a communication channel."
720 (let ((title (org-ascii--translate "List of Tables" info)))
721 (concat
722 title "\n"
723 (make-string (string-width title)
724 (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))
725 "\n\n"
726 (let ((text-width
727 (if keyword (org-ascii--current-text-width keyword info)
728 (- org-ascii-text-width org-ascii-global-margin)))
729 ;; Use a counter instead of retrieving ordinal of each
730 ;; src-block.
731 (count 0))
732 (mapconcat
733 (lambda (table)
734 ;; Store initial text so its length can be computed. This is
735 ;; used to properly align caption right to it in case of
736 ;; filling (like contents of a description list item).
737 (let* ((initial-text
738 (format (org-ascii--translate "Table %d:" info)
739 (incf count)))
740 (initial-width (string-width initial-text)))
741 (concat
742 initial-text " "
743 (org-trim
744 (org-ascii--indent-string
745 (org-ascii--fill-string
746 ;; Use short name in priority, if available.
747 (let ((caption (or (org-export-get-caption table t)
748 (org-export-get-caption table))))
749 (org-export-data caption info))
750 (- text-width initial-width) info)
751 initial-width)))))
752 (org-export-collect-tables info) "\n")))))
754 (defun org-ascii--unique-links (element info)
755 "Return a list of unique link references in ELEMENT.
756 ELEMENT is either a headline element or a section element. INFO
757 is a plist used as a communication channel."
758 (let* (seen
759 (unique-link-p
760 (function
761 ;; Return LINK if it wasn't referenced so far, or nil.
762 ;; Update SEEN links along the way.
763 (lambda (link)
764 (let ((footprint
765 ;; Normalize description in footprints.
766 (cons (org-element-property :raw-link link)
767 (let ((contents (org-element-contents link)))
768 (and contents
769 (replace-regexp-in-string
770 "[ \r\t\n]+" " "
771 (org-trim
772 (org-element-interpret-data contents))))))))
773 ;; Ignore LINK if it hasn't been translated already.
774 ;; It can happen if it is located in an affiliated
775 ;; keyword that was ignored.
776 (when (and (org-string-nw-p
777 (gethash link (plist-get info :exported-data)))
778 (not (member footprint seen)))
779 (push footprint seen) link)))))
780 ;; If at a section, find parent headline, if any, in order to
781 ;; count links that might be in the title.
782 (headline
783 (if (eq (org-element-type element) 'headline) element
784 (or (org-export-get-parent-headline element) element))))
785 ;; Get all links in HEADLINE.
786 (org-element-map headline 'link
787 (lambda (l) (funcall unique-link-p l)) info nil nil t)))
789 (defun org-ascii--describe-links (links width info)
790 "Return a string describing a list of links.
792 LINKS is a list of link type objects, as returned by
793 `org-ascii--unique-links'. WIDTH is the text width allowed for
794 the output string. INFO is a plist used as a communication
795 channel."
796 (mapconcat
797 (lambda (link)
798 (let ((type (org-element-property :type link))
799 (anchor (let ((desc (org-element-contents link)))
800 (if desc (org-export-data desc info)
801 (org-element-property :raw-link link)))))
802 (cond
803 ;; Coderefs, radio links and fuzzy links are ignored.
804 ((member type '("coderef" "radio" "fuzzy")) nil)
805 ;; Id and custom-id links: Headlines refer to their numbering.
806 ((member type '("custom-id" "id"))
807 (let ((dest (org-export-resolve-id-link link info)))
808 (concat
809 (org-ascii--fill-string
810 (format
811 "[%s] %s"
812 anchor
813 (if (not dest) (org-ascii--translate "Unknown reference" info)
814 (format
815 (org-ascii--translate "See section %s" info)
816 (mapconcat 'number-to-string
817 (org-export-get-headline-number dest info) "."))))
818 width info) "\n\n")))
819 ;; Do not add a link that cannot be resolved and doesn't have
820 ;; any description: destination is already visible in the
821 ;; paragraph.
822 ((not (org-element-contents link)) nil)
824 (concat
825 (org-ascii--fill-string
826 (format "[%s] %s" anchor (org-element-property :raw-link link))
827 width info)
828 "\n\n")))))
829 links ""))
831 (defun org-ascii--checkbox (item info)
832 "Return checkbox string for ITEM or nil.
833 INFO is a plist used as a communication channel."
834 (let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
835 (case (org-element-property :checkbox item)
836 (on (if utf8p "☑ " "[X] "))
837 (off (if utf8p "☐ " "[ ] "))
838 (trans (if utf8p "☒ " "[-] ")))))
842 ;;; Template
844 (defun org-ascii-template--document-title (info)
845 "Return document title, as a string.
846 INFO is a plist used as a communication channel."
847 (let* ((text-width org-ascii-text-width)
848 ;; Links in the title will not be resolved later, so we make
849 ;; sure their path is located right after them.
850 (org-ascii-links-to-notes nil)
851 (title (org-export-data (plist-get info :title) info))
852 (author (and (plist-get info :with-author)
853 (let ((auth (plist-get info :author)))
854 (and auth (org-export-data auth info)))))
855 (email (and (plist-get info :with-email)
856 (org-export-data (plist-get info :email) info)))
857 (date (and (plist-get info :with-date)
858 (org-export-data (org-export-get-date info) info))))
859 ;; There are two types of title blocks depending on the presence
860 ;; of a title to display.
861 (if (string= title "")
862 ;; Title block without a title. DATE is positioned at the top
863 ;; right of the document, AUTHOR to the top left and EMAIL
864 ;; just below.
865 (cond
866 ((and (org-string-nw-p date) (org-string-nw-p author))
867 (concat
868 author
869 (make-string (- text-width (string-width date) (string-width author))
870 ?\s)
871 date
872 (when (org-string-nw-p email) (concat "\n" email))
873 "\n\n\n"))
874 ((and (org-string-nw-p date) (org-string-nw-p email))
875 (concat
876 email
877 (make-string (- text-width (string-width date) (string-width email))
878 ?\s)
879 date "\n\n\n"))
880 ((org-string-nw-p date)
881 (concat
882 (org-ascii--justify-string date text-width 'right)
883 "\n\n\n"))
884 ((and (org-string-nw-p author) (org-string-nw-p email))
885 (concat author "\n" email "\n\n\n"))
886 ((org-string-nw-p author) (concat author "\n\n\n"))
887 ((org-string-nw-p email) (concat email "\n\n\n")))
888 ;; Title block with a title. Document's TITLE, along with the
889 ;; AUTHOR and its EMAIL are both overlined and an underlined,
890 ;; centered. Date is just below, also centered.
891 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8))
892 ;; Format TITLE. It may be filled if it is too wide,
893 ;; that is wider than the two thirds of the total width.
894 (title-len (min (length title) (/ (* 2 text-width) 3)))
895 (formatted-title (org-ascii--fill-string title title-len info))
896 (line
897 (make-string
898 (min (+ (max title-len
899 (string-width (or author ""))
900 (string-width (or email "")))
902 text-width) (if utf8p ?━ ?_))))
903 (org-ascii--justify-string
904 (concat line "\n"
905 (unless utf8p "\n")
906 (upcase formatted-title)
907 (cond
908 ((and (org-string-nw-p author) (org-string-nw-p email))
909 (concat (if utf8p "\n\n\n" "\n\n") author "\n" email))
910 ((org-string-nw-p author)
911 (concat (if utf8p "\n\n\n" "\n\n") author))
912 ((org-string-nw-p email)
913 (concat (if utf8p "\n\n\n" "\n\n") email)))
914 "\n" line
915 (when (org-string-nw-p date) (concat "\n\n\n" date))
916 "\n\n\n") text-width 'center)))))
918 (defun org-ascii-inner-template (contents info)
919 "Return complete document string after ASCII conversion.
920 CONTENTS is the transcoded contents string. INFO is a plist
921 holding export options."
922 (org-element-normalize-string
923 (org-ascii--indent-string
924 (concat
925 ;; 1. Document's body.
926 contents
927 ;; 2. Footnote definitions.
928 (let ((definitions (org-export-collect-footnote-definitions
929 (plist-get info :parse-tree) info))
930 ;; Insert full links right inside the footnote definition
931 ;; as they have no chance to be inserted later.
932 (org-ascii-links-to-notes nil))
933 (when definitions
934 (concat
935 "\n\n\n"
936 (let ((title (org-ascii--translate "Footnotes" info)))
937 (concat
938 title "\n"
939 (make-string
940 (string-width title)
941 (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))))
942 "\n\n"
943 (let ((text-width (- org-ascii-text-width org-ascii-global-margin)))
944 (mapconcat
945 (lambda (ref)
946 (let ((id (format "[%s] " (car ref))))
947 ;; Distinguish between inline definitions and
948 ;; full-fledged definitions.
949 (org-trim
950 (let ((def (nth 2 ref)))
951 (if (eq (org-element-type def) 'org-data)
952 ;; Full-fledged definition: footnote ID is
953 ;; inserted inside the first parsed paragraph
954 ;; (FIRST), if any, to be sure filling will
955 ;; take it into consideration.
956 (let ((first (car (org-element-contents def))))
957 (if (not (eq (org-element-type first) 'paragraph))
958 (concat id "\n" (org-export-data def info))
959 (push id (nthcdr 2 first))
960 (org-export-data def info)))
961 ;; Fill paragraph once footnote ID is inserted
962 ;; in order to have a correct length for first
963 ;; line.
964 (org-ascii--fill-string
965 (concat id (org-export-data def info))
966 text-width info))))))
967 definitions "\n\n"))))))
968 org-ascii-global-margin)))
970 (defun org-ascii-template (contents info)
971 "Return complete document string after ASCII conversion.
972 CONTENTS is the transcoded contents string. INFO is a plist
973 holding export options."
974 (concat
975 ;; 1. Build title block.
976 (org-ascii--indent-string
977 (concat (org-ascii-template--document-title info)
978 ;; 2. Table of contents.
979 (let ((depth (plist-get info :with-toc)))
980 (when depth
981 (concat
982 (org-ascii--build-toc info (and (wholenump depth) depth))
983 "\n\n\n"))))
984 org-ascii-global-margin)
985 ;; 3. Document's body.
986 contents
987 ;; 4. Creator. Ignore `comment' value as there are no comments in
988 ;; ASCII. Justify it to the bottom right.
989 (org-ascii--indent-string
990 (let ((creator-info (plist-get info :with-creator))
991 (text-width (- org-ascii-text-width org-ascii-global-margin)))
992 (unless (or (not creator-info) (eq creator-info 'comment))
993 (concat
994 "\n\n\n"
995 (org-ascii--fill-string
996 (plist-get info :creator) text-width info 'right))))
997 org-ascii-global-margin)))
999 (defun org-ascii--translate (s info)
1000 "Translate string S according to specified language and charset.
1001 INFO is a plist used as a communication channel."
1002 (let ((charset (intern (format ":%s" (plist-get info :ascii-charset)))))
1003 (org-export-translate s charset info)))
1007 ;;; Transcode Functions
1009 ;;;; Bold
1011 (defun org-ascii-bold (bold contents info)
1012 "Transcode BOLD from Org to ASCII.
1013 CONTENTS is the text with bold markup. INFO is a plist holding
1014 contextual information."
1015 (format "*%s*" contents))
1018 ;;;; Center Block
1020 (defun org-ascii-center-block (center-block contents info)
1021 "Transcode a CENTER-BLOCK element from Org to ASCII.
1022 CONTENTS holds the contents of the block. INFO is a plist
1023 holding contextual information."
1024 (org-ascii--justify-string
1025 contents (org-ascii--current-text-width center-block info) 'center))
1028 ;;;; Clock
1030 (defun org-ascii-clock (clock contents info)
1031 "Transcode a CLOCK object from Org to ASCII.
1032 CONTENTS is nil. INFO is a plist holding contextual
1033 information."
1034 (concat org-clock-string " "
1035 (org-translate-time
1036 (org-element-property :raw-value
1037 (org-element-property :value clock)))
1038 (let ((time (org-element-property :duration clock)))
1039 (and time
1040 (concat " => "
1041 (apply 'format
1042 "%2s:%02s"
1043 (org-split-string time ":")))))))
1046 ;;;; Code
1048 (defun org-ascii-code (code contents info)
1049 "Return a CODE object from Org to ASCII.
1050 CONTENTS is nil. INFO is a plist holding contextual
1051 information."
1052 (format org-ascii-verbatim-format (org-element-property :value code)))
1055 ;;;; Drawer
1057 (defun org-ascii-drawer (drawer contents info)
1058 "Transcode a DRAWER element from Org to ASCII.
1059 CONTENTS holds the contents of the block. INFO is a plist
1060 holding contextual information."
1061 (let ((name (org-element-property :drawer-name drawer))
1062 (width (org-ascii--current-text-width drawer info)))
1063 (funcall org-ascii-format-drawer-function name contents width)))
1066 ;;;; Dynamic Block
1068 (defun org-ascii-dynamic-block (dynamic-block contents info)
1069 "Transcode a DYNAMIC-BLOCK element from Org to ASCII.
1070 CONTENTS holds the contents of the block. INFO is a plist
1071 holding contextual information."
1072 contents)
1075 ;;;; Entity
1077 (defun org-ascii-entity (entity contents info)
1078 "Transcode an ENTITY object from Org to ASCII.
1079 CONTENTS are the definition itself. INFO is a plist holding
1080 contextual information."
1081 (org-element-property
1082 (intern (concat ":" (symbol-name (plist-get info :ascii-charset))))
1083 entity))
1086 ;;;; Example Block
1088 (defun org-ascii-example-block (example-block contents info)
1089 "Transcode a EXAMPLE-BLOCK element from Org to ASCII.
1090 CONTENTS is nil. INFO is a plist holding contextual information."
1091 (org-ascii--box-string
1092 (org-export-format-code-default example-block info) info))
1095 ;;;; Export Snippet
1097 (defun org-ascii-export-snippet (export-snippet contents info)
1098 "Transcode a EXPORT-SNIPPET object from Org to ASCII.
1099 CONTENTS is nil. INFO is a plist holding contextual information."
1100 (when (eq (org-export-snippet-backend export-snippet) 'ascii)
1101 (org-element-property :value export-snippet)))
1104 ;;;; Export Block
1106 (defun org-ascii-export-block (export-block contents info)
1107 "Transcode a EXPORT-BLOCK element from Org to ASCII.
1108 CONTENTS is nil. INFO is a plist holding contextual information."
1109 (when (string= (org-element-property :type export-block) "ASCII")
1110 (org-remove-indentation (org-element-property :value export-block))))
1113 ;;;; Fixed Width
1115 (defun org-ascii-fixed-width (fixed-width contents info)
1116 "Transcode a FIXED-WIDTH element from Org to ASCII.
1117 CONTENTS is nil. INFO is a plist holding contextual information."
1118 (org-ascii--box-string
1119 (org-remove-indentation
1120 (org-element-property :value fixed-width)) info))
1123 ;;;; Footnote Definition
1125 ;; Footnote Definitions are ignored. They are compiled at the end of
1126 ;; the document, by `org-ascii-inner-template'.
1129 ;;;; Footnote Reference
1131 (defun org-ascii-footnote-reference (footnote-reference contents info)
1132 "Transcode a FOOTNOTE-REFERENCE element from Org to ASCII.
1133 CONTENTS is nil. INFO is a plist holding contextual information."
1134 (format "[%s]" (org-export-get-footnote-number footnote-reference info)))
1137 ;;;; Headline
1139 (defun org-ascii-headline (headline contents info)
1140 "Transcode a HEADLINE element from Org to ASCII.
1141 CONTENTS holds the contents of the headline. INFO is a plist
1142 holding contextual information."
1143 ;; Don't export footnote section, which will be handled at the end
1144 ;; of the template.
1145 (unless (org-element-property :footnote-section-p headline)
1146 (let* ((low-level-rank (org-export-low-level-p headline info))
1147 (width (org-ascii--current-text-width headline info))
1148 ;; Blank lines between headline and its contents.
1149 ;; `org-ascii-headline-spacing', when set, overwrites
1150 ;; original buffer's spacing.
1151 (pre-blanks
1152 (make-string
1153 (if org-ascii-headline-spacing (car org-ascii-headline-spacing)
1154 (org-element-property :pre-blank headline)) ?\n))
1155 ;; Even if HEADLINE has no section, there might be some
1156 ;; links in its title that we shouldn't forget to describe.
1157 (links
1158 (unless (or (eq (caar (org-element-contents headline)) 'section))
1159 (let ((title (org-element-property :title headline)))
1160 (when (consp title)
1161 (org-ascii--describe-links
1162 (org-ascii--unique-links title info) width info))))))
1163 ;; Deep subtree: export it as a list item.
1164 (if low-level-rank
1165 (concat
1166 ;; Bullet.
1167 (let ((bullets (cdr (assq (plist-get info :ascii-charset)
1168 org-ascii-bullets))))
1169 (char-to-string
1170 (nth (mod (1- low-level-rank) (length bullets)) bullets)))
1172 ;; Title.
1173 (org-ascii--build-title headline info width) "\n"
1174 ;; Contents, indented by length of bullet.
1175 pre-blanks
1176 (org-ascii--indent-string
1177 (concat contents
1178 (when (org-string-nw-p links) (concat "\n\n" links)))
1180 ;; Else: Standard headline.
1181 (concat
1182 (org-ascii--build-title headline info width 'underline)
1183 "\n" pre-blanks
1184 (concat (when (org-string-nw-p links) links) contents))))))
1187 ;;;; Horizontal Rule
1189 (defun org-ascii-horizontal-rule (horizontal-rule contents info)
1190 "Transcode an HORIZONTAL-RULE object from Org to ASCII.
1191 CONTENTS is nil. INFO is a plist holding contextual
1192 information."
1193 (let ((text-width (org-ascii--current-text-width horizontal-rule info))
1194 (spec-width
1195 (org-export-read-attribute :attr_ascii horizontal-rule :width)))
1196 (org-ascii--justify-string
1197 (make-string (if (and spec-width (string-match "^[0-9]+$" spec-width))
1198 (string-to-number spec-width)
1199 text-width)
1200 (if (eq (plist-get info :ascii-charset) 'utf-8) ?― ?-))
1201 text-width 'center)))
1204 ;;;; Inline Src Block
1206 (defun org-ascii-inline-src-block (inline-src-block contents info)
1207 "Transcode an INLINE-SRC-BLOCK element from Org to ASCII.
1208 CONTENTS holds the contents of the item. INFO is a plist holding
1209 contextual information."
1210 (format org-ascii-verbatim-format
1211 (org-element-property :value inline-src-block)))
1214 ;;;; Inlinetask
1216 (defun org-ascii-format-inlinetask-default
1217 (todo type priority name tags contents width inlinetask info)
1218 "Format an inline task element for ASCII export.
1219 See `org-ascii-format-inlinetask-function' for a description
1220 of the parameters."
1221 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8))
1222 (width (or width org-ascii-inlinetask-width)))
1223 (org-ascii--indent-string
1224 (concat
1225 ;; Top line, with an additional blank line if not in UTF-8.
1226 (make-string width (if utf8p ?━ ?_)) "\n"
1227 (unless utf8p (concat (make-string width ? ) "\n"))
1228 ;; Add title. Fill it if wider than inlinetask.
1229 (let ((title (org-ascii--build-title inlinetask info width)))
1230 (if (<= (string-width title) width) title
1231 (org-ascii--fill-string title width info)))
1232 "\n"
1233 ;; If CONTENTS is not empty, insert it along with
1234 ;; a separator.
1235 (when (org-string-nw-p contents)
1236 (concat (make-string width (if utf8p ?─ ?-)) "\n" contents))
1237 ;; Bottom line.
1238 (make-string width (if utf8p ?━ ?_)))
1239 ;; Flush the inlinetask to the right.
1240 (- org-ascii-text-width org-ascii-global-margin
1241 (if (not (org-export-get-parent-headline inlinetask)) 0
1242 org-ascii-inner-margin)
1243 (org-ascii--current-text-width inlinetask info)))))
1245 (defun org-ascii-inlinetask (inlinetask contents info)
1246 "Transcode an INLINETASK element from Org to ASCII.
1247 CONTENTS holds the contents of the block. INFO is a plist
1248 holding contextual information."
1249 (let ((width (org-ascii--current-text-width inlinetask info)))
1250 (funcall org-ascii-format-inlinetask-function
1251 ;; todo.
1252 (and (plist-get info :with-todo-keywords)
1253 (let ((todo (org-element-property
1254 :todo-keyword inlinetask)))
1255 (and todo (org-export-data todo info))))
1256 ;; todo-type
1257 (org-element-property :todo-type inlinetask)
1258 ;; priority
1259 (and (plist-get info :with-priority)
1260 (org-element-property :priority inlinetask))
1261 ;; title
1262 (org-export-data (org-element-property :title inlinetask) info)
1263 ;; tags
1264 (and (plist-get info :with-tags)
1265 (org-element-property :tags inlinetask))
1266 ;; contents and width
1267 contents width inlinetask info)))
1270 ;;;; Italic
1272 (defun org-ascii-italic (italic contents info)
1273 "Transcode italic from Org to ASCII.
1274 CONTENTS is the text with italic markup. INFO is a plist holding
1275 contextual information."
1276 (format "/%s/" contents))
1279 ;;;; Item
1281 (defun org-ascii-item (item contents info)
1282 "Transcode an ITEM element from Org to ASCII.
1283 CONTENTS holds the contents of the item. INFO is a plist holding
1284 contextual information."
1285 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8))
1286 (checkbox (org-ascii--checkbox item info))
1287 (list-type (org-element-property :type (org-export-get-parent item)))
1288 (bullet
1289 ;; First parent of ITEM is always the plain-list. Get
1290 ;; `:type' property from it.
1291 (org-list-bullet-string
1292 (case list-type
1293 (descriptive
1294 (concat checkbox
1295 (org-export-data (org-element-property :tag item) info)
1296 ": "))
1297 (ordered
1298 ;; Return correct number for ITEM, paying attention to
1299 ;; counters.
1300 (let* ((struct (org-element-property :structure item))
1301 (bul (org-element-property :bullet item))
1302 (num (number-to-string
1303 (car (last (org-list-get-item-number
1304 (org-element-property :begin item)
1305 struct
1306 (org-list-prevs-alist struct)
1307 (org-list-parents-alist struct)))))))
1308 (replace-regexp-in-string "[0-9]+" num bul)))
1309 (t (let ((bul (org-element-property :bullet item)))
1310 ;; Change bullets into more visible form if UTF-8 is active.
1311 (if (not utf8p) bul
1312 (replace-regexp-in-string
1313 "-" "•"
1314 (replace-regexp-in-string
1315 "+" "⁃"
1316 (replace-regexp-in-string "*" "‣" bul))))))))))
1317 (concat
1318 bullet
1319 (unless (eq list-type 'descriptive) checkbox)
1320 ;; Contents: Pay attention to indentation. Note: check-boxes are
1321 ;; already taken care of at the paragraph level so they don't
1322 ;; interfere with indentation.
1323 (let ((contents (org-ascii--indent-string contents (string-width bullet))))
1324 (if (eq (org-element-type (car (org-element-contents item))) 'paragraph)
1325 (org-trim contents)
1326 (concat "\n" contents))))))
1329 ;;;; Keyword
1331 (defun org-ascii-keyword (keyword contents info)
1332 "Transcode a KEYWORD element from Org to ASCII.
1333 CONTENTS is nil. INFO is a plist holding contextual
1334 information."
1335 (let ((key (org-element-property :key keyword))
1336 (value (org-element-property :value keyword)))
1337 (cond
1338 ((string= key "ASCII") value)
1339 ((string= key "TOC")
1340 (let ((value (downcase value)))
1341 (cond
1342 ((string-match "\\<headlines\\>" value)
1343 (let ((depth (or (and (string-match "[0-9]+" value)
1344 (string-to-number (match-string 0 value)))
1345 (plist-get info :with-toc))))
1346 (org-ascii--build-toc
1347 info (and (wholenump depth) depth) keyword)))
1348 ((string= "tables" value)
1349 (org-ascii--list-tables keyword info))
1350 ((string= "listings" value)
1351 (org-ascii--list-listings keyword info))))))))
1354 ;;;; Latex Environment
1356 (defun org-ascii-latex-environment (latex-environment contents info)
1357 "Transcode a LATEX-ENVIRONMENT element from Org to ASCII.
1358 CONTENTS is nil. INFO is a plist holding contextual
1359 information."
1360 (when (plist-get info :with-latex)
1361 (org-remove-indentation (org-element-property :value latex-environment))))
1364 ;;;; Latex Fragment
1366 (defun org-ascii-latex-fragment (latex-fragment contents info)
1367 "Transcode a LATEX-FRAGMENT object from Org to ASCII.
1368 CONTENTS is nil. INFO is a plist holding contextual
1369 information."
1370 (when (plist-get info :with-latex)
1371 (org-element-property :value latex-fragment)))
1374 ;;;; Line Break
1376 (defun org-ascii-line-break (line-break contents info)
1377 "Transcode a LINE-BREAK object from Org to ASCII.
1378 CONTENTS is nil. INFO is a plist holding contextual
1379 information." hard-newline)
1382 ;;;; Link
1384 (defun org-ascii-link (link desc info)
1385 "Transcode a LINK object from Org to ASCII.
1387 DESC is the description part of the link, or the empty string.
1388 INFO is a plist holding contextual information."
1389 (let ((raw-link (org-element-property :raw-link link))
1390 (type (org-element-property :type link)))
1391 (cond
1392 ((string= type "coderef")
1393 (let ((ref (org-element-property :path link)))
1394 (format (org-export-get-coderef-format ref desc)
1395 (org-export-resolve-coderef ref info))))
1396 ;; Do not apply a special syntax on radio links. Though, use
1397 ;; transcoded target's contents as output.
1398 ((string= type "radio") desc)
1399 ;; Do not apply a special syntax on fuzzy links pointing to
1400 ;; targets.
1401 ((string= type "fuzzy")
1402 (let ((destination (org-export-resolve-fuzzy-link link info)))
1403 (if (org-string-nw-p desc) desc
1404 (when destination
1405 (let ((number
1406 (org-export-get-ordinal
1407 destination info nil 'org-ascii--has-caption-p)))
1408 (when number
1409 (if (atom number) (number-to-string number)
1410 (mapconcat 'number-to-string number "."))))))))
1412 (if (not (org-string-nw-p desc)) (format "[%s]" raw-link)
1413 (concat
1414 (format "[%s]" desc)
1415 (unless org-ascii-links-to-notes (format " (%s)" raw-link))))))))
1418 ;;;; Node Properties
1420 (defun org-ascii-node-property (node-property contents info)
1421 "Transcode a NODE-PROPERTY element from Org to ASCII.
1422 CONTENTS is nil. INFO is a plist holding contextual
1423 information."
1424 (format "%s:%s"
1425 (org-element-property :key node-property)
1426 (let ((value (org-element-property :value node-property)))
1427 (if value (concat " " value) ""))))
1430 ;;;; Paragraph
1432 (defun org-ascii-paragraph (paragraph contents info)
1433 "Transcode a PARAGRAPH element from Org to ASCII.
1434 CONTENTS is the contents of the paragraph, as a string. INFO is
1435 the plist used as a communication channel."
1436 (org-ascii--fill-string
1437 (if (not (wholenump org-ascii-indented-line-width)) contents
1438 (concat
1439 ;; Do not indent first paragraph in a section.
1440 (unless (and (not (org-export-get-previous-element paragraph info))
1441 (eq (org-element-type (org-export-get-parent paragraph))
1442 'section))
1443 (make-string org-ascii-indented-line-width ?\s))
1444 (replace-regexp-in-string "\\`[ \t]+" "" contents)))
1445 (org-ascii--current-text-width paragraph info) info))
1448 ;;;; Plain List
1450 (defun org-ascii-plain-list (plain-list contents info)
1451 "Transcode a PLAIN-LIST element from Org to ASCII.
1452 CONTENTS is the contents of the list. INFO is a plist holding
1453 contextual information."
1454 contents)
1457 ;;;; Plain Text
1459 (defun org-ascii-plain-text (text info)
1460 "Transcode a TEXT string from Org to ASCII.
1461 INFO is a plist used as a communication channel."
1462 (let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
1463 (when (and utf8p (plist-get info :with-smart-quotes))
1464 (setq text (org-export-activate-smart-quotes text :utf-8 info)))
1465 (if (not (plist-get info :with-special-strings)) text
1466 (setq text (replace-regexp-in-string "\\\\-" "" text))
1467 (if (not utf8p) text
1468 ;; Usual replacements in utf-8 with proper option set.
1469 (replace-regexp-in-string
1470 "\\.\\.\\." "…"
1471 (replace-regexp-in-string
1472 "--" "–"
1473 (replace-regexp-in-string "---" "—" text)))))))
1476 ;;;; Planning
1478 (defun org-ascii-planning (planning contents info)
1479 "Transcode a PLANNING element from Org to ASCII.
1480 CONTENTS is nil. INFO is a plist used as a communication
1481 channel."
1482 (mapconcat
1483 'identity
1484 (delq nil
1485 (list (let ((closed (org-element-property :closed planning)))
1486 (when closed
1487 (concat org-closed-string " "
1488 (org-translate-time
1489 (org-element-property :raw-value closed)))))
1490 (let ((deadline (org-element-property :deadline planning)))
1491 (when deadline
1492 (concat org-deadline-string " "
1493 (org-translate-time
1494 (org-element-property :raw-value deadline)))))
1495 (let ((scheduled (org-element-property :scheduled planning)))
1496 (when scheduled
1497 (concat org-scheduled-string " "
1498 (org-translate-time
1499 (org-element-property :raw-value scheduled)))))))
1500 " "))
1503 ;;;; Property Drawer
1505 (defun org-ascii-property-drawer (property-drawer contents info)
1506 "Transcode a PROPERTY-DRAWER element from Org to ASCII.
1507 CONTENTS holds the contents of the drawer. INFO is a plist
1508 holding contextual information."
1509 (org-string-nw-p contents))
1512 ;;;; Quote Block
1514 (defun org-ascii-quote-block (quote-block contents info)
1515 "Transcode a QUOTE-BLOCK element from Org to ASCII.
1516 CONTENTS holds the contents of the block. INFO is a plist
1517 holding contextual information."
1518 (org-ascii--indent-string contents org-ascii-quote-margin))
1521 ;;;; Radio Target
1523 (defun org-ascii-radio-target (radio-target contents info)
1524 "Transcode a RADIO-TARGET object from Org to ASCII.
1525 CONTENTS is the contents of the target. INFO is a plist holding
1526 contextual information."
1527 contents)
1530 ;;;; Section
1532 (defun org-ascii-section (section contents info)
1533 "Transcode a SECTION element from Org to ASCII.
1534 CONTENTS is the contents of the section. INFO is a plist holding
1535 contextual information."
1536 (org-ascii--indent-string
1537 (concat
1538 contents
1539 (when org-ascii-links-to-notes
1540 ;; Add list of links at the end of SECTION.
1541 (let ((links (org-ascii--describe-links
1542 (org-ascii--unique-links section info)
1543 (org-ascii--current-text-width section info) info)))
1544 ;; Separate list of links and section contents.
1545 (when (org-string-nw-p links) (concat "\n\n" links)))))
1546 ;; Do not apply inner margin if parent headline is low level.
1547 (let ((headline (org-export-get-parent-headline section)))
1548 (if (or (not headline) (org-export-low-level-p headline info)) 0
1549 org-ascii-inner-margin))))
1552 ;;;; Special Block
1554 (defun org-ascii-special-block (special-block contents info)
1555 "Transcode a SPECIAL-BLOCK element from Org to ASCII.
1556 CONTENTS holds the contents of the block. INFO is a plist
1557 holding contextual information."
1558 contents)
1561 ;;;; Src Block
1563 (defun org-ascii-src-block (src-block contents info)
1564 "Transcode a SRC-BLOCK element from Org to ASCII.
1565 CONTENTS holds the contents of the item. INFO is a plist holding
1566 contextual information."
1567 (let ((caption (org-ascii--build-caption src-block info))
1568 (code (org-export-format-code-default src-block info)))
1569 (if (equal code "") ""
1570 (concat
1571 (when (and caption org-ascii-caption-above) (concat caption "\n"))
1572 (org-ascii--box-string code info)
1573 (when (and caption (not org-ascii-caption-above))
1574 (concat "\n" caption))))))
1577 ;;;; Statistics Cookie
1579 (defun org-ascii-statistics-cookie (statistics-cookie contents info)
1580 "Transcode a STATISTICS-COOKIE object from Org to ASCII.
1581 CONTENTS is nil. INFO is a plist holding contextual information."
1582 (org-element-property :value statistics-cookie))
1585 ;;;; Subscript
1587 (defun org-ascii-subscript (subscript contents info)
1588 "Transcode a SUBSCRIPT object from Org to ASCII.
1589 CONTENTS is the contents of the object. INFO is a plist holding
1590 contextual information."
1591 (if (org-element-property :use-brackets-p subscript)
1592 (format "_{%s}" contents)
1593 (format "_%s" contents)))
1596 ;;;; Superscript
1598 (defun org-ascii-superscript (superscript contents info)
1599 "Transcode a SUPERSCRIPT object from Org to ASCII.
1600 CONTENTS is the contents of the object. INFO is a plist holding
1601 contextual information."
1602 (if (org-element-property :use-brackets-p superscript)
1603 (format "^{%s}" contents)
1604 (format "^%s" contents)))
1607 ;;;; Strike-through
1609 (defun org-ascii-strike-through (strike-through contents info)
1610 "Transcode STRIKE-THROUGH from Org to ASCII.
1611 CONTENTS is text with strike-through markup. INFO is a plist
1612 holding contextual information."
1613 (format "+%s+" contents))
1616 ;;;; Table
1618 (defun org-ascii-table (table contents info)
1619 "Transcode a TABLE element from Org to ASCII.
1620 CONTENTS is the contents of the table. INFO is a plist holding
1621 contextual information."
1622 (let ((caption (org-ascii--build-caption table info)))
1623 (concat
1624 ;; Possibly add a caption string above.
1625 (when (and caption org-ascii-caption-above) (concat caption "\n"))
1626 ;; Insert table. Note: "table.el" tables are left unmodified.
1627 (cond ((eq (org-element-property :type table) 'org) contents)
1628 ((and org-ascii-table-use-ascii-art
1629 (eq (plist-get info :ascii-charset) 'utf-8)
1630 (require 'ascii-art-to-unicode nil t))
1631 (with-temp-buffer
1632 (insert (org-remove-indentation
1633 (org-element-property :value table)))
1634 (goto-char (point-min))
1635 (aa2u)
1636 (goto-char (point-max))
1637 (skip-chars-backward " \r\t\n")
1638 (buffer-substring (point-min) (point))))
1639 (t (org-remove-indentation (org-element-property :value table))))
1640 ;; Possible add a caption string below.
1641 (and (not org-ascii-caption-above) caption))))
1644 ;;;; Table Cell
1646 (defun org-ascii--table-cell-width (table-cell info)
1647 "Return width of TABLE-CELL.
1649 INFO is a plist used as a communication channel.
1651 Width of a cell is determined either by a width cookie in the
1652 same column as the cell, or by the maximum cell's length in that
1653 column.
1655 When `org-ascii-table-widen-columns' is non-nil, width cookies
1656 are ignored."
1657 (let* ((row (org-export-get-parent table-cell))
1658 (table (org-export-get-parent row))
1659 (col (let ((cells (org-element-contents row)))
1660 (- (length cells) (length (memq table-cell cells)))))
1661 (cache
1662 (or (plist-get info :ascii-table-cell-width-cache)
1663 (plist-get (setq info
1664 (plist-put info :ascii-table-cell-width-cache
1665 (make-hash-table :test 'equal)))
1666 :ascii-table-cell-width-cache)))
1667 (key (cons table col)))
1668 (or (gethash key cache)
1669 (puthash
1671 (or (and (not org-ascii-table-widen-columns)
1672 (org-export-table-cell-width table-cell info))
1673 (let* ((max-width 0))
1674 (org-element-map table 'table-row
1675 (lambda (row)
1676 (setq max-width
1677 (max (string-width
1678 (org-export-data
1679 (org-element-contents
1680 (elt (org-element-contents row) col))
1681 info))
1682 max-width)))
1683 info)
1684 max-width))
1685 cache))))
1687 (defun org-ascii-table-cell (table-cell contents info)
1688 "Transcode a TABLE-CELL object from Org to ASCII.
1689 CONTENTS is the cell contents. INFO is a plist used as
1690 a communication channel."
1691 ;; Determine column width. When `org-ascii-table-widen-columns'
1692 ;; is nil and some width cookie has set it, use that value.
1693 ;; Otherwise, compute the maximum width among transcoded data of
1694 ;; each cell in the column.
1695 (let ((width (org-ascii--table-cell-width table-cell info)))
1696 ;; When contents are too large, truncate them.
1697 (unless (or org-ascii-table-widen-columns
1698 (<= (string-width (or contents "")) width))
1699 (setq contents (concat (substring contents 0 (- width 2)) "=>")))
1700 ;; Align contents correctly within the cell.
1701 (let* ((indent-tabs-mode nil)
1702 (data
1703 (when contents
1704 (org-ascii--justify-string
1705 contents width
1706 (org-export-table-cell-alignment table-cell info)))))
1707 (setq contents
1708 (concat data
1709 (make-string (- width (string-width (or data ""))) ?\s))))
1710 ;; Return cell.
1711 (concat (format " %s " contents)
1712 (when (memq 'right (org-export-table-cell-borders table-cell info))
1713 (if (eq (plist-get info :ascii-charset) 'utf-8) "│" "|")))))
1716 ;;;; Table Row
1718 (defun org-ascii-table-row (table-row contents info)
1719 "Transcode a TABLE-ROW element from Org to ASCII.
1720 CONTENTS is the row contents. INFO is a plist used as
1721 a communication channel."
1722 (when (eq (org-element-property :type table-row) 'standard)
1723 (let ((build-hline
1724 (function
1725 (lambda (lcorner horiz vert rcorner)
1726 (concat
1727 (apply
1728 'concat
1729 (org-element-map table-row 'table-cell
1730 (lambda (cell)
1731 (let ((width (org-ascii--table-cell-width cell info))
1732 (borders (org-export-table-cell-borders cell info)))
1733 (concat
1734 ;; In order to know if CELL starts the row, do
1735 ;; not compare it with the first cell in the
1736 ;; row as there might be a special column.
1737 ;; Instead, compare it with first exportable
1738 ;; cell, obtained with `org-element-map'.
1739 (when (and (memq 'left borders)
1740 (eq (org-element-map table-row 'table-cell
1741 'identity info t)
1742 cell))
1743 lcorner)
1744 (make-string (+ 2 width) (string-to-char horiz))
1745 (cond
1746 ((not (memq 'right borders)) nil)
1747 ((eq (car (last (org-element-contents table-row))) cell)
1748 rcorner)
1749 (t vert)))))
1750 info)) "\n"))))
1751 (utf8p (eq (plist-get info :ascii-charset) 'utf-8))
1752 (borders (org-export-table-cell-borders
1753 (org-element-map table-row 'table-cell 'identity info t)
1754 info)))
1755 (concat (cond
1756 ((and (memq 'top borders) (or utf8p (memq 'above borders)))
1757 (if utf8p (funcall build-hline "┍" "━" "┯" "┑")
1758 (funcall build-hline "+" "-" "+" "+")))
1759 ((memq 'above borders)
1760 (if utf8p (funcall build-hline "├" "─" "┼" "┤")
1761 (funcall build-hline "+" "-" "+" "+"))))
1762 (when (memq 'left borders) (if utf8p "│" "|"))
1763 contents "\n"
1764 (when (and (memq 'bottom borders) (or utf8p (memq 'below borders)))
1765 (if utf8p (funcall build-hline "┕" "━" "┷" "┙")
1766 (funcall build-hline "+" "-" "+" "+")))))))
1769 ;;;; Timestamp
1771 (defun org-ascii-timestamp (timestamp contents info)
1772 "Transcode a TIMESTAMP object from Org to ASCII.
1773 CONTENTS is nil. INFO is a plist holding contextual information."
1774 (org-ascii-plain-text (org-timestamp-translate timestamp) info))
1777 ;;;; Underline
1779 (defun org-ascii-underline (underline contents info)
1780 "Transcode UNDERLINE from Org to ASCII.
1781 CONTENTS is the text with underline markup. INFO is a plist
1782 holding contextual information."
1783 (format "_%s_" contents))
1786 ;;;; Verbatim
1788 (defun org-ascii-verbatim (verbatim contents info)
1789 "Return a VERBATIM object from Org to ASCII.
1790 CONTENTS is nil. INFO is a plist holding contextual information."
1791 (format org-ascii-verbatim-format
1792 (org-element-property :value verbatim)))
1795 ;;;; Verse Block
1797 (defun org-ascii-verse-block (verse-block contents info)
1798 "Transcode a VERSE-BLOCK element from Org to ASCII.
1799 CONTENTS is verse block contents. INFO is a plist holding
1800 contextual information."
1801 (let ((verse-width (org-ascii--current-text-width verse-block info)))
1802 (org-ascii--indent-string
1803 (org-ascii--justify-string contents verse-width 'left)
1804 org-ascii-quote-margin)))
1808 ;;; Filters
1810 (defun org-ascii-filter-headline-blank-lines (headline back-end info)
1811 "Filter controlling number of blank lines after a headline.
1813 HEADLINE is a string representing a transcoded headline.
1814 BACK-END is symbol specifying back-end used for export. INFO is
1815 plist containing the communication channel.
1817 This function only applies to `ascii' back-end. See
1818 `org-ascii-headline-spacing' for information."
1819 (if (not org-ascii-headline-spacing) headline
1820 (let ((blanks (make-string (1+ (cdr org-ascii-headline-spacing)) ?\n)))
1821 (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" blanks headline))))
1823 (defun org-ascii-filter-paragraph-spacing (tree back-end info)
1824 "Filter controlling number of blank lines between paragraphs.
1826 TREE is the parse tree. BACK-END is the symbol specifying
1827 back-end used for export. INFO is a plist used as
1828 a communication channel.
1830 See `org-ascii-paragraph-spacing' for information."
1831 (when (wholenump org-ascii-paragraph-spacing)
1832 (org-element-map tree 'paragraph
1833 (lambda (p)
1834 (when (eq (org-element-type (org-export-get-next-element p info))
1835 'paragraph)
1836 (org-element-put-property
1837 p :post-blank org-ascii-paragraph-spacing)))))
1838 tree)
1840 (defun org-ascii-filter-comment-spacing (tree backend info)
1841 "Filter removing blank lines between comments.
1842 TREE is the parse tree. BACK-END is the symbol specifying
1843 back-end used for export. INFO is a plist used as
1844 a communication channel."
1845 (org-element-map tree '(comment comment-block)
1846 (lambda (c)
1847 (when (memq (org-element-type (org-export-get-next-element c info))
1848 '(comment comment-block))
1849 (org-element-put-property c :post-blank 0))))
1850 tree)
1854 ;;; End-user functions
1856 ;;;###autoload
1857 (defun org-ascii-export-as-ascii
1858 (&optional async subtreep visible-only body-only ext-plist)
1859 "Export current buffer to a text buffer.
1861 If narrowing is active in the current buffer, only export its
1862 narrowed part.
1864 If a region is active, export that region.
1866 A non-nil optional argument ASYNC means the process should happen
1867 asynchronously. The resulting buffer should be accessible
1868 through the `org-export-stack' interface.
1870 When optional argument SUBTREEP is non-nil, export the sub-tree
1871 at point, extracting information from the headline properties
1872 first.
1874 When optional argument VISIBLE-ONLY is non-nil, don't export
1875 contents of hidden elements.
1877 When optional argument BODY-ONLY is non-nil, strip title and
1878 table of contents from output.
1880 EXT-PLIST, when provided, is a property list with external
1881 parameters overriding Org default settings, but still inferior to
1882 file-local settings.
1884 Export is done in a buffer named \"*Org ASCII Export*\", which
1885 will be displayed when `org-export-show-temporary-export-buffer'
1886 is non-nil."
1887 (interactive)
1888 (org-export-to-buffer 'ascii "*Org ASCII Export*"
1889 async subtreep visible-only body-only ext-plist (lambda () (text-mode))))
1891 ;;;###autoload
1892 (defun org-ascii-export-to-ascii
1893 (&optional async subtreep visible-only body-only ext-plist)
1894 "Export current buffer to a text file.
1896 If narrowing is active in the current buffer, only export its
1897 narrowed part.
1899 If a region is active, export that region.
1901 A non-nil optional argument ASYNC means the process should happen
1902 asynchronously. The resulting file should be accessible through
1903 the `org-export-stack' interface.
1905 When optional argument SUBTREEP is non-nil, export the sub-tree
1906 at point, extracting information from the headline properties
1907 first.
1909 When optional argument VISIBLE-ONLY is non-nil, don't export
1910 contents of hidden elements.
1912 When optional argument BODY-ONLY is non-nil, strip title and
1913 table of contents from output.
1915 EXT-PLIST, when provided, is a property list with external
1916 parameters overriding Org default settings, but still inferior to
1917 file-local settings.
1919 Return output file's name."
1920 (interactive)
1921 (let ((file (org-export-output-file-name ".txt" subtreep)))
1922 (org-export-to-file 'ascii file
1923 async subtreep visible-only body-only ext-plist)))
1925 ;;;###autoload
1926 (defun org-ascii-publish-to-ascii (plist filename pub-dir)
1927 "Publish an Org file to ASCII.
1929 FILENAME is the filename of the Org file to be published. PLIST
1930 is the property list for the given project. PUB-DIR is the
1931 publishing directory.
1933 Return output file name."
1934 (org-publish-org-to
1935 'ascii filename ".txt" `(:ascii-charset ascii ,@plist) pub-dir))
1937 ;;;###autoload
1938 (defun org-ascii-publish-to-latin1 (plist filename pub-dir)
1939 "Publish an Org file to Latin-1.
1941 FILENAME is the filename of the Org file to be published. PLIST
1942 is the property list for the given project. PUB-DIR is the
1943 publishing directory.
1945 Return output file name."
1946 (org-publish-org-to
1947 'ascii filename ".txt" `(:ascii-charset latin1 ,@plist) pub-dir))
1949 ;;;###autoload
1950 (defun org-ascii-publish-to-utf8 (plist filename pub-dir)
1951 "Publish an org file to UTF-8.
1953 FILENAME is the filename of the Org file to be published. PLIST
1954 is the property list for the given project. PUB-DIR is the
1955 publishing directory.
1957 Return output file name."
1958 (org-publish-org-to
1959 'ascii filename ".txt" `(:ascii-charset utf-8 ,@plist) pub-dir))
1962 (provide 'ox-ascii)
1964 ;; Local variables:
1965 ;; generated-autoload-file: "org-loaddefs.el"
1966 ;; coding: utf-8-emacs
1967 ;; End:
1969 ;;; ox-ascii.el ends here