Graphic: Catch errors and return error message
[org-mode.git] / lisp / ox-ascii.el
blob5247156fee5366b2db0575e59e25872adec8bf2e
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 (quote-section . org-ascii-quote-section)
82 (radio-target . org-ascii-radio-target)
83 (section . org-ascii-section)
84 (special-block . org-ascii-special-block)
85 (src-block . org-ascii-src-block)
86 (statistics-cookie . org-ascii-statistics-cookie)
87 (strike-through . org-ascii-strike-through)
88 (subscript . org-ascii-subscript)
89 (superscript . org-ascii-superscript)
90 (table . org-ascii-table)
91 (table-cell . org-ascii-table-cell)
92 (table-row . org-ascii-table-row)
93 (target . org-ascii-target)
94 (template . org-ascii-template)
95 (timestamp . org-ascii-timestamp)
96 (underline . org-ascii-underline)
97 (verbatim . org-ascii-verbatim)
98 (verse-block . org-ascii-verse-block))
99 :export-block "ASCII"
100 :menu-entry
101 '(?t "Export to Plain Text"
102 ((?A "As ASCII buffer"
103 (lambda (a s v b)
104 (org-ascii-export-as-ascii a s v b '(:ascii-charset ascii))))
105 (?a "As ASCII file"
106 (lambda (a s v b)
107 (org-ascii-export-to-ascii a s v b '(:ascii-charset ascii))))
108 (?L "As Latin1 buffer"
109 (lambda (a s v b)
110 (org-ascii-export-as-ascii a s v b '(:ascii-charset latin1))))
111 (?l "As Latin1 file"
112 (lambda (a s v b)
113 (org-ascii-export-to-ascii a s v b '(:ascii-charset latin1))))
114 (?U "As UTF-8 buffer"
115 (lambda (a s v b)
116 (org-ascii-export-as-ascii a s v b '(:ascii-charset utf-8))))
117 (?u "As UTF-8 file"
118 (lambda (a s v b)
119 (org-ascii-export-to-ascii a s v b '(:ascii-charset utf-8))))))
120 :filters-alist '((:filter-headline . org-ascii-filter-headline-blank-lines)
121 (:filter-parse-tree org-ascii-filter-paragraph-spacing
122 org-ascii-filter-comment-spacing)
123 (:filter-section . org-ascii-filter-headline-blank-lines))
124 :options-alist '((:ascii-charset nil nil org-ascii-charset)))
128 ;;; User Configurable Variables
130 (defgroup org-export-ascii nil
131 "Options for exporting Org mode files to ASCII."
132 :tag "Org Export ASCII"
133 :group 'org-export)
135 (defcustom org-ascii-text-width 72
136 "Maximum width of exported text.
137 This number includes margin size, as set in
138 `org-ascii-global-margin'."
139 :group 'org-export-ascii
140 :version "24.4"
141 :package-version '(Org . "8.0")
142 :type 'integer)
144 (defcustom org-ascii-global-margin 0
145 "Width of the left margin, in number of characters."
146 :group 'org-export-ascii
147 :version "24.4"
148 :package-version '(Org . "8.0")
149 :type 'integer)
151 (defcustom org-ascii-inner-margin 2
152 "Width of the inner margin, in number of characters.
153 Inner margin is applied between each headline."
154 :group 'org-export-ascii
155 :version "24.4"
156 :package-version '(Org . "8.0")
157 :type 'integer)
159 (defcustom org-ascii-quote-margin 6
160 "Width of margin used for quoting text, in characters.
161 This margin is applied on both sides of the text."
162 :group 'org-export-ascii
163 :version "24.4"
164 :package-version '(Org . "8.0")
165 :type 'integer)
167 (defcustom org-ascii-inlinetask-width 30
168 "Width of inline tasks, in number of characters.
169 This number ignores any margin."
170 :group 'org-export-ascii
171 :version "24.4"
172 :package-version '(Org . "8.0")
173 :type 'integer)
175 (defcustom org-ascii-headline-spacing '(1 . 2)
176 "Number of blank lines inserted around headlines.
178 This variable can be set to a cons cell. In that case, its car
179 represents the number of blank lines present before headline
180 contents whereas its cdr reflects the number of blank lines after
181 contents.
183 A nil value replicates the number of blank lines found in the
184 original Org buffer at the same place."
185 :group 'org-export-ascii
186 :version "24.4"
187 :package-version '(Org . "8.0")
188 :type '(choice
189 (const :tag "Replicate original spacing" nil)
190 (cons :tag "Set an uniform spacing"
191 (integer :tag "Number of blank lines before contents")
192 (integer :tag "Number of blank lines after contents"))))
194 (defcustom org-ascii-indented-line-width 'auto
195 "Additional indentation width for the first line in a paragraph.
196 If the value is an integer, indent the first line of each
197 paragraph by this number. If it is the symbol `auto' preserve
198 indentation from original 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 "\\(^\\)\\(?:.*\\S-\\)" (make-string width ? ) 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.
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 (cons (org-element-property :raw-link link)
766 (org-element-contents link))))
767 ;; Ignore LINK if it hasn't been translated already.
768 ;; It can happen if it is located in an affiliated
769 ;; keyword that was ignored.
770 (when (and (org-string-nw-p
771 (gethash link (plist-get info :exported-data)))
772 (not (member footprint seen)))
773 (push footprint seen) link)))))
774 ;; If at a section, find parent headline, if any, in order to
775 ;; count links that might be in the title.
776 (headline
777 (if (eq (org-element-type element) 'headline) element
778 (or (org-export-get-parent-headline element) element))))
779 ;; Get all links in HEADLINE.
780 (org-element-map headline 'link
781 (lambda (l) (funcall unique-link-p l)) info nil nil t)))
783 (defun org-ascii--describe-links (links width info)
784 "Return a string describing a list of links.
786 LINKS is a list of link type objects, as returned by
787 `org-ascii--unique-links'. WIDTH is the text width allowed for
788 the output string. INFO is a plist used as a communication
789 channel."
790 (mapconcat
791 (lambda (link)
792 (let ((type (org-element-property :type link))
793 (anchor (let ((desc (org-element-contents link)))
794 (if desc (org-export-data desc info)
795 (org-element-property :raw-link link)))))
796 (cond
797 ;; Coderefs, radio links and fuzzy links are ignored.
798 ((member type '("coderef" "radio" "fuzzy")) nil)
799 ;; Id and custom-id links: Headlines refer to their numbering.
800 ((member type '("custom-id" "id"))
801 (let ((dest (org-export-resolve-id-link link info)))
802 (concat
803 (org-ascii--fill-string
804 (format
805 "[%s] %s"
806 anchor
807 (if (not dest) (org-ascii--translate "Unknown reference" info)
808 (format
809 (org-ascii--translate "See section %s" info)
810 (mapconcat 'number-to-string
811 (org-export-get-headline-number dest info) "."))))
812 width info) "\n\n")))
813 ;; Do not add a link that cannot be resolved and doesn't have
814 ;; any description: destination is already visible in the
815 ;; paragraph.
816 ((not (org-element-contents link)) nil)
818 (concat
819 (org-ascii--fill-string
820 (format "[%s] %s" anchor (org-element-property :raw-link link))
821 width info)
822 "\n\n")))))
823 links ""))
825 (defun org-ascii--checkbox (item info)
826 "Return checkbox string for ITEM or nil.
827 INFO is a plist used as a communication channel."
828 (let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
829 (case (org-element-property :checkbox item)
830 (on (if utf8p "☑ " "[X] "))
831 (off (if utf8p "☐ " "[ ] "))
832 (trans (if utf8p "☒ " "[-] ")))))
836 ;;; Template
838 (defun org-ascii-template--document-title (info)
839 "Return document title, as a string.
840 INFO is a plist used as a communication channel."
841 (let* ((text-width org-ascii-text-width)
842 ;; Links in the title will not be resolved later, so we make
843 ;; sure their path is located right after them.
844 (org-ascii-links-to-notes nil)
845 (title (org-export-data (plist-get info :title) info))
846 (author (and (plist-get info :with-author)
847 (let ((auth (plist-get info :author)))
848 (and auth (org-export-data auth info)))))
849 (email (and (plist-get info :with-email)
850 (org-export-data (plist-get info :email) info)))
851 (date (and (plist-get info :with-date)
852 (org-export-data (org-export-get-date info) info))))
853 ;; There are two types of title blocks depending on the presence
854 ;; of a title to display.
855 (if (string= title "")
856 ;; Title block without a title. DATE is positioned at the top
857 ;; right of the document, AUTHOR to the top left and EMAIL
858 ;; just below.
859 (cond
860 ((and (org-string-nw-p date) (org-string-nw-p author))
861 (concat
862 author
863 (make-string (- text-width (string-width date) (string-width author))
864 ?\s)
865 date
866 (when (org-string-nw-p email) (concat "\n" email))
867 "\n\n\n"))
868 ((and (org-string-nw-p date) (org-string-nw-p email))
869 (concat
870 email
871 (make-string (- text-width (string-width date) (string-width email))
872 ?\s)
873 date "\n\n\n"))
874 ((org-string-nw-p date)
875 (concat
876 (org-ascii--justify-string date text-width 'right)
877 "\n\n\n"))
878 ((and (org-string-nw-p author) (org-string-nw-p email))
879 (concat author "\n" email "\n\n\n"))
880 ((org-string-nw-p author) (concat author "\n\n\n"))
881 ((org-string-nw-p email) (concat email "\n\n\n")))
882 ;; Title block with a title. Document's TITLE, along with the
883 ;; AUTHOR and its EMAIL are both overlined and an underlined,
884 ;; centered. Date is just below, also centered.
885 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8))
886 ;; Format TITLE. It may be filled if it is too wide,
887 ;; that is wider than the two thirds of the total width.
888 (title-len (min (length title) (/ (* 2 text-width) 3)))
889 (formatted-title (org-ascii--fill-string title title-len info))
890 (line
891 (make-string
892 (min (+ (max title-len
893 (string-width (or author ""))
894 (string-width (or email "")))
896 text-width) (if utf8p ?━ ?_))))
897 (org-ascii--justify-string
898 (concat line "\n"
899 (unless utf8p "\n")
900 (upcase formatted-title)
901 (cond
902 ((and (org-string-nw-p author) (org-string-nw-p email))
903 (concat (if utf8p "\n\n\n" "\n\n") author "\n" email))
904 ((org-string-nw-p author)
905 (concat (if utf8p "\n\n\n" "\n\n") author))
906 ((org-string-nw-p email)
907 (concat (if utf8p "\n\n\n" "\n\n") email)))
908 "\n" line
909 (when (org-string-nw-p date) (concat "\n\n\n" date))
910 "\n\n\n") text-width 'center)))))
912 (defun org-ascii-inner-template (contents info)
913 "Return complete document string after ASCII conversion.
914 CONTENTS is the transcoded contents string. INFO is a plist
915 holding export options."
916 (org-element-normalize-string
917 (org-ascii--indent-string
918 (concat
919 ;; 1. Document's body.
920 contents
921 ;; 2. Footnote definitions.
922 (let ((definitions (org-export-collect-footnote-definitions
923 (plist-get info :parse-tree) info))
924 ;; Insert full links right inside the footnote definition
925 ;; as they have no chance to be inserted later.
926 (org-ascii-links-to-notes nil))
927 (when definitions
928 (concat
929 "\n\n\n"
930 (let ((title (org-ascii--translate "Footnotes" info)))
931 (concat
932 title "\n"
933 (make-string
934 (string-width title)
935 (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))))
936 "\n\n"
937 (let ((text-width (- org-ascii-text-width org-ascii-global-margin)))
938 (mapconcat
939 (lambda (ref)
940 (let ((id (format "[%s] " (car ref))))
941 ;; Distinguish between inline definitions and
942 ;; full-fledged definitions.
943 (org-trim
944 (let ((def (nth 2 ref)))
945 (if (eq (org-element-type def) 'org-data)
946 ;; Full-fledged definition: footnote ID is
947 ;; inserted inside the first parsed paragraph
948 ;; (FIRST), if any, to be sure filling will
949 ;; take it into consideration.
950 (let ((first (car (org-element-contents def))))
951 (if (not (eq (org-element-type first) 'paragraph))
952 (concat id "\n" (org-export-data def info))
953 (push id (nthcdr 2 first))
954 (org-export-data def info)))
955 ;; Fill paragraph once footnote ID is inserted
956 ;; in order to have a correct length for first
957 ;; line.
958 (org-ascii--fill-string
959 (concat id (org-export-data def info))
960 text-width info))))))
961 definitions "\n\n"))))))
962 org-ascii-global-margin)))
964 (defun org-ascii-template (contents info)
965 "Return complete document string after ASCII conversion.
966 CONTENTS is the transcoded contents string. INFO is a plist
967 holding export options."
968 (concat
969 ;; 1. Build title block.
970 (org-ascii--indent-string
971 (concat (org-ascii-template--document-title info)
972 ;; 2. Table of contents.
973 (let ((depth (plist-get info :with-toc)))
974 (when depth
975 (concat
976 (org-ascii--build-toc info (and (wholenump depth) depth))
977 "\n\n\n"))))
978 org-ascii-global-margin)
979 ;; 3. Document's body.
980 contents
981 ;; 4. Creator. Ignore `comment' value as there are no comments in
982 ;; ASCII. Justify it to the bottom right.
983 (org-ascii--indent-string
984 (let ((creator-info (plist-get info :with-creator))
985 (text-width (- org-ascii-text-width org-ascii-global-margin)))
986 (unless (or (not creator-info) (eq creator-info 'comment))
987 (concat
988 "\n\n\n"
989 (org-ascii--fill-string
990 (plist-get info :creator) text-width info 'right))))
991 org-ascii-global-margin)))
993 (defun org-ascii--translate (s info)
994 "Translate string S according to specified language and charset.
995 INFO is a plist used as a communication channel."
996 (let ((charset (intern (format ":%s" (plist-get info :ascii-charset)))))
997 (org-export-translate s charset info)))
1001 ;;; Transcode Functions
1003 ;;;; Bold
1005 (defun org-ascii-bold (bold contents info)
1006 "Transcode BOLD from Org to ASCII.
1007 CONTENTS is the text with bold markup. INFO is a plist holding
1008 contextual information."
1009 (format "*%s*" contents))
1012 ;;;; Center Block
1014 (defun org-ascii-center-block (center-block contents info)
1015 "Transcode a CENTER-BLOCK element from Org to ASCII.
1016 CONTENTS holds the contents of the block. INFO is a plist
1017 holding contextual information."
1018 (org-ascii--justify-string
1019 contents (org-ascii--current-text-width center-block info) 'center))
1022 ;;;; Clock
1024 (defun org-ascii-clock (clock contents info)
1025 "Transcode a CLOCK object from Org to ASCII.
1026 CONTENTS is nil. INFO is a plist holding contextual
1027 information."
1028 (concat org-clock-string " "
1029 (org-translate-time
1030 (org-element-property :raw-value
1031 (org-element-property :value clock)))
1032 (let ((time (org-element-property :duration clock)))
1033 (and time
1034 (concat " => "
1035 (apply 'format
1036 "%2s:%02s"
1037 (org-split-string time ":")))))))
1040 ;;;; Code
1042 (defun org-ascii-code (code contents info)
1043 "Return a CODE object from Org to ASCII.
1044 CONTENTS is nil. INFO is a plist holding contextual
1045 information."
1046 (format org-ascii-verbatim-format (org-element-property :value code)))
1049 ;;;; Drawer
1051 (defun org-ascii-drawer (drawer contents info)
1052 "Transcode a DRAWER element from Org to ASCII.
1053 CONTENTS holds the contents of the block. INFO is a plist
1054 holding contextual information."
1055 (let ((name (org-element-property :drawer-name drawer))
1056 (width (org-ascii--current-text-width drawer info)))
1057 (funcall org-ascii-format-drawer-function name contents width)))
1060 ;;;; Dynamic Block
1062 (defun org-ascii-dynamic-block (dynamic-block contents info)
1063 "Transcode a DYNAMIC-BLOCK element from Org to ASCII.
1064 CONTENTS holds the contents of the block. INFO is a plist
1065 holding contextual information."
1066 contents)
1069 ;;;; Entity
1071 (defun org-ascii-entity (entity contents info)
1072 "Transcode an ENTITY object from Org to ASCII.
1073 CONTENTS are the definition itself. INFO is a plist holding
1074 contextual information."
1075 (org-element-property
1076 (intern (concat ":" (symbol-name (plist-get info :ascii-charset))))
1077 entity))
1080 ;;;; Example Block
1082 (defun org-ascii-example-block (example-block contents info)
1083 "Transcode a EXAMPLE-BLOCK element from Org to ASCII.
1084 CONTENTS is nil. INFO is a plist holding contextual information."
1085 (org-ascii--box-string
1086 (org-export-format-code-default example-block info) info))
1089 ;;;; Export Snippet
1091 (defun org-ascii-export-snippet (export-snippet contents info)
1092 "Transcode a EXPORT-SNIPPET object from Org to ASCII.
1093 CONTENTS is nil. INFO is a plist holding contextual information."
1094 (when (eq (org-export-snippet-backend export-snippet) 'ascii)
1095 (org-element-property :value export-snippet)))
1098 ;;;; Export Block
1100 (defun org-ascii-export-block (export-block contents info)
1101 "Transcode a EXPORT-BLOCK element from Org to ASCII.
1102 CONTENTS is nil. INFO is a plist holding contextual information."
1103 (when (string= (org-element-property :type export-block) "ASCII")
1104 (org-remove-indentation (org-element-property :value export-block))))
1107 ;;;; Fixed Width
1109 (defun org-ascii-fixed-width (fixed-width contents info)
1110 "Transcode a FIXED-WIDTH element from Org to ASCII.
1111 CONTENTS is nil. INFO is a plist holding contextual information."
1112 (org-ascii--box-string
1113 (org-remove-indentation
1114 (org-element-property :value fixed-width)) info))
1117 ;;;; Footnote Definition
1119 ;; Footnote Definitions are ignored. They are compiled at the end of
1120 ;; the document, by `org-ascii-inner-template'.
1123 ;;;; Footnote Reference
1125 (defun org-ascii-footnote-reference (footnote-reference contents info)
1126 "Transcode a FOOTNOTE-REFERENCE element from Org to ASCII.
1127 CONTENTS is nil. INFO is a plist holding contextual information."
1128 (format "[%s]" (org-export-get-footnote-number footnote-reference info)))
1131 ;;;; Headline
1133 (defun org-ascii-headline (headline contents info)
1134 "Transcode a HEADLINE element from Org to ASCII.
1135 CONTENTS holds the contents of the headline. INFO is a plist
1136 holding contextual information."
1137 ;; Don't export footnote section, which will be handled at the end
1138 ;; of the template.
1139 (unless (org-element-property :footnote-section-p headline)
1140 (let* ((low-level-rank (org-export-low-level-p headline info))
1141 (width (org-ascii--current-text-width headline info))
1142 ;; Blank lines between headline and its contents.
1143 ;; `org-ascii-headline-spacing', when set, overwrites
1144 ;; original buffer's spacing.
1145 (pre-blanks
1146 (make-string
1147 (if org-ascii-headline-spacing (car org-ascii-headline-spacing)
1148 (org-element-property :pre-blank headline)) ?\n))
1149 ;; Even if HEADLINE has no section, there might be some
1150 ;; links in its title that we shouldn't forget to describe.
1151 (links
1152 (unless (or (eq (caar (org-element-contents headline)) 'section))
1153 (let ((title (org-element-property :title headline)))
1154 (when (consp title)
1155 (org-ascii--describe-links
1156 (org-ascii--unique-links title info) width info))))))
1157 ;; Deep subtree: export it as a list item.
1158 (if low-level-rank
1159 (concat
1160 ;; Bullet.
1161 (let ((bullets (cdr (assq (plist-get info :ascii-charset)
1162 org-ascii-bullets))))
1163 (char-to-string
1164 (nth (mod (1- low-level-rank) (length bullets)) bullets)))
1166 ;; Title.
1167 (org-ascii--build-title headline info width) "\n"
1168 ;; Contents, indented by length of bullet.
1169 pre-blanks
1170 (org-ascii--indent-string
1171 (concat contents
1172 (when (org-string-nw-p links) (concat "\n\n" links)))
1174 ;; Else: Standard headline.
1175 (concat
1176 (org-ascii--build-title headline info width 'underline)
1177 "\n" pre-blanks
1178 (concat (when (org-string-nw-p links) links) contents))))))
1181 ;;;; Horizontal Rule
1183 (defun org-ascii-horizontal-rule (horizontal-rule contents info)
1184 "Transcode an HORIZONTAL-RULE object from Org to ASCII.
1185 CONTENTS is nil. INFO is a plist holding contextual
1186 information."
1187 (let ((text-width (org-ascii--current-text-width horizontal-rule info))
1188 (spec-width
1189 (org-export-read-attribute :attr_ascii horizontal-rule :width)))
1190 (org-ascii--justify-string
1191 (make-string (if (and spec-width (string-match "^[0-9]+$" spec-width))
1192 (string-to-number spec-width)
1193 text-width)
1194 (if (eq (plist-get info :ascii-charset) 'utf-8) ?― ?-))
1195 text-width 'center)))
1198 ;;;; Inline Src Block
1200 (defun org-ascii-inline-src-block (inline-src-block contents info)
1201 "Transcode an INLINE-SRC-BLOCK element from Org to ASCII.
1202 CONTENTS holds the contents of the item. INFO is a plist holding
1203 contextual information."
1204 (format org-ascii-verbatim-format
1205 (org-element-property :value inline-src-block)))
1208 ;;;; Inlinetask
1210 (defun org-ascii-format-inlinetask-default
1211 (todo type priority name tags contents width inlinetask info)
1212 "Format an inline task element for ASCII export.
1213 See `org-ascii-format-inlinetask-function' for a description
1214 of the parameters."
1215 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8))
1216 (width (or width org-ascii-inlinetask-width)))
1217 (org-ascii--indent-string
1218 (concat
1219 ;; Top line, with an additional blank line if not in UTF-8.
1220 (make-string width (if utf8p ?━ ?_)) "\n"
1221 (unless utf8p (concat (make-string width ? ) "\n"))
1222 ;; Add title. Fill it if wider than inlinetask.
1223 (let ((title (org-ascii--build-title inlinetask info width)))
1224 (if (<= (string-width title) width) title
1225 (org-ascii--fill-string title width info)))
1226 "\n"
1227 ;; If CONTENTS is not empty, insert it along with
1228 ;; a separator.
1229 (when (org-string-nw-p contents)
1230 (concat (make-string width (if utf8p ?─ ?-)) "\n" contents))
1231 ;; Bottom line.
1232 (make-string width (if utf8p ?━ ?_)))
1233 ;; Flush the inlinetask to the right.
1234 (- org-ascii-text-width org-ascii-global-margin
1235 (if (not (org-export-get-parent-headline inlinetask)) 0
1236 org-ascii-inner-margin)
1237 (org-ascii--current-text-width inlinetask info)))))
1239 (defun org-ascii-inlinetask (inlinetask contents info)
1240 "Transcode an INLINETASK element from Org to ASCII.
1241 CONTENTS holds the contents of the block. INFO is a plist
1242 holding contextual information."
1243 (let ((width (org-ascii--current-text-width inlinetask info)))
1244 (funcall org-ascii-format-inlinetask-function
1245 ;; todo.
1246 (and (plist-get info :with-todo-keywords)
1247 (let ((todo (org-element-property
1248 :todo-keyword inlinetask)))
1249 (and todo (org-export-data todo info))))
1250 ;; todo-type
1251 (org-element-property :todo-type inlinetask)
1252 ;; priority
1253 (and (plist-get info :with-priority)
1254 (org-element-property :priority inlinetask))
1255 ;; title
1256 (org-export-data (org-element-property :title inlinetask) info)
1257 ;; tags
1258 (and (plist-get info :with-tags)
1259 (org-element-property :tags inlinetask))
1260 ;; contents and width
1261 contents width inlinetask info)))
1264 ;;;; Italic
1266 (defun org-ascii-italic (italic contents info)
1267 "Transcode italic from Org to ASCII.
1268 CONTENTS is the text with italic markup. INFO is a plist holding
1269 contextual information."
1270 (format "/%s/" contents))
1273 ;;;; Item
1275 (defun org-ascii-item (item contents info)
1276 "Transcode an ITEM element from Org to ASCII.
1277 CONTENTS holds the contents of the item. INFO is a plist holding
1278 contextual information."
1279 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8))
1280 (checkbox (org-ascii--checkbox item info))
1281 (list-type (org-element-property :type (org-export-get-parent item)))
1282 (bullet
1283 ;; First parent of ITEM is always the plain-list. Get
1284 ;; `:type' property from it.
1285 (org-list-bullet-string
1286 (case list-type
1287 (descriptive
1288 (concat checkbox
1289 (org-export-data (org-element-property :tag item) info)
1290 ": "))
1291 (ordered
1292 ;; Return correct number for ITEM, paying attention to
1293 ;; counters.
1294 (let* ((struct (org-element-property :structure item))
1295 (bul (org-element-property :bullet item))
1296 (num (number-to-string
1297 (car (last (org-list-get-item-number
1298 (org-element-property :begin item)
1299 struct
1300 (org-list-prevs-alist struct)
1301 (org-list-parents-alist struct)))))))
1302 (replace-regexp-in-string "[0-9]+" num bul)))
1303 (t (let ((bul (org-element-property :bullet item)))
1304 ;; Change bullets into more visible form if UTF-8 is active.
1305 (if (not utf8p) bul
1306 (replace-regexp-in-string
1307 "-" "•"
1308 (replace-regexp-in-string
1309 "+" "⁃"
1310 (replace-regexp-in-string "*" "‣" bul))))))))))
1311 (concat
1312 bullet
1313 (unless (eq list-type 'descriptive) checkbox)
1314 ;; Contents: Pay attention to indentation. Note: check-boxes are
1315 ;; already taken care of at the paragraph level so they don't
1316 ;; interfere with indentation.
1317 (let ((contents (org-ascii--indent-string contents (string-width bullet))))
1318 (if (eq (org-element-type (car (org-element-contents item))) 'paragraph)
1319 (org-trim contents)
1320 (concat "\n" contents))))))
1323 ;;;; Keyword
1325 (defun org-ascii-keyword (keyword contents info)
1326 "Transcode a KEYWORD element from Org to ASCII.
1327 CONTENTS is nil. INFO is a plist holding contextual
1328 information."
1329 (let ((key (org-element-property :key keyword))
1330 (value (org-element-property :value keyword)))
1331 (cond
1332 ((string= key "ASCII") value)
1333 ((string= key "TOC")
1334 (let ((value (downcase value)))
1335 (cond
1336 ((string-match "\\<headlines\\>" value)
1337 (let ((depth (or (and (string-match "[0-9]+" value)
1338 (string-to-number (match-string 0 value)))
1339 (plist-get info :with-toc))))
1340 (org-ascii--build-toc
1341 info (and (wholenump depth) depth) keyword)))
1342 ((string= "tables" value)
1343 (org-ascii--list-tables keyword info))
1344 ((string= "listings" value)
1345 (org-ascii--list-listings keyword info))))))))
1348 ;;;; Latex Environment
1350 (defun org-ascii-latex-environment (latex-environment contents info)
1351 "Transcode a LATEX-ENVIRONMENT element from Org to ASCII.
1352 CONTENTS is nil. INFO is a plist holding contextual
1353 information."
1354 (when (plist-get info :with-latex)
1355 (org-remove-indentation (org-element-property :value latex-environment))))
1358 ;;;; Latex Fragment
1360 (defun org-ascii-latex-fragment (latex-fragment contents info)
1361 "Transcode a LATEX-FRAGMENT object from Org to ASCII.
1362 CONTENTS is nil. INFO is a plist holding contextual
1363 information."
1364 (when (plist-get info :with-latex)
1365 (org-element-property :value latex-fragment)))
1368 ;;;; Line Break
1370 (defun org-ascii-line-break (line-break contents info)
1371 "Transcode a LINE-BREAK object from Org to ASCII.
1372 CONTENTS is nil. INFO is a plist holding contextual
1373 information." hard-newline)
1376 ;;;; Link
1378 (defun org-ascii-link (link desc info)
1379 "Transcode a LINK object from Org to ASCII.
1381 DESC is the description part of the link, or the empty string.
1382 INFO is a plist holding contextual information."
1383 (let ((raw-link (org-element-property :raw-link link))
1384 (type (org-element-property :type link)))
1385 (cond
1386 ((string= type "coderef")
1387 (let ((ref (org-element-property :path link)))
1388 (format (org-export-get-coderef-format ref desc)
1389 (org-export-resolve-coderef ref info))))
1390 ;; Do not apply a special syntax on radio links. Though, use
1391 ;; transcoded target's contents as output.
1392 ((string= type "radio")
1393 (let ((destination (org-export-resolve-radio-link link info)))
1394 (when destination
1395 (org-export-data (org-element-contents destination) info))))
1396 ;; Do not apply a special syntax on fuzzy links pointing to
1397 ;; targets.
1398 ((string= type "fuzzy")
1399 (let ((destination (org-export-resolve-fuzzy-link link info)))
1400 (if (org-string-nw-p desc) desc
1401 (when destination
1402 (let ((number
1403 (org-export-get-ordinal
1404 destination info nil 'org-ascii--has-caption-p)))
1405 (when number
1406 (if (atom number) (number-to-string number)
1407 (mapconcat 'number-to-string number "."))))))))
1409 (if (not (org-string-nw-p desc)) (format "[%s]" raw-link)
1410 (concat
1411 (format "[%s]" desc)
1412 (unless org-ascii-links-to-notes (format " (%s)" raw-link))))))))
1415 ;;;; Node Properties
1417 (defun org-ascii-node-property (node-property contents info)
1418 "Transcode a NODE-PROPERTY element from Org to ASCII.
1419 CONTENTS is nil. INFO is a plist holding contextual
1420 information."
1421 (format "%s:%s"
1422 (org-element-property :key node-property)
1423 (let ((value (org-element-property :value node-property)))
1424 (if value (concat " " value) ""))))
1427 ;;;; Paragraph
1429 (defun org-ascii-paragraph (paragraph contents info)
1430 "Transcode a PARAGRAPH element from Org to ASCII.
1431 CONTENTS is the contents of the paragraph, as a string. INFO is
1432 the plist used as a communication channel."
1433 (let ((contents (if (not (wholenump org-ascii-indented-line-width)) contents
1434 (concat
1435 (make-string org-ascii-indented-line-width ? )
1436 (replace-regexp-in-string "\\`[ \t]+" "" contents)))))
1437 (org-ascii--fill-string
1438 contents (org-ascii--current-text-width paragraph info) info)))
1441 ;;;; Plain List
1443 (defun org-ascii-plain-list (plain-list contents info)
1444 "Transcode a PLAIN-LIST element from Org to ASCII.
1445 CONTENTS is the contents of the list. INFO is a plist holding
1446 contextual information."
1447 contents)
1450 ;;;; Plain Text
1452 (defun org-ascii-plain-text (text info)
1453 "Transcode a TEXT string from Org to ASCII.
1454 INFO is a plist used as a communication channel."
1455 (let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
1456 (when (and utf8p (plist-get info :with-smart-quotes))
1457 (setq text (org-export-activate-smart-quotes text :utf-8 info)))
1458 (if (not (plist-get info :with-special-strings)) text
1459 (setq text (replace-regexp-in-string "\\\\-" "" text))
1460 (if (not utf8p) text
1461 ;; Usual replacements in utf-8 with proper option set.
1462 (replace-regexp-in-string
1463 "\\.\\.\\." "…"
1464 (replace-regexp-in-string
1465 "--" "–"
1466 (replace-regexp-in-string "---" "—" text)))))))
1469 ;;;; Planning
1471 (defun org-ascii-planning (planning contents info)
1472 "Transcode a PLANNING element from Org to ASCII.
1473 CONTENTS is nil. INFO is a plist used as a communication
1474 channel."
1475 (mapconcat
1476 'identity
1477 (delq nil
1478 (list (let ((closed (org-element-property :closed planning)))
1479 (when closed
1480 (concat org-closed-string " "
1481 (org-translate-time
1482 (org-element-property :raw-value closed)))))
1483 (let ((deadline (org-element-property :deadline planning)))
1484 (when deadline
1485 (concat org-deadline-string " "
1486 (org-translate-time
1487 (org-element-property :raw-value deadline)))))
1488 (let ((scheduled (org-element-property :scheduled planning)))
1489 (when scheduled
1490 (concat org-scheduled-string " "
1491 (org-translate-time
1492 (org-element-property :raw-value scheduled)))))))
1493 " "))
1496 ;;;; Property Drawer
1498 (defun org-ascii-property-drawer (property-drawer contents info)
1499 "Transcode a PROPERTY-DRAWER element from Org to ASCII.
1500 CONTENTS holds the contents of the drawer. INFO is a plist
1501 holding contextual information."
1502 (org-string-nw-p contents))
1505 ;;;; Quote Block
1507 (defun org-ascii-quote-block (quote-block contents info)
1508 "Transcode a QUOTE-BLOCK element from Org to ASCII.
1509 CONTENTS holds the contents of the block. INFO is a plist
1510 holding contextual information."
1511 (org-ascii--indent-string contents org-ascii-quote-margin))
1514 ;;;; Quote Section
1516 (defun org-ascii-quote-section (quote-section contents info)
1517 "Transcode a QUOTE-SECTION element from Org to ASCII.
1518 CONTENTS is nil. INFO is a plist holding contextual information."
1519 (let ((width (org-ascii--current-text-width quote-section info))
1520 (value
1521 (org-export-data
1522 (org-remove-indentation (org-element-property :value quote-section))
1523 info)))
1524 (org-ascii--indent-string
1525 value
1526 (+ org-ascii-quote-margin
1527 ;; Don't apply inner margin if parent headline is low level.
1528 (let ((headline (org-export-get-parent-headline quote-section)))
1529 (if (org-export-low-level-p headline info) 0
1530 org-ascii-inner-margin))))))
1533 ;;;; Radio Target
1535 (defun org-ascii-radio-target (radio-target contents info)
1536 "Transcode a RADIO-TARGET object from Org to ASCII.
1537 CONTENTS is the contents of the target. INFO is a plist holding
1538 contextual information."
1539 contents)
1542 ;;;; Section
1544 (defun org-ascii-section (section contents info)
1545 "Transcode a SECTION element from Org to ASCII.
1546 CONTENTS is the contents of the section. INFO is a plist holding
1547 contextual information."
1548 (org-ascii--indent-string
1549 (concat
1550 contents
1551 (when org-ascii-links-to-notes
1552 ;; Add list of links at the end of SECTION.
1553 (let ((links (org-ascii--describe-links
1554 (org-ascii--unique-links section info)
1555 (org-ascii--current-text-width section info) info)))
1556 ;; Separate list of links and section contents.
1557 (when (org-string-nw-p links) (concat "\n\n" links)))))
1558 ;; Do not apply inner margin if parent headline is low level.
1559 (let ((headline (org-export-get-parent-headline section)))
1560 (if (or (not headline) (org-export-low-level-p headline info)) 0
1561 org-ascii-inner-margin))))
1564 ;;;; Special Block
1566 (defun org-ascii-special-block (special-block contents info)
1567 "Transcode a SPECIAL-BLOCK element from Org to ASCII.
1568 CONTENTS holds the contents of the block. INFO is a plist
1569 holding contextual information."
1570 contents)
1573 ;;;; Src Block
1575 (defun org-ascii-src-block (src-block contents info)
1576 "Transcode a SRC-BLOCK element from Org to ASCII.
1577 CONTENTS holds the contents of the item. INFO is a plist holding
1578 contextual information."
1579 (let ((caption (org-ascii--build-caption src-block info))
1580 (code (org-export-format-code-default src-block info)))
1581 (if (equal code "") ""
1582 (concat
1583 (when (and caption org-ascii-caption-above) (concat caption "\n"))
1584 (org-ascii--box-string code info)
1585 (when (and caption (not org-ascii-caption-above))
1586 (concat "\n" caption))))))
1589 ;;;; Statistics Cookie
1591 (defun org-ascii-statistics-cookie (statistics-cookie contents info)
1592 "Transcode a STATISTICS-COOKIE object from Org to ASCII.
1593 CONTENTS is nil. INFO is a plist holding contextual information."
1594 (org-element-property :value statistics-cookie))
1597 ;;;; Subscript
1599 (defun org-ascii-subscript (subscript contents info)
1600 "Transcode a SUBSCRIPT object from Org to ASCII.
1601 CONTENTS is the contents of the object. INFO is a plist holding
1602 contextual information."
1603 (if (org-element-property :use-brackets-p subscript)
1604 (format "_{%s}" contents)
1605 (format "_%s" contents)))
1608 ;;;; Superscript
1610 (defun org-ascii-superscript (superscript contents info)
1611 "Transcode a SUPERSCRIPT object from Org to ASCII.
1612 CONTENTS is the contents of the object. INFO is a plist holding
1613 contextual information."
1614 (if (org-element-property :use-brackets-p superscript)
1615 (format "_{%s}" contents)
1616 (format "_%s" contents)))
1619 ;;;; Strike-through
1621 (defun org-ascii-strike-through (strike-through contents info)
1622 "Transcode STRIKE-THROUGH from Org to ASCII.
1623 CONTENTS is text with strike-through markup. INFO is a plist
1624 holding contextual information."
1625 (format "+%s+" contents))
1628 ;;;; Table
1630 (defun org-ascii-table (table contents info)
1631 "Transcode a TABLE element from Org to ASCII.
1632 CONTENTS is the contents of the table. INFO is a plist holding
1633 contextual information."
1634 (let ((caption (org-ascii--build-caption table info)))
1635 (concat
1636 ;; Possibly add a caption string above.
1637 (when (and caption org-ascii-caption-above) (concat caption "\n"))
1638 ;; Insert table. Note: "table.el" tables are left unmodified.
1639 (cond ((eq (org-element-property :type table) 'org) contents)
1640 ((and org-ascii-table-use-ascii-art
1641 (eq (plist-get info :ascii-charset) 'utf-8)
1642 (require 'ascii-art-to-unicode nil t))
1643 (with-temp-buffer
1644 (insert (org-remove-indentation
1645 (org-element-property :value table)))
1646 (goto-char (point-min))
1647 (aa2u)
1648 (goto-char (point-max))
1649 (skip-chars-backward " \r\t\n")
1650 (buffer-substring (point-min) (point))))
1651 (t (org-remove-indentation (org-element-property :value table))))
1652 ;; Possible add a caption string below.
1653 (and (not org-ascii-caption-above) caption))))
1656 ;;;; Table Cell
1658 (defun org-ascii--table-cell-width (table-cell info)
1659 "Return width of TABLE-CELL.
1661 INFO is a plist used as a communication channel.
1663 Width of a cell is determined either by a width cookie in the
1664 same column as the cell, or by the maximum cell's length in that
1665 column.
1667 When `org-ascii-table-widen-columns' is non-nil, width cookies
1668 are ignored."
1669 (let* ((row (org-export-get-parent table-cell))
1670 (table (org-export-get-parent row))
1671 (col (let ((cells (org-element-contents row)))
1672 (- (length cells) (length (memq table-cell cells)))))
1673 (cache
1674 (or (plist-get info :ascii-table-cell-width-cache)
1675 (plist-get (setq info
1676 (plist-put info :ascii-table-cell-width-cache
1677 (make-hash-table :test 'equal)))
1678 :ascii-table-cell-width-cache)))
1679 (key (cons table col)))
1680 (or (gethash key cache)
1681 (puthash
1683 (or (and (not org-ascii-table-widen-columns)
1684 (org-export-table-cell-width table-cell info))
1685 (let* ((max-width 0))
1686 (org-element-map table 'table-row
1687 (lambda (row)
1688 (setq max-width
1689 (max (string-width
1690 (org-export-data
1691 (org-element-contents
1692 (elt (org-element-contents row) col))
1693 info))
1694 max-width)))
1695 info)
1696 max-width))
1697 cache))))
1699 (defun org-ascii-table-cell (table-cell contents info)
1700 "Transcode a TABLE-CELL object from Org to ASCII.
1701 CONTENTS is the cell contents. INFO is a plist used as
1702 a communication channel."
1703 ;; Determine column width. When `org-ascii-table-widen-columns'
1704 ;; is nil and some width cookie has set it, use that value.
1705 ;; Otherwise, compute the maximum width among transcoded data of
1706 ;; each cell in the column.
1707 (let ((width (org-ascii--table-cell-width table-cell info)))
1708 ;; When contents are too large, truncate them.
1709 (unless (or org-ascii-table-widen-columns
1710 (<= (string-width (or contents "")) width))
1711 (setq contents (concat (substring contents 0 (- width 2)) "=>")))
1712 ;; Align contents correctly within the cell.
1713 (let* ((indent-tabs-mode nil)
1714 (data
1715 (when contents
1716 (org-ascii--justify-string
1717 contents width
1718 (org-export-table-cell-alignment table-cell info)))))
1719 (setq contents
1720 (concat data
1721 (make-string (- width (string-width (or data ""))) ?\s))))
1722 ;; Return cell.
1723 (concat (format " %s " contents)
1724 (when (memq 'right (org-export-table-cell-borders table-cell info))
1725 (if (eq (plist-get info :ascii-charset) 'utf-8) "│" "|")))))
1728 ;;;; Table Row
1730 (defun org-ascii-table-row (table-row contents info)
1731 "Transcode a TABLE-ROW element from Org to ASCII.
1732 CONTENTS is the row contents. INFO is a plist used as
1733 a communication channel."
1734 (when (eq (org-element-property :type table-row) 'standard)
1735 (let ((build-hline
1736 (function
1737 (lambda (lcorner horiz vert rcorner)
1738 (concat
1739 (apply
1740 'concat
1741 (org-element-map table-row 'table-cell
1742 (lambda (cell)
1743 (let ((width (org-ascii--table-cell-width cell info))
1744 (borders (org-export-table-cell-borders cell info)))
1745 (concat
1746 ;; In order to know if CELL starts the row, do
1747 ;; not compare it with the first cell in the
1748 ;; row as there might be a special column.
1749 ;; Instead, compare it with first exportable
1750 ;; cell, obtained with `org-element-map'.
1751 (when (and (memq 'left borders)
1752 (eq (org-element-map table-row 'table-cell
1753 'identity info t)
1754 cell))
1755 lcorner)
1756 (make-string (+ 2 width) (string-to-char horiz))
1757 (cond
1758 ((not (memq 'right borders)) nil)
1759 ((eq (car (last (org-element-contents table-row))) cell)
1760 rcorner)
1761 (t vert)))))
1762 info)) "\n"))))
1763 (utf8p (eq (plist-get info :ascii-charset) 'utf-8))
1764 (borders (org-export-table-cell-borders
1765 (org-element-map table-row 'table-cell 'identity info t)
1766 info)))
1767 (concat (cond
1768 ((and (memq 'top borders) (or utf8p (memq 'above borders)))
1769 (if utf8p (funcall build-hline "┍" "━" "┯" "┑")
1770 (funcall build-hline "+" "-" "+" "+")))
1771 ((memq 'above borders)
1772 (if utf8p (funcall build-hline "├" "─" "┼" "┤")
1773 (funcall build-hline "+" "-" "+" "+"))))
1774 (when (memq 'left borders) (if utf8p "│" "|"))
1775 contents "\n"
1776 (when (and (memq 'bottom borders) (or utf8p (memq 'below borders)))
1777 (if utf8p (funcall build-hline "┕" "━" "┷" "┙")
1778 (funcall build-hline "+" "-" "+" "+")))))))
1781 ;;;; Timestamp
1783 (defun org-ascii-timestamp (timestamp contents info)
1784 "Transcode a TIMESTAMP object from Org to ASCII.
1785 CONTENTS is nil. INFO is a plist holding contextual information."
1786 (org-ascii-plain-text (org-timestamp-translate timestamp) info))
1789 ;;;; Underline
1791 (defun org-ascii-underline (underline contents info)
1792 "Transcode UNDERLINE from Org to ASCII.
1793 CONTENTS is the text with underline markup. INFO is a plist
1794 holding contextual information."
1795 (format "_%s_" contents))
1798 ;;;; Verbatim
1800 (defun org-ascii-verbatim (verbatim contents info)
1801 "Return a VERBATIM object from Org to ASCII.
1802 CONTENTS is nil. INFO is a plist holding contextual information."
1803 (format org-ascii-verbatim-format
1804 (org-element-property :value verbatim)))
1807 ;;;; Verse Block
1809 (defun org-ascii-verse-block (verse-block contents info)
1810 "Transcode a VERSE-BLOCK element from Org to ASCII.
1811 CONTENTS is verse block contents. INFO is a plist holding
1812 contextual information."
1813 (let ((verse-width (org-ascii--current-text-width verse-block info)))
1814 (org-ascii--indent-string
1815 (org-ascii--justify-string contents verse-width 'left)
1816 org-ascii-quote-margin)))
1820 ;;; Filters
1822 (defun org-ascii-filter-headline-blank-lines (headline back-end info)
1823 "Filter controlling number of blank lines after a headline.
1825 HEADLINE is a string representing a transcoded headline.
1826 BACK-END is symbol specifying back-end used for export. INFO is
1827 plist containing the communication channel.
1829 This function only applies to `ascii' back-end. See
1830 `org-ascii-headline-spacing' for information."
1831 (if (not org-ascii-headline-spacing) headline
1832 (let ((blanks (make-string (1+ (cdr org-ascii-headline-spacing)) ?\n)))
1833 (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" blanks headline))))
1835 (defun org-ascii-filter-paragraph-spacing (tree back-end info)
1836 "Filter controlling number of blank lines between paragraphs.
1838 TREE is the parse tree. BACK-END is the symbol specifying
1839 back-end used for export. INFO is a plist used as
1840 a communication channel.
1842 See `org-ascii-paragraph-spacing' for information."
1843 (when (wholenump org-ascii-paragraph-spacing)
1844 (org-element-map tree 'paragraph
1845 (lambda (p)
1846 (when (eq (org-element-type (org-export-get-next-element p info))
1847 'paragraph)
1848 (org-element-put-property
1849 p :post-blank org-ascii-paragraph-spacing)))))
1850 tree)
1852 (defun org-ascii-filter-comment-spacing (tree backend info)
1853 "Filter removing blank lines between comments.
1854 TREE is the parse tree. BACK-END is the symbol specifying
1855 back-end used for export. INFO is a plist used as
1856 a communication channel."
1857 (org-element-map tree '(comment comment-block)
1858 (lambda (c)
1859 (when (memq (org-element-type (org-export-get-next-element c info))
1860 '(comment comment-block))
1861 (org-element-put-property c :post-blank 0))))
1862 tree)
1866 ;;; End-user functions
1868 ;;;###autoload
1869 (defun org-ascii-export-as-ascii
1870 (&optional async subtreep visible-only body-only ext-plist)
1871 "Export current buffer to a text buffer.
1873 If narrowing is active in the current buffer, only export its
1874 narrowed part.
1876 If a region is active, export that region.
1878 A non-nil optional argument ASYNC means the process should happen
1879 asynchronously. The resulting buffer should be accessible
1880 through the `org-export-stack' interface.
1882 When optional argument SUBTREEP is non-nil, export the sub-tree
1883 at point, extracting information from the headline properties
1884 first.
1886 When optional argument VISIBLE-ONLY is non-nil, don't export
1887 contents of hidden elements.
1889 When optional argument BODY-ONLY is non-nil, strip title and
1890 table of contents from output.
1892 EXT-PLIST, when provided, is a property list with external
1893 parameters overriding Org default settings, but still inferior to
1894 file-local settings.
1896 Export is done in a buffer named \"*Org ASCII Export*\", which
1897 will be displayed when `org-export-show-temporary-export-buffer'
1898 is non-nil."
1899 (interactive)
1900 (org-export-to-buffer 'ascii "*Org ASCII Export*"
1901 async subtreep visible-only body-only ext-plist (lambda () (text-mode))))
1903 ;;;###autoload
1904 (defun org-ascii-export-to-ascii
1905 (&optional async subtreep visible-only body-only ext-plist)
1906 "Export current buffer to a text file.
1908 If narrowing is active in the current buffer, only export its
1909 narrowed part.
1911 If a region is active, export that region.
1913 A non-nil optional argument ASYNC means the process should happen
1914 asynchronously. The resulting file should be accessible through
1915 the `org-export-stack' interface.
1917 When optional argument SUBTREEP is non-nil, export the sub-tree
1918 at point, extracting information from the headline properties
1919 first.
1921 When optional argument VISIBLE-ONLY is non-nil, don't export
1922 contents of hidden elements.
1924 When optional argument BODY-ONLY is non-nil, strip title and
1925 table of contents from output.
1927 EXT-PLIST, when provided, is a property list with external
1928 parameters overriding Org default settings, but still inferior to
1929 file-local settings.
1931 Return output file's name."
1932 (interactive)
1933 (let ((file (org-export-output-file-name ".txt" subtreep)))
1934 (org-export-to-file 'ascii file
1935 async subtreep visible-only body-only ext-plist)))
1937 ;;;###autoload
1938 (defun org-ascii-publish-to-ascii (plist filename pub-dir)
1939 "Publish an Org file to ASCII.
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 ascii ,@plist) pub-dir))
1949 ;;;###autoload
1950 (defun org-ascii-publish-to-latin1 (plist filename pub-dir)
1951 "Publish an Org file to Latin-1.
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 latin1 ,@plist) pub-dir))
1961 ;;;###autoload
1962 (defun org-ascii-publish-to-utf8 (plist filename pub-dir)
1963 "Publish an org file to UTF-8.
1965 FILENAME is the filename of the Org file to be published. PLIST
1966 is the property list for the given project. PUB-DIR is the
1967 publishing directory.
1969 Return output file name."
1970 (org-publish-org-to
1971 'ascii filename ".txt" `(:ascii-charset utf-8 ,@plist) pub-dir))
1974 (provide 'ox-ascii)
1976 ;; Local variables:
1977 ;; generated-autoload-file: "org-loaddefs.el"
1978 ;; coding: utf-8-emacs
1979 ;; End:
1981 ;;; ox-ascii.el ends here