Move functions operating on timestamp objects into org.el
[org-mode.git] / contrib / lisp / org-e-ascii.el
blob7bfc4c2c94c363ee60fe5fc35c06c3bec5e97ff6
1 ;;; org-e-ascii.el --- ASCII Back-End For Org Export Engine
3 ;; Copyright (C) 2012, 2013 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 (a s v b)
108 (org-e-ascii-export-as-ascii a s v b '(:ascii-charset ascii))))
109 (?a "As ASCII file"
110 (lambda (a s v b)
111 (org-e-ascii-export-to-ascii a s v b '(:ascii-charset ascii))))
112 (?L "As Latin1 buffer"
113 (lambda (a s v b)
114 (org-e-ascii-export-as-ascii a s v b '(:ascii-charset latin1))))
115 (?l "As Latin1 file"
116 (lambda (a s v b)
117 (org-e-ascii-export-to-ascii a s v b '(:ascii-charset latin1))))
118 (?U "As UTF-8 buffer"
119 (lambda (a s v b)
120 (org-e-ascii-export-as-ascii a s v b '(:ascii-charset utf-8))))
121 (?u "As UTF-8 file"
122 (lambda (a s v b)
123 (org-e-ascii-export-to-ascii a 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 three 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 (and (plist-get info :with-date)
823 (org-export-data (plist-get info :date) info))))
824 ;; There are two types of title blocks depending on the presence
825 ;; of a title to display.
826 (if (string= title "")
827 ;; Title block without a title. DATE is positioned at the top
828 ;; right of the document, AUTHOR to the top left and EMAIL
829 ;; just below.
830 (cond
831 ((and (org-string-nw-p date) (org-string-nw-p author))
832 (concat
833 author
834 (make-string (- text-width (length date) (length author)) ? )
835 date
836 (when (org-string-nw-p email) (concat "\n" email))
837 "\n\n\n"))
838 ((and (org-string-nw-p date) (org-string-nw-p email))
839 (concat
840 email
841 (make-string (- text-width (length date) (length email)) ? )
842 date "\n\n\n"))
843 ((org-string-nw-p date)
844 (concat
845 (org-e-ascii--justify-string date text-width 'right)
846 "\n\n\n"))
847 ((and (org-string-nw-p author) (org-string-nw-p email))
848 (concat author "\n" email "\n\n\n"))
849 ((org-string-nw-p author) (concat author "\n\n\n"))
850 ((org-string-nw-p email) (concat email "\n\n\n")))
851 ;; Title block with a title. Document's TITLE, along with the
852 ;; AUTHOR and its EMAIL are both overlined and an underlined,
853 ;; centered. Date is just below, also centered.
854 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8))
855 ;; Format TITLE. It may be filled if it is too wide,
856 ;; that is wider than the two thirds of the total width.
857 (title-len (min (length title) (/ (* 2 text-width) 3)))
858 (formatted-title (org-e-ascii--fill-string title title-len info))
859 (line
860 (make-string
861 (min (+ (max title-len (length author) (length email)) 2)
862 text-width) (if utf8p ?━ ?_))))
863 (org-e-ascii--justify-string
864 (concat line "\n"
865 (unless utf8p "\n")
866 (upcase formatted-title)
867 (cond
868 ((and (org-string-nw-p author) (org-string-nw-p email))
869 (concat (if utf8p "\n\n\n" "\n\n") author "\n" email))
870 ((org-string-nw-p author)
871 (concat (if utf8p "\n\n\n" "\n\n") author))
872 ((org-string-nw-p email)
873 (concat (if utf8p "\n\n\n" "\n\n") email)))
874 "\n" line
875 (when (org-string-nw-p date) (concat "\n\n\n" date))
876 "\n\n\n") text-width 'center)))))
878 (defun org-e-ascii-template (contents info)
879 "Return complete document string after ASCII conversion.
880 CONTENTS is the transcoded contents string. INFO is a plist
881 holding export options."
882 (org-element-normalize-string
883 (org-e-ascii--indent-string
884 (let ((text-width (- org-e-ascii-text-width org-e-ascii-global-margin)))
885 ;; 1. Build title block.
886 (concat
887 (org-e-ascii-template--document-title info)
888 ;; 2. Table of contents.
889 (let ((depth (plist-get info :with-toc)))
890 (when depth
891 (concat
892 (org-e-ascii--build-toc info (and (wholenump depth) depth))
893 "\n\n\n")))
894 ;; 3. Document's body.
895 contents
896 ;; 4. Footnote definitions.
897 (let ((definitions (org-export-collect-footnote-definitions
898 (plist-get info :parse-tree) info))
899 ;; Insert full links right inside the footnote definition
900 ;; as they have no chance to be inserted later.
901 (org-e-ascii-links-to-notes nil))
902 (when definitions
903 (concat
904 "\n\n\n"
905 (let ((title (org-e-ascii--translate "Footnotes" info)))
906 (concat
907 title "\n"
908 (make-string
909 (length title)
910 (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))))
911 "\n\n"
912 (mapconcat
913 (lambda (ref)
914 (let ((id (format "[%s] " (car ref))))
915 ;; Distinguish between inline definitions and
916 ;; full-fledged definitions.
917 (org-trim
918 (let ((def (nth 2 ref)))
919 (if (eq (org-element-type def) 'org-data)
920 ;; Full-fledged definition: footnote ID is
921 ;; inserted inside the first parsed paragraph
922 ;; (FIRST), if any, to be sure filling will
923 ;; take it into consideration.
924 (let ((first (car (org-element-contents def))))
925 (if (not (eq (org-element-type first) 'paragraph))
926 (concat id "\n" (org-export-data def info))
927 (push id (nthcdr 2 first))
928 (org-export-data def info)))
929 ;; Fill paragraph once footnote ID is inserted in
930 ;; order to have a correct length for first line.
931 (org-e-ascii--fill-string
932 (concat id (org-export-data def info))
933 text-width info))))))
934 definitions "\n\n"))))
935 ;; 5. Creator. Ignore `comment' value as there are no comments in
936 ;; ASCII. Justify it to the bottom right.
937 (let ((creator-info (plist-get info :with-creator)))
938 (unless (or (not creator-info) (eq creator-info 'comment))
939 (concat
940 "\n\n\n"
941 (org-e-ascii--fill-string
942 (plist-get info :creator) text-width info 'right))))))
943 org-e-ascii-global-margin)))
945 (defun org-e-ascii--translate (s info)
946 "Translate string S according to specified language and charset.
947 INFO is a plist used as a communication channel."
948 (let ((charset (intern (format ":%s" (plist-get info :ascii-charset)))))
949 (org-export-translate s charset info)))
953 ;;; Transcode Functions
955 ;;;; Bold
957 (defun org-e-ascii-bold (bold contents info)
958 "Transcode BOLD from Org to ASCII.
959 CONTENTS is the text with bold markup. INFO is a plist holding
960 contextual information."
961 (format "*%s*" contents))
964 ;;;; Center Block
966 (defun org-e-ascii-center-block (center-block contents info)
967 "Transcode a CENTER-BLOCK element from Org to ASCII.
968 CONTENTS holds the contents of the block. INFO is a plist
969 holding contextual information."
970 (org-e-ascii--justify-string
971 contents (org-e-ascii--current-text-width center-block info) 'center))
974 ;;;; Clock
976 (defun org-e-ascii-clock (clock contents info)
977 "Transcode a CLOCK object from Org to ASCII.
978 CONTENTS is nil. INFO is a plist holding contextual
979 information."
980 (concat org-clock-string " "
981 (org-translate-time
982 (org-element-property :raw-value
983 (org-element-property :value clock)))
984 (let ((time (org-element-property :duration clock)))
985 (and time
986 (concat " => "
987 (apply 'format
988 "%2s:%02s"
989 (org-split-string time ":")))))))
992 ;;;; Code
994 (defun org-e-ascii-code (code contents info)
995 "Return a CODE object from Org to ASCII.
996 CONTENTS is nil. INFO is a plist holding contextual
997 information."
998 (format org-e-ascii-verbatim-format (org-element-property :value code)))
1001 ;;;; Drawer
1003 (defun org-e-ascii-drawer (drawer contents info)
1004 "Transcode a DRAWER element from Org to ASCII.
1005 CONTENTS holds the contents of the block. INFO is a plist
1006 holding contextual information."
1007 (let ((name (org-element-property :drawer-name drawer))
1008 (width (org-e-ascii--current-text-width drawer info)))
1009 (if (functionp org-e-ascii-format-drawer-function)
1010 (funcall org-e-ascii-format-drawer-function name contents width)
1011 ;; If there's no user defined function: simply
1012 ;; display contents of the drawer.
1013 contents)))
1016 ;;;; Dynamic Block
1018 (defun org-e-ascii-dynamic-block (dynamic-block contents info)
1019 "Transcode a DYNAMIC-BLOCK element from Org to ASCII.
1020 CONTENTS holds the contents of the block. INFO is a plist
1021 holding contextual information."
1022 contents)
1025 ;;;; Entity
1027 (defun org-e-ascii-entity (entity contents info)
1028 "Transcode an ENTITY object from Org to ASCII.
1029 CONTENTS are the definition itself. INFO is a plist holding
1030 contextual information."
1031 (org-element-property
1032 (intern (concat ":" (symbol-name (plist-get info :ascii-charset))))
1033 entity))
1036 ;;;; Example Block
1038 (defun org-e-ascii-example-block (example-block contents info)
1039 "Transcode a EXAMPLE-BLOCK element from Org to ASCII.
1040 CONTENTS is nil. INFO is a plist holding contextual information."
1041 (org-e-ascii--box-string
1042 (org-export-format-code-default example-block info) info))
1045 ;;;; Export Snippet
1047 (defun org-e-ascii-export-snippet (export-snippet contents info)
1048 "Transcode a EXPORT-SNIPPET object from Org to ASCII.
1049 CONTENTS is nil. INFO is a plist holding contextual information."
1050 (when (eq (org-export-snippet-backend export-snippet) 'e-ascii)
1051 (org-element-property :value export-snippet)))
1054 ;;;; Export Block
1056 (defun org-e-ascii-export-block (export-block contents info)
1057 "Transcode a EXPORT-BLOCK element from Org to ASCII.
1058 CONTENTS is nil. INFO is a plist holding contextual information."
1059 (when (string= (org-element-property :type export-block) "ASCII")
1060 (org-remove-indentation (org-element-property :value export-block))))
1063 ;;;; Fixed Width
1065 (defun org-e-ascii-fixed-width (fixed-width contents info)
1066 "Transcode a FIXED-WIDTH element from Org to ASCII.
1067 CONTENTS is nil. INFO is a plist holding contextual information."
1068 (org-e-ascii--box-string
1069 (org-remove-indentation
1070 (org-element-property :value fixed-width)) info))
1073 ;;;; Footnote Definition
1075 ;; Footnote Definitions are ignored. They are compiled at the end of
1076 ;; the document, by `org-e-ascii-template'.
1079 ;;;; Footnote Reference
1081 (defun org-e-ascii-footnote-reference (footnote-reference contents info)
1082 "Transcode a FOOTNOTE-REFERENCE element from Org to ASCII.
1083 CONTENTS is nil. INFO is a plist holding contextual information."
1084 (format "[%s]" (org-export-get-footnote-number footnote-reference info)))
1087 ;;;; Headline
1089 (defun org-e-ascii-headline (headline contents info)
1090 "Transcode an HEADLINE element from Org to ASCII.
1091 CONTENTS holds the contents of the headline. INFO is a plist
1092 holding contextual information."
1093 ;; Don't export footnote section, which will be handled at the end
1094 ;; of the template.
1095 (unless (org-element-property :footnote-section-p headline)
1096 (let* ((low-level-rank (org-export-low-level-p headline info))
1097 (width (org-e-ascii--current-text-width headline info))
1098 ;; Blank lines between headline and its contents.
1099 ;; `org-e-ascii-headline-spacing', when set, overwrites
1100 ;; original buffer's spacing.
1101 (pre-blanks
1102 (make-string
1103 (if org-e-ascii-headline-spacing (car org-e-ascii-headline-spacing)
1104 (org-element-property :pre-blank headline)) ?\n))
1105 ;; Even if HEADLINE has no section, there might be some
1106 ;; links in its title that we shouldn't forget to describe.
1107 (links
1108 (unless (or (eq (caar (org-element-contents headline)) 'section))
1109 (let ((title (org-element-property :title headline)))
1110 (when (consp title)
1111 (org-e-ascii--describe-links
1112 (org-e-ascii--unique-links title info) width info))))))
1113 ;; Deep subtree: export it as a list item.
1114 (if low-level-rank
1115 (concat
1116 ;; Bullet.
1117 (let ((bullets (cdr (assq (plist-get info :ascii-charset)
1118 org-e-ascii-bullets))))
1119 (char-to-string
1120 (nth (mod (1- low-level-rank) (length bullets)) bullets)))
1122 ;; Title.
1123 (org-e-ascii--build-title headline info width) "\n"
1124 ;; Contents, indented by length of bullet.
1125 pre-blanks
1126 (org-e-ascii--indent-string
1127 (concat contents
1128 (when (org-string-nw-p links) (concat "\n\n" links)))
1130 ;; Else: Standard headline.
1131 (concat
1132 (org-e-ascii--build-title headline info width 'underline)
1133 "\n" pre-blanks
1134 (concat (when (org-string-nw-p links) links) contents))))))
1137 ;;;; Horizontal Rule
1139 (defun org-e-ascii-horizontal-rule (horizontal-rule contents info)
1140 "Transcode an HORIZONTAL-RULE object from Org to ASCII.
1141 CONTENTS is nil. INFO is a plist holding contextual
1142 information."
1143 (let ((text-width (org-e-ascii--current-text-width horizontal-rule info))
1144 (spec-width
1145 (org-export-read-attribute :attr_ascii horizontal-rule :width)))
1146 (org-e-ascii--justify-string
1147 (make-string (if (wholenump spec-width) spec-width text-width)
1148 (if (eq (plist-get info :ascii-charset) 'utf-8) ?― ?-))
1149 text-width 'center)))
1152 ;;;; Inline Src Block
1154 (defun org-e-ascii-inline-src-block (inline-src-block contents info)
1155 "Transcode an INLINE-SRC-BLOCK element from Org to ASCII.
1156 CONTENTS holds the contents of the item. INFO is a plist holding
1157 contextual information."
1158 (format org-e-ascii-verbatim-format
1159 (org-element-property :value inline-src-block)))
1162 ;;;; Inlinetask
1164 (defun org-e-ascii-inlinetask (inlinetask contents info)
1165 "Transcode an INLINETASK element from Org to ASCII.
1166 CONTENTS holds the contents of the block. INFO is a plist
1167 holding contextual information."
1168 (let ((width (org-e-ascii--current-text-width inlinetask info)))
1169 ;; If `org-e-ascii-format-inlinetask-function' is provided, call it
1170 ;; with appropriate arguments.
1171 (if (functionp org-e-ascii-format-inlinetask-function)
1172 (funcall org-e-ascii-format-inlinetask-function
1173 ;; todo.
1174 (and (plist-get info :with-todo-keywords)
1175 (let ((todo (org-element-property
1176 :todo-keyword inlinetask)))
1177 (and todo (org-export-data todo info))))
1178 ;; todo-type
1179 (org-element-property :todo-type inlinetask)
1180 ;; priority
1181 (and (plist-get info :with-priority)
1182 (org-element-property :priority inlinetask))
1183 ;; title
1184 (org-export-data (org-element-property :title inlinetask) info)
1185 ;; tags
1186 (and (plist-get info :with-tags)
1187 (org-element-property :tags inlinetask))
1188 ;; contents and width
1189 contents width)
1190 ;; Otherwise, use a default template.
1191 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
1192 (org-e-ascii--indent-string
1193 (concat
1194 ;; Top line, with an additional blank line if not in UTF-8.
1195 (make-string width (if utf8p ?━ ?_)) "\n"
1196 (unless utf8p (concat (make-string width ? ) "\n"))
1197 ;; Add title. Fill it if wider than inlinetask.
1198 (let ((title (org-e-ascii--build-title inlinetask info width)))
1199 (if (<= (length title) width) title
1200 (org-e-ascii--fill-string title width info)))
1201 "\n"
1202 ;; If CONTENTS is not empty, insert it along with
1203 ;; a separator.
1204 (when (org-string-nw-p contents)
1205 (concat (make-string width (if utf8p ?─ ?-)) "\n" contents))
1206 ;; Bottom line.
1207 (make-string width (if utf8p ?━ ?_)))
1208 ;; Flush the inlinetask to the right.
1209 (- org-e-ascii-text-width org-e-ascii-global-margin
1210 (if (not (org-export-get-parent-headline inlinetask)) 0
1211 org-e-ascii-inner-margin)
1212 (org-e-ascii--current-text-width inlinetask info)))))))
1215 ;;;; Italic
1217 (defun org-e-ascii-italic (italic contents info)
1218 "Transcode italic from Org to ASCII.
1219 CONTENTS is the text with italic markup. INFO is a plist holding
1220 contextual information."
1221 (format "/%s/" contents))
1224 ;;;; Item
1226 (defun org-e-ascii-item (item contents info)
1227 "Transcode an ITEM element from Org to ASCII.
1228 CONTENTS holds the contents of the item. INFO is a plist holding
1229 contextual information."
1230 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8))
1231 (checkbox (org-e-ascii--checkbox item info))
1232 (list-type (org-element-property :type (org-export-get-parent item)))
1233 (bullet
1234 ;; First parent of ITEM is always the plain-list. Get
1235 ;; `:type' property from it.
1236 (org-list-bullet-string
1237 (case list-type
1238 (descriptive
1239 (concat checkbox
1240 (org-export-data (org-element-property :tag item) info)
1241 ": "))
1242 (ordered
1243 ;; Return correct number for ITEM, paying attention to
1244 ;; counters.
1245 (let* ((struct (org-element-property :structure item))
1246 (bul (org-element-property :bullet item))
1247 (num (number-to-string
1248 (car (last (org-list-get-item-number
1249 (org-element-property :begin item)
1250 struct
1251 (org-list-prevs-alist struct)
1252 (org-list-parents-alist struct)))))))
1253 (replace-regexp-in-string "[0-9]+" num bul)))
1254 (t (let ((bul (org-element-property :bullet item)))
1255 ;; Change bullets into more visible form if UTF-8 is active.
1256 (if (not utf8p) bul
1257 (replace-regexp-in-string
1258 "-" "•"
1259 (replace-regexp-in-string
1260 "+" "⁃"
1261 (replace-regexp-in-string "*" "‣" bul))))))))))
1262 (concat
1263 bullet
1264 (unless (eq list-type 'descriptive) checkbox)
1265 ;; Contents: Pay attention to indentation. Note: check-boxes are
1266 ;; already taken care of at the paragraph level so they don't
1267 ;; interfere with indentation.
1268 (let ((contents (org-e-ascii--indent-string contents (length bullet))))
1269 (if (eq (org-element-type (car (org-element-contents item))) 'paragraph)
1270 (org-trim contents)
1271 (concat "\n" contents))))))
1274 ;;;; Keyword
1276 (defun org-e-ascii-keyword (keyword contents info)
1277 "Transcode a KEYWORD element from Org to ASCII.
1278 CONTENTS is nil. INFO is a plist holding contextual
1279 information."
1280 (let ((key (org-element-property :key keyword))
1281 (value (org-element-property :value keyword)))
1282 (cond
1283 ((string= key "ASCII") value)
1284 ((string= key "TOC")
1285 (let ((value (downcase value)))
1286 (cond
1287 ((string-match "\\<headlines\\>" value)
1288 (let ((depth (or (and (string-match "[0-9]+" value)
1289 (string-to-number (match-string 0 value)))
1290 (plist-get info :with-toc))))
1291 (org-e-ascii--build-toc
1292 info (and (wholenump depth) depth) keyword)))
1293 ((string= "tables" value)
1294 (org-e-ascii--list-tables keyword info))
1295 ((string= "listings" value)
1296 (org-e-ascii--list-listings keyword info))))))))
1299 ;;;; Latex Environment
1301 (defun org-e-ascii-latex-environment (latex-environment contents info)
1302 "Transcode a LATEX-ENVIRONMENT element from Org to ASCII.
1303 CONTENTS is nil. INFO is a plist holding contextual
1304 information."
1305 (org-remove-indentation (org-element-property :value latex-environment)))
1308 ;;;; Latex Fragment
1310 (defun org-e-ascii-latex-fragment (latex-fragment contents info)
1311 "Transcode a LATEX-FRAGMENT object from Org to ASCII.
1312 CONTENTS is nil. INFO is a plist holding contextual
1313 information."
1314 (org-element-property :value latex-fragment))
1317 ;;;; Line Break
1319 (defun org-e-ascii-line-break (line-break contents info)
1320 "Transcode a LINE-BREAK object from Org to ASCII.
1321 CONTENTS is nil. INFO is a plist holding contextual
1322 information." hard-newline)
1325 ;;;; Link
1327 (defun org-e-ascii-link (link desc info)
1328 "Transcode a LINK object from Org to ASCII.
1330 DESC is the description part of the link, or the empty string.
1331 INFO is a plist holding contextual information."
1332 (let ((raw-link (org-element-property :raw-link link))
1333 (type (org-element-property :type link)))
1334 (cond
1335 ((string= type "coderef")
1336 (let ((ref (org-element-property :path link)))
1337 (format (org-export-get-coderef-format ref desc)
1338 (org-export-resolve-coderef ref info))))
1339 ;; Do not apply a special syntax on radio links. Though, use
1340 ;; transcoded target's contents as output.
1341 ((string= type "radio")
1342 (let ((destination (org-export-resolve-radio-link link info)))
1343 (when destination
1344 (org-export-data (org-element-contents destination) info))))
1345 ;; Do not apply a special syntax on fuzzy links pointing to
1346 ;; targets.
1347 ((string= type "fuzzy")
1348 (let ((destination (org-export-resolve-fuzzy-link link info)))
1349 ;; Ignore invisible "#+TARGET: path".
1350 (unless (eq (org-element-type destination) 'keyword)
1351 (if (org-string-nw-p desc) desc
1352 (when destination
1353 (let ((number
1354 (org-export-get-ordinal
1355 destination info nil 'org-e-ascii--has-caption-p)))
1356 (when number
1357 (if (atom number) (number-to-string number)
1358 (mapconcat 'number-to-string number ".")))))))))
1360 (if (not (org-string-nw-p desc)) (format "[%s]" raw-link)
1361 (concat
1362 (format "[%s]" desc)
1363 (unless org-e-ascii-links-to-notes (format " (%s)" raw-link))))))))
1366 ;;;; Paragraph
1368 (defun org-e-ascii-paragraph (paragraph contents info)
1369 "Transcode a PARAGRAPH element from Org to ASCII.
1370 CONTENTS is the contents of the paragraph, as a string. INFO is
1371 the plist used as a communication channel."
1372 (let ((contents (if (not (wholenump org-e-ascii-indented-line-width)) contents
1373 (concat
1374 (make-string org-e-ascii-indented-line-width ? )
1375 (replace-regexp-in-string "\\`[ \t]+" "" contents)))))
1376 (org-e-ascii--fill-string
1377 contents (org-e-ascii--current-text-width paragraph info) info)))
1380 ;;;; Plain List
1382 (defun org-e-ascii-plain-list (plain-list contents info)
1383 "Transcode a PLAIN-LIST element from Org to ASCII.
1384 CONTENTS is the contents of the list. INFO is a plist holding
1385 contextual information."
1386 contents)
1389 ;;;; Plain Text
1391 (defun org-e-ascii-plain-text (text info)
1392 "Transcode a TEXT string from Org to ASCII.
1393 INFO is a plist used as a communication channel."
1394 (let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
1395 (when (and utf8p (plist-get info :with-smart-quotes))
1396 (setq text (org-export-activate-smart-quotes text :utf-8 info)))
1397 (if (not (plist-get info :with-special-strings)) text
1398 (setq text (replace-regexp-in-string "\\\\-" "" text))
1399 (if (not utf8p) text
1400 ;; Usual replacements in utf-8 with proper option set.
1401 (replace-regexp-in-string
1402 "\\.\\.\\." "…"
1403 (replace-regexp-in-string
1404 "--" "–"
1405 (replace-regexp-in-string "---" "—" text)))))))
1408 ;;;; Planning
1410 (defun org-e-ascii-planning (planning contents info)
1411 "Transcode a PLANNING element from Org to ASCII.
1412 CONTENTS is nil. INFO is a plist used as a communication
1413 channel."
1414 (mapconcat
1415 'identity
1416 (delq nil
1417 (list (let ((closed (org-element-property :closed planning)))
1418 (when closed
1419 (concat org-closed-string " "
1420 (org-translate-time
1421 (org-element-property :raw-value closed)))))
1422 (let ((deadline (org-element-property :deadline planning)))
1423 (when deadline
1424 (concat org-deadline-string " "
1425 (org-translate-time
1426 (org-element-property :raw-value deadline)))))
1427 (let ((scheduled (org-element-property :scheduled planning)))
1428 (when scheduled
1429 (concat org-scheduled-string " "
1430 (org-translate-time
1431 (org-element-property :raw-value scheduled)))))))
1432 " "))
1435 ;;;; Quote Block
1437 (defun org-e-ascii-quote-block (quote-block contents info)
1438 "Transcode a QUOTE-BLOCK element from Org to ASCII.
1439 CONTENTS holds the contents of the block. INFO is a plist
1440 holding contextual information."
1441 (let ((width (org-e-ascii--current-text-width quote-block info)))
1442 (org-e-ascii--indent-string
1443 (org-remove-indentation
1444 (org-e-ascii--fill-string contents width info))
1445 org-e-ascii-quote-margin)))
1448 ;;;; Quote Section
1450 (defun org-e-ascii-quote-section (quote-section contents info)
1451 "Transcode a QUOTE-SECTION element from Org to ASCII.
1452 CONTENTS is nil. INFO is a plist holding contextual information."
1453 (let ((width (org-e-ascii--current-text-width quote-section info))
1454 (value
1455 (org-export-data
1456 (org-remove-indentation (org-element-property :value quote-section))
1457 info)))
1458 (org-e-ascii--indent-string
1459 value
1460 (+ org-e-ascii-quote-margin
1461 ;; Don't apply inner margin if parent headline is low level.
1462 (let ((headline (org-export-get-parent-headline quote-section)))
1463 (if (org-export-low-level-p headline info) 0
1464 org-e-ascii-inner-margin))))))
1467 ;;;; Radio Target
1469 (defun org-e-ascii-radio-target (radio-target contents info)
1470 "Transcode a RADIO-TARGET object from Org to ASCII.
1471 CONTENTS is the contents of the target. INFO is a plist holding
1472 contextual information."
1473 contents)
1476 ;;;; Section
1478 (defun org-e-ascii-section (section contents info)
1479 "Transcode a SECTION element from Org to ASCII.
1480 CONTENTS is the contents of the section. INFO is a plist holding
1481 contextual information."
1482 (org-e-ascii--indent-string
1483 (concat
1484 contents
1485 (when org-e-ascii-links-to-notes
1486 ;; Add list of links at the end of SECTION.
1487 (let ((links (org-e-ascii--describe-links
1488 (org-e-ascii--unique-links section info)
1489 (org-e-ascii--current-text-width section info) info)))
1490 ;; Separate list of links and section contents.
1491 (when (org-string-nw-p links) (concat "\n\n" links)))))
1492 ;; Do not apply inner margin if parent headline is low level.
1493 (let ((headline (org-export-get-parent-headline section)))
1494 (if (or (not headline) (org-export-low-level-p headline info)) 0
1495 org-e-ascii-inner-margin))))
1498 ;;;; Special Block
1500 (defun org-e-ascii-special-block (special-block contents info)
1501 "Transcode a SPECIAL-BLOCK element from Org to ASCII.
1502 CONTENTS holds the contents of the block. INFO is a plist
1503 holding contextual information."
1504 contents)
1507 ;;;; Src Block
1509 (defun org-e-ascii-src-block (src-block contents info)
1510 "Transcode a SRC-BLOCK element from Org to ASCII.
1511 CONTENTS holds the contents of the item. INFO is a plist holding
1512 contextual information."
1513 (let ((caption (org-e-ascii--build-caption src-block info)))
1514 (concat
1515 (when (and caption org-e-ascii-caption-above) (concat caption "\n"))
1516 (org-e-ascii--box-string
1517 (org-export-format-code-default src-block info) info)
1518 (when (and caption (not org-e-ascii-caption-above))
1519 (concat "\n" caption)))))
1522 ;;;; Statistics Cookie
1524 (defun org-e-ascii-statistics-cookie (statistics-cookie contents info)
1525 "Transcode a STATISTICS-COOKIE object from Org to ASCII.
1526 CONTENTS is nil. INFO is a plist holding contextual information."
1527 (org-element-property :value statistics-cookie))
1530 ;;;; Subscript
1532 (defun org-e-ascii-subscript (subscript contents info)
1533 "Transcode a SUBSCRIPT object from Org to ASCII.
1534 CONTENTS is the contents of the object. INFO is a plist holding
1535 contextual information."
1536 (if (org-element-property :use-brackets-p subscript)
1537 (format "_{%s}" contents)
1538 (format "_%s" contents)))
1541 ;;;; Superscript
1543 (defun org-e-ascii-superscript (superscript contents info)
1544 "Transcode a SUPERSCRIPT object from Org to ASCII.
1545 CONTENTS is the contents of the object. INFO is a plist holding
1546 contextual information."
1547 (if (org-element-property :use-brackets-p superscript)
1548 (format "_{%s}" contents)
1549 (format "_%s" contents)))
1552 ;;;; Strike-through
1554 (defun org-e-ascii-strike-through (strike-through contents info)
1555 "Transcode STRIKE-THROUGH from Org to ASCII.
1556 CONTENTS is text with strike-through markup. INFO is a plist
1557 holding contextual information."
1558 (format "+%s+" contents))
1561 ;;;; Table
1563 (defun org-e-ascii-table (table contents info)
1564 "Transcode a TABLE element from Org to ASCII.
1565 CONTENTS is the contents of the table. INFO is a plist holding
1566 contextual information."
1567 (let ((caption (org-e-ascii--build-caption table info)))
1568 (concat
1569 ;; Possibly add a caption string above.
1570 (when (and caption org-e-ascii-caption-above) (concat caption "\n"))
1571 ;; Insert table. Note: "table.el" tables are left unmodified.
1572 (cond ((eq (org-element-property :type table) 'org) contents)
1573 ((and org-e-ascii-table-use-ascii-art
1574 (eq (plist-get info :ascii-charset) 'utf-8)
1575 (require 'ascii-art-to-unicode nil t))
1576 (with-temp-buffer
1577 (insert (org-remove-indentation
1578 (org-element-property :value table)))
1579 (goto-char (point-min))
1580 (aa2u)
1581 (goto-char (point-max))
1582 (skip-chars-backward " \r\t\n")
1583 (buffer-substring (point-min) (point))))
1584 (t (org-remove-indentation (org-element-property :value table))))
1585 ;; Possible add a caption string below.
1586 (when (and caption (not org-e-ascii-caption-above))
1587 (concat "\n" caption)))))
1590 ;;;; Table Cell
1592 (defun org-e-ascii--table-cell-width (table-cell info)
1593 "Return width of TABLE-CELL.
1595 INFO is a plist used as a communication channel.
1597 Width of a cell is determined either by a width cookie in the
1598 same column as the cell, or by the maximum cell's length in that
1599 column.
1601 When `org-e-ascii-table-widen-columns' is non-nil, width cookies
1602 are ignored."
1603 (or (and (not org-e-ascii-table-widen-columns)
1604 (org-export-table-cell-width table-cell info))
1605 (let* ((max-width 0)
1606 (table (org-export-get-parent-table table-cell))
1607 (specialp (org-export-table-has-special-column-p table))
1608 (col (cdr (org-export-table-cell-address table-cell info))))
1609 (org-element-map
1610 table 'table-row
1611 (lambda (row)
1612 (setq max-width
1613 (max (length
1614 (org-export-data
1615 (org-element-contents
1616 (elt (if specialp (cdr (org-element-contents row))
1617 (org-element-contents row))
1618 col))
1619 info))
1620 max-width)))
1621 info)
1622 max-width)))
1624 (defun org-e-ascii-table-cell (table-cell contents info)
1625 "Transcode a TABLE-CELL object from Org to ASCII.
1626 CONTENTS is the cell contents. INFO is a plist used as
1627 a communication channel."
1628 ;; Determine column width. When `org-e-ascii-table-widen-columns'
1629 ;; is nil and some width cookie has set it, use that value.
1630 ;; Otherwise, compute the maximum width among transcoded data of
1631 ;; each cell in the column.
1632 (let ((width (org-e-ascii--table-cell-width table-cell info)))
1633 ;; When contents are too large, truncate them.
1634 (unless (or org-e-ascii-table-widen-columns (<= (length contents) width))
1635 (setq contents (concat (substring contents 0 (- width 2)) "=>")))
1636 ;; Align contents correctly within the cell.
1637 (let* ((indent-tabs-mode nil)
1638 (data
1639 (when contents
1640 (org-e-ascii--justify-string
1641 contents width
1642 (org-export-table-cell-alignment table-cell info)))))
1643 (setq contents (concat data (make-string (- width (length data)) ? ))))
1644 ;; Return cell.
1645 (concat (format " %s " contents)
1646 (when (memq 'right (org-export-table-cell-borders table-cell info))
1647 (if (eq (plist-get info :ascii-charset) 'utf-8) "│" "|")))))
1650 ;;;; Table Row
1652 (defun org-e-ascii-table-row (table-row contents info)
1653 "Transcode a TABLE-ROW element from Org to ASCII.
1654 CONTENTS is the row contents. INFO is a plist used as
1655 a communication channel."
1656 (when (eq (org-element-property :type table-row) 'standard)
1657 (let ((build-hline
1658 (function
1659 (lambda (lcorner horiz vert rcorner)
1660 (concat
1661 (apply
1662 'concat
1663 (org-element-map
1664 table-row 'table-cell
1665 (lambda (cell)
1666 (let ((width (org-e-ascii--table-cell-width cell info))
1667 (borders (org-export-table-cell-borders cell info)))
1668 (concat
1669 ;; In order to know if CELL starts the row, do
1670 ;; not compare it with the first cell in the row
1671 ;; as there might be a special column. Instead,
1672 ;; compare it with the first exportable cell,
1673 ;; obtained with `org-element-map'.
1674 (when (and (memq 'left borders)
1675 (eq (org-element-map
1676 table-row 'table-cell 'identity info t)
1677 cell))
1678 lcorner)
1679 (make-string (+ 2 width) (string-to-char horiz))
1680 (cond
1681 ((not (memq 'right borders)) nil)
1682 ((eq (car (last (org-element-contents table-row))) cell)
1683 rcorner)
1684 (t vert)))))
1685 info)) "\n"))))
1686 (utf8p (eq (plist-get info :ascii-charset) 'utf-8))
1687 (borders (org-export-table-cell-borders
1688 (org-element-map table-row 'table-cell 'identity info t)
1689 info)))
1690 (concat (cond
1691 ((and (memq 'top borders) (or utf8p (memq 'above borders)))
1692 (if utf8p (funcall build-hline "┍" "━" "┯" "┑")
1693 (funcall build-hline "+" "-" "+" "+")))
1694 ((memq 'above borders)
1695 (if utf8p (funcall build-hline "├" "─" "┼" "┤")
1696 (funcall build-hline "+" "-" "+" "+"))))
1697 (when (memq 'left borders) (if utf8p "│" "|"))
1698 contents "\n"
1699 (when (and (memq 'bottom borders) (or utf8p (memq 'below borders)))
1700 (if utf8p (funcall build-hline "┕" "━" "┷" "┙")
1701 (funcall build-hline "+" "-" "+" "+")))))))
1704 ;;;; Timestamp
1706 (defun org-e-ascii-timestamp (timestamp contents info)
1707 "Transcode a TIMESTAMP object from Org to ASCII.
1708 CONTENTS is nil. INFO is a plist holding contextual information."
1709 (org-e-ascii-plain-text (org-timestamp-translate timestamp) info))
1712 ;;;; Underline
1714 (defun org-e-ascii-underline (underline contents info)
1715 "Transcode UNDERLINE from Org to ASCII.
1716 CONTENTS is the text with underline markup. INFO is a plist
1717 holding contextual information."
1718 (format "_%s_" contents))
1721 ;;;; Verbatim
1723 (defun org-e-ascii-verbatim (verbatim contents info)
1724 "Return a VERBATIM object from Org to ASCII.
1725 CONTENTS is nil. INFO is a plist holding contextual information."
1726 (format org-e-ascii-verbatim-format
1727 (org-element-property :value verbatim)))
1730 ;;;; Verse Block
1732 (defun org-e-ascii-verse-block (verse-block contents info)
1733 "Transcode a VERSE-BLOCK element from Org to ASCII.
1734 CONTENTS is verse block contents. INFO is a plist holding
1735 contextual information."
1736 (let ((verse-width (org-e-ascii--current-text-width verse-block info)))
1737 (org-e-ascii--indent-string
1738 (org-e-ascii--justify-string contents verse-width 'left)
1739 org-e-ascii-quote-margin)))
1743 ;;; Filters
1745 (defun org-e-ascii-filter-headline-blank-lines (headline back-end info)
1746 "Filter controlling number of blank lines after an headline.
1748 HEADLINE is a string representing a transcoded headline.
1749 BACK-END is symbol specifying back-end used for export. INFO is
1750 plist containing the communication channel.
1752 This function only applies to `e-ascii' back-end. See
1753 `org-e-ascii-headline-spacing' for information."
1754 (if (not org-e-ascii-headline-spacing) headline
1755 (let ((blanks (make-string (1+ (cdr org-e-ascii-headline-spacing)) ?\n)))
1756 (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" blanks headline))))
1758 (defun org-e-ascii-filter-paragraph-spacing (tree back-end info)
1759 "Filter controlling number of blank lines between paragraphs.
1761 TREE is the parse tree. BACK-END is the symbol specifying
1762 back-end used for export. INFO is a plist used as
1763 a communication channel.
1765 This function only applies to `e-ascii' back-end. See
1766 `org-e-ascii-paragraph-spacing' for information."
1767 (when (wholenump org-e-ascii-paragraph-spacing)
1768 (org-element-map
1769 tree 'paragraph
1770 (lambda (p)
1771 (when (eq (org-element-type (org-export-get-next-element p info))
1772 'paragraph)
1773 (org-element-put-property
1774 p :post-blank org-e-ascii-paragraph-spacing)))))
1775 tree)
1779 ;;; End-user functions
1781 ;;;###autoload
1782 (defun org-e-ascii-export-as-ascii
1783 (&optional async subtreep visible-only body-only ext-plist)
1784 "Export current buffer to a text buffer.
1786 If narrowing is active in the current buffer, only export its
1787 narrowed part.
1789 If a region is active, export that region.
1791 A non-nil optional argument ASYNC means the process should happen
1792 asynchronously. The resulting buffer should be accessible
1793 through the `org-export-stack' interface.
1795 When optional argument SUBTREEP is non-nil, export the sub-tree
1796 at point, extracting information from the headline properties
1797 first.
1799 When optional argument VISIBLE-ONLY is non-nil, don't export
1800 contents of hidden elements.
1802 When optional argument BODY-ONLY is non-nil, strip title, table
1803 of contents and footnote definitions from output.
1805 EXT-PLIST, when provided, is a property list with external
1806 parameters overriding Org default settings, but still inferior to
1807 file-local settings.
1809 Export is done in a buffer named \"*Org E-ASCII Export*\", which
1810 will be displayed when `org-export-show-temporary-export-buffer'
1811 is non-nil."
1812 (interactive)
1813 (if async
1814 (org-export-async-start
1815 (lambda (output)
1816 (with-current-buffer (get-buffer-create "*Org E-ASCII Export*")
1817 (erase-buffer)
1818 (insert output)
1819 (goto-char (point-min))
1820 (text-mode)
1821 (org-export-add-to-stack (current-buffer) 'e-ascii)))
1822 `(org-export-as 'e-ascii ,subtreep ,visible-only ,body-only
1823 ',ext-plist))
1824 (let ((outbuf (org-export-to-buffer
1825 'e-ascii "*Org E-ASCII Export*"
1826 subtreep visible-only body-only ext-plist)))
1827 (with-current-buffer outbuf (text-mode))
1828 (when org-export-show-temporary-export-buffer
1829 (switch-to-buffer-other-window outbuf)))))
1831 ;;;###autoload
1832 (defun org-e-ascii-export-to-ascii
1833 (&optional async subtreep visible-only body-only ext-plist)
1834 "Export current buffer to a text file.
1836 If narrowing is active in the current buffer, only export its
1837 narrowed part.
1839 If a region is active, export that region.
1841 A non-nil optional argument ASYNC means the process should happen
1842 asynchronously. The resulting file should be accessible through
1843 the `org-export-stack' interface.
1845 When optional argument SUBTREEP is non-nil, export the sub-tree
1846 at point, extracting information from the headline properties
1847 first.
1849 When optional argument VISIBLE-ONLY is non-nil, don't export
1850 contents of hidden elements.
1852 When optional argument BODY-ONLY is non-nil, strip title, table
1853 of contents and footnote definitions from output.
1855 EXT-PLIST, when provided, is a property list with external
1856 parameters overriding Org default settings, but still inferior to
1857 file-local settings.
1859 Return output file's name."
1860 (interactive)
1861 (let ((outfile (org-export-output-file-name ".txt" subtreep)))
1862 (if async
1863 (org-export-async-start
1864 (lambda (f) (org-export-add-to-stack f 'e-ascii))
1865 `(expand-file-name
1866 (org-export-to-file
1867 'e-ascii ,outfile ,subtreep ,visible-only ,body-only ',ext-plist)))
1868 (org-export-to-file
1869 'e-ascii outfile subtreep visible-only body-only ext-plist))))
1871 ;;;###autoload
1872 (defun org-e-ascii-publish-to-ascii (plist filename pub-dir)
1873 "Publish an Org file to ASCII.
1875 FILENAME is the filename of the Org file to be published. PLIST
1876 is the property list for the given project. PUB-DIR is the
1877 publishing directory.
1879 Return output file name."
1880 (org-e-publish-org-to
1881 'e-ascii filename ".txt" `(:ascii-charset ascii ,@plist) pub-dir))
1883 ;;;###autoload
1884 (defun org-e-ascii-publish-to-latin1 (plist filename pub-dir)
1885 "Publish an Org file to Latin-1.
1887 FILENAME is the filename of the Org file to be published. PLIST
1888 is the property list for the given project. PUB-DIR is the
1889 publishing directory.
1891 Return output file name."
1892 (org-e-publish-org-to
1893 'e-ascii filename ".txt" `(:ascii-charset latin1 ,@plist) pub-dir))
1895 ;;;###autoload
1896 (defun org-e-ascii-publish-to-utf8 (plist filename pub-dir)
1897 "Publish an org file to UTF-8.
1899 FILENAME is the filename of the Org file to be published. PLIST
1900 is the property list for the given project. PUB-DIR is the
1901 publishing directory.
1903 Return output file name."
1904 (org-e-publish-org-to
1905 'e-ascii filename ".txt" `(:ascii-charset utf-8 ,@plist) pub-dir))
1908 (provide 'org-e-ascii)
1909 ;;; org-e-ascii.el ends here