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