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