org-element: Return nil for unspecified time values
[org-mode.git] / contrib / lisp / org-e-ascii.el
blob1d9619f49ba31cde39e8f101996fa25fab31df74
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 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 ;;;; Babel Call
957 ;; Babel Calls are ignored.
960 ;;;; Bold
962 (defun org-e-ascii-bold (bold contents info)
963 "Transcode BOLD from Org to ASCII.
964 CONTENTS is the text with bold markup. INFO is a plist holding
965 contextual information."
966 (format "*%s*" contents))
969 ;;;; Center Block
971 (defun org-e-ascii-center-block (center-block contents info)
972 "Transcode a CENTER-BLOCK element from Org to ASCII.
973 CONTENTS holds the contents of the block. INFO is a plist
974 holding contextual information."
975 (org-e-ascii--justify-string
976 contents (org-e-ascii--current-text-width center-block info) 'center))
979 ;;;; Clock
981 (defun org-e-ascii-clock (clock contents info)
982 "Transcode a CLOCK object from Org to ASCII.
983 CONTENTS is nil. INFO is a plist holding contextual
984 information."
985 (concat org-clock-string " "
986 (org-translate-time
987 (org-element-property :raw-value
988 (org-element-property :value clock)))
989 (let ((time (org-element-property :duration clock)))
990 (and time
991 (concat " => "
992 (apply 'format
993 "%2s:%02s"
994 (org-split-string time ":")))))))
997 ;;;; Code
999 (defun org-e-ascii-code (code contents info)
1000 "Return a CODE object from Org to ASCII.
1001 CONTENTS is nil. INFO is a plist holding contextual
1002 information."
1003 (format org-e-ascii-verbatim-format (org-element-property :value code)))
1006 ;;;; Comment
1008 ;; Comments are ignored.
1011 ;;;; Comment Block
1013 ;; Comment Blocks are ignored.
1016 ;;;; Drawer
1018 (defun org-e-ascii-drawer (drawer contents info)
1019 "Transcode a DRAWER element from Org to ASCII.
1020 CONTENTS holds the contents of the block. INFO is a plist
1021 holding contextual information."
1022 (let ((name (org-element-property :drawer-name drawer))
1023 (width (org-e-ascii--current-text-width drawer info)))
1024 (if (functionp org-e-ascii-format-drawer-function)
1025 (funcall org-e-ascii-format-drawer-function name contents width)
1026 ;; If there's no user defined function: simply
1027 ;; display contents of the drawer.
1028 contents)))
1031 ;;;; Dynamic Block
1033 (defun org-e-ascii-dynamic-block (dynamic-block contents info)
1034 "Transcode a DYNAMIC-BLOCK element from Org to ASCII.
1035 CONTENTS holds the contents of the block. INFO is a plist
1036 holding contextual information."
1037 contents)
1040 ;;;; Entity
1042 (defun org-e-ascii-entity (entity contents info)
1043 "Transcode an ENTITY object from Org to ASCII.
1044 CONTENTS are the definition itself. INFO is a plist holding
1045 contextual information."
1046 (org-element-property
1047 (intern (concat ":" (symbol-name (plist-get info :ascii-charset))))
1048 entity))
1051 ;;;; Example Block
1053 (defun org-e-ascii-example-block (example-block contents info)
1054 "Transcode a EXAMPLE-BLOCK element from Org to ASCII.
1055 CONTENTS is nil. INFO is a plist holding contextual information."
1056 (org-e-ascii--box-string
1057 (org-export-format-code-default example-block info) info))
1060 ;;;; Export Snippet
1062 (defun org-e-ascii-export-snippet (export-snippet contents info)
1063 "Transcode a EXPORT-SNIPPET object from Org to ASCII.
1064 CONTENTS is nil. INFO is a plist holding contextual information."
1065 (when (eq (org-export-snippet-backend export-snippet) 'e-ascii)
1066 (org-element-property :value export-snippet)))
1069 ;;;; Export Block
1071 (defun org-e-ascii-export-block (export-block contents info)
1072 "Transcode a EXPORT-BLOCK element from Org to ASCII.
1073 CONTENTS is nil. INFO is a plist holding contextual information."
1074 (when (string= (org-element-property :type export-block) "ASCII")
1075 (org-remove-indentation (org-element-property :value export-block))))
1078 ;;;; Fixed Width
1080 (defun org-e-ascii-fixed-width (fixed-width contents info)
1081 "Transcode a FIXED-WIDTH element from Org to ASCII.
1082 CONTENTS is nil. INFO is a plist holding contextual information."
1083 (org-e-ascii--box-string
1084 (org-remove-indentation
1085 (org-element-property :value fixed-width)) info))
1088 ;;;; Footnote Definition
1090 ;; Footnote Definitions are ignored. They are compiled at the end of
1091 ;; the document, by `org-e-ascii-template'.
1094 ;;;; Footnote Reference
1096 (defun org-e-ascii-footnote-reference (footnote-reference contents info)
1097 "Transcode a FOOTNOTE-REFERENCE element from Org to ASCII.
1098 CONTENTS is nil. INFO is a plist holding contextual information."
1099 (format "[%s]" (org-export-get-footnote-number footnote-reference info)))
1102 ;;;; Headline
1104 (defun org-e-ascii-headline (headline contents info)
1105 "Transcode an HEADLINE element from Org to ASCII.
1106 CONTENTS holds the contents of the headline. INFO is a plist
1107 holding contextual information."
1108 ;; Don't export footnote section, which will be handled at the end
1109 ;; of the template.
1110 (unless (org-element-property :footnote-section-p headline)
1111 (let* ((low-level-rank (org-export-low-level-p headline info))
1112 (width (org-e-ascii--current-text-width headline info))
1113 ;; Blank lines between headline and its contents.
1114 ;; `org-e-ascii-headline-spacing', when set, overwrites
1115 ;; original buffer's spacing.
1116 (pre-blanks
1117 (make-string
1118 (if org-e-ascii-headline-spacing (car org-e-ascii-headline-spacing)
1119 (org-element-property :pre-blank headline)) ?\n))
1120 ;; Even if HEADLINE has no section, there might be some
1121 ;; links in its title that we shouldn't forget to describe.
1122 (links
1123 (unless (or (eq (caar (org-element-contents headline)) 'section))
1124 (let ((title (org-element-property :title headline)))
1125 (when (consp title)
1126 (org-e-ascii--describe-links
1127 (org-e-ascii--unique-links title info) width info))))))
1128 ;; Deep subtree: export it as a list item.
1129 (if low-level-rank
1130 (concat
1131 ;; Bullet.
1132 (let ((bullets (cdr (assq (plist-get info :ascii-charset)
1133 org-e-ascii-bullets))))
1134 (char-to-string
1135 (nth (mod (1- low-level-rank) (length bullets)) bullets)))
1137 ;; Title.
1138 (org-e-ascii--build-title headline info width) "\n"
1139 ;; Contents, indented by length of bullet.
1140 pre-blanks
1141 (org-e-ascii--indent-string
1142 (concat contents
1143 (when (org-string-nw-p links) (concat "\n\n" links)))
1145 ;; Else: Standard headline.
1146 (concat
1147 (org-e-ascii--build-title headline info width 'underline)
1148 "\n" pre-blanks
1149 (concat (when (org-string-nw-p links) links) contents))))))
1152 ;;;; Horizontal Rule
1154 (defun org-e-ascii-horizontal-rule (horizontal-rule contents info)
1155 "Transcode an HORIZONTAL-RULE object from Org to ASCII.
1156 CONTENTS is nil. INFO is a plist holding contextual
1157 information."
1158 (let ((text-width (org-e-ascii--current-text-width horizontal-rule info))
1159 (spec-width
1160 (org-export-read-attribute :attr_ascii horizontal-rule :width)))
1161 (org-e-ascii--justify-string
1162 (make-string (if (wholenump spec-width) spec-width text-width)
1163 (if (eq (plist-get info :ascii-charset) 'utf-8) ?― ?-))
1164 text-width 'center)))
1167 ;;;; Inline Babel Call
1169 ;; Inline Babel Calls are ignored.
1172 ;;;; Inline Src Block
1174 (defun org-e-ascii-inline-src-block (inline-src-block contents info)
1175 "Transcode an INLINE-SRC-BLOCK element from Org to ASCII.
1176 CONTENTS holds the contents of the item. INFO is a plist holding
1177 contextual information."
1178 (format org-e-ascii-verbatim-format
1179 (org-element-property :value inline-src-block)))
1182 ;;;; Inlinetask
1184 (defun org-e-ascii-inlinetask (inlinetask contents info)
1185 "Transcode an INLINETASK element from Org to ASCII.
1186 CONTENTS holds the contents of the block. INFO is a plist
1187 holding contextual information."
1188 (let ((width (org-e-ascii--current-text-width inlinetask info)))
1189 ;; If `org-e-ascii-format-inlinetask-function' is provided, call it
1190 ;; with appropriate arguments.
1191 (if (functionp org-e-ascii-format-inlinetask-function)
1192 (funcall org-e-ascii-format-inlinetask-function
1193 ;; todo.
1194 (and (plist-get info :with-todo-keywords)
1195 (let ((todo (org-element-property
1196 :todo-keyword inlinetask)))
1197 (and todo (org-export-data todo info))))
1198 ;; todo-type
1199 (org-element-property :todo-type inlinetask)
1200 ;; priority
1201 (and (plist-get info :with-priority)
1202 (org-element-property :priority inlinetask))
1203 ;; title
1204 (org-export-data (org-element-property :title inlinetask) info)
1205 ;; tags
1206 (and (plist-get info :with-tags)
1207 (org-element-property :tags inlinetask))
1208 ;; contents and width
1209 contents width)
1210 ;; Otherwise, use a default template.
1211 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
1212 (org-e-ascii--indent-string
1213 (concat
1214 ;; Top line, with an additional blank line if not in UTF-8.
1215 (make-string width (if utf8p ?━ ?_)) "\n"
1216 (unless utf8p (concat (make-string width ? ) "\n"))
1217 ;; Add title. Fill it if wider than inlinetask.
1218 (let ((title (org-e-ascii--build-title inlinetask info width)))
1219 (if (<= (length title) width) title
1220 (org-e-ascii--fill-string title width info)))
1221 "\n"
1222 ;; If CONTENTS is not empty, insert it along with
1223 ;; a separator.
1224 (when (org-string-nw-p contents)
1225 (concat (make-string width (if utf8p ?─ ?-)) "\n" contents))
1226 ;; Bottom line.
1227 (make-string width (if utf8p ?━ ?_)))
1228 ;; Flush the inlinetask to the right.
1229 (- org-e-ascii-text-width org-e-ascii-global-margin
1230 (if (not (org-export-get-parent-headline inlinetask)) 0
1231 org-e-ascii-inner-margin)
1232 (org-e-ascii--current-text-width inlinetask info)))))))
1234 ;;;; Italic
1236 (defun org-e-ascii-italic (italic contents info)
1237 "Transcode italic from Org to ASCII.
1238 CONTENTS is the text with italic markup. INFO is a plist holding
1239 contextual information."
1240 (format "/%s/" contents))
1243 ;;;; Item
1245 (defun org-e-ascii-item (item contents info)
1246 "Transcode an ITEM element from Org to ASCII.
1247 CONTENTS holds the contents of the item. INFO is a plist holding
1248 contextual information."
1249 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8))
1250 (checkbox (org-e-ascii--checkbox item info))
1251 (list-type (org-element-property :type (org-export-get-parent item)))
1252 (bullet
1253 ;; First parent of ITEM is always the plain-list. Get
1254 ;; `:type' property from it.
1255 (org-list-bullet-string
1256 (case list-type
1257 (descriptive
1258 (concat checkbox
1259 (org-export-data (org-element-property :tag item) info)
1260 ": "))
1261 (ordered
1262 ;; Return correct number for ITEM, paying attention to
1263 ;; counters.
1264 (let* ((struct (org-element-property :structure item))
1265 (bul (org-element-property :bullet item))
1266 (num (number-to-string
1267 (car (last (org-list-get-item-number
1268 (org-element-property :begin item)
1269 struct
1270 (org-list-prevs-alist struct)
1271 (org-list-parents-alist struct)))))))
1272 (replace-regexp-in-string "[0-9]+" num bul)))
1273 (t (let ((bul (org-element-property :bullet item)))
1274 ;; Change bullets into more visible form if UTF-8 is active.
1275 (if (not utf8p) bul
1276 (replace-regexp-in-string
1277 "-" "•"
1278 (replace-regexp-in-string
1279 "+" "⁃"
1280 (replace-regexp-in-string "*" "‣" bul))))))))))
1281 (concat
1282 bullet
1283 (unless (eq list-type 'descriptive) checkbox)
1284 ;; Contents: Pay attention to indentation. Note: check-boxes are
1285 ;; already taken care of at the paragraph level so they don't
1286 ;; interfere with indentation.
1287 (let ((contents (org-e-ascii--indent-string contents (length bullet))))
1288 (if (eq (org-element-type (car (org-element-contents item))) 'paragraph)
1289 (org-trim contents)
1290 (concat "\n" contents))))))
1293 ;;;; Keyword
1295 (defun org-e-ascii-keyword (keyword contents info)
1296 "Transcode a KEYWORD element from Org to ASCII.
1297 CONTENTS is nil. INFO is a plist holding contextual
1298 information."
1299 (let ((key (org-element-property :key keyword))
1300 (value (org-element-property :value keyword)))
1301 (cond
1302 ((string= key "ASCII") value)
1303 ((string= key "TOC")
1304 (let ((value (downcase value)))
1305 (cond
1306 ((string-match "\\<headlines\\>" value)
1307 (let ((depth (or (and (string-match "[0-9]+" value)
1308 (string-to-number (match-string 0 value)))
1309 (plist-get info :with-toc))))
1310 (org-e-ascii--build-toc
1311 info (and (wholenump depth) depth) keyword)))
1312 ((string= "tables" value)
1313 (org-e-ascii--list-tables keyword info))
1314 ((string= "listings" value)
1315 (org-e-ascii--list-listings keyword info))))))))
1318 ;;;; Latex Environment
1320 (defun org-e-ascii-latex-environment (latex-environment contents info)
1321 "Transcode a LATEX-ENVIRONMENT element from Org to ASCII.
1322 CONTENTS is nil. INFO is a plist holding contextual
1323 information."
1324 (org-remove-indentation (org-element-property :value latex-environment)))
1327 ;;;; Latex Fragment
1329 (defun org-e-ascii-latex-fragment (latex-fragment contents info)
1330 "Transcode a LATEX-FRAGMENT object from Org to ASCII.
1331 CONTENTS is nil. INFO is a plist holding contextual
1332 information."
1333 (org-element-property :value latex-fragment))
1336 ;;;; Line Break
1338 (defun org-e-ascii-line-break (line-break contents info)
1339 "Transcode a LINE-BREAK object from Org to ASCII.
1340 CONTENTS is nil. INFO is a plist holding contextual
1341 information." hard-newline)
1344 ;;;; Link
1346 (defun org-e-ascii-link (link desc info)
1347 "Transcode a LINK object from Org to ASCII.
1349 DESC is the description part of the link, or the empty string.
1350 INFO is a plist holding contextual information."
1351 (let ((raw-link (org-element-property :raw-link link))
1352 (type (org-element-property :type link)))
1353 (cond
1354 ((string= type "coderef")
1355 (let ((ref (org-element-property :path link)))
1356 (format (org-export-get-coderef-format ref desc)
1357 (org-export-resolve-coderef ref info))))
1358 ;; Do not apply a special syntax on radio links. Though, use
1359 ;; transcoded target's contents as output.
1360 ((string= type "radio")
1361 (let ((destination (org-export-resolve-radio-link link info)))
1362 (when destination
1363 (org-export-data (org-element-contents destination) info))))
1364 ;; Do not apply a special syntax on fuzzy links pointing to
1365 ;; targets.
1366 ((string= type "fuzzy")
1367 (let ((destination (org-export-resolve-fuzzy-link link info)))
1368 ;; Ignore invisible "#+TARGET: path".
1369 (unless (eq (org-element-type destination) 'keyword)
1370 (if (org-string-nw-p desc) desc
1371 (when destination
1372 (let ((number
1373 (org-export-get-ordinal
1374 destination info nil 'org-e-ascii--has-caption-p)))
1375 (when number
1376 (if (atom number) (number-to-string number)
1377 (mapconcat 'number-to-string number ".")))))))))
1379 (if (not (org-string-nw-p desc)) (format "[%s]" raw-link)
1380 (concat
1381 (format "[%s]" desc)
1382 (unless org-e-ascii-links-to-notes (format " (%s)" raw-link))))))))
1385 ;;;; Paragraph
1387 (defun org-e-ascii-paragraph (paragraph contents info)
1388 "Transcode a PARAGRAPH element from Org to ASCII.
1389 CONTENTS is the contents of the paragraph, as a string. INFO is
1390 the plist used as a communication channel."
1391 (let ((contents (if (not (wholenump org-e-ascii-indented-line-width)) contents
1392 (concat
1393 (make-string org-e-ascii-indented-line-width ? )
1394 (replace-regexp-in-string "\\`[ \t]+" "" contents)))))
1395 (org-e-ascii--fill-string
1396 contents (org-e-ascii--current-text-width paragraph info) info)))
1399 ;;;; Plain List
1401 (defun org-e-ascii-plain-list (plain-list contents info)
1402 "Transcode a PLAIN-LIST element from Org to ASCII.
1403 CONTENTS is the contents of the list. INFO is a plist holding
1404 contextual information."
1405 contents)
1408 ;;;; Plain Text
1410 (defun org-e-ascii-plain-text (text info)
1411 "Transcode a TEXT string from Org to ASCII.
1412 INFO is a plist used as a communication channel."
1413 (let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
1414 (when (and utf8p (plist-get info :with-smart-quotes))
1415 (setq text (org-export-activate-smart-quotes text :utf-8 info)))
1416 (if (not (plist-get info :with-special-strings)) text
1417 (setq text (replace-regexp-in-string "\\\\-" "" text))
1418 (if (not utf8p) text
1419 ;; Usual replacements in utf-8 with proper option set.
1420 (replace-regexp-in-string
1421 "\\.\\.\\." "…"
1422 (replace-regexp-in-string
1423 "--" "–"
1424 (replace-regexp-in-string "---" "—" text)))))))
1427 ;;;; Planning
1429 (defun org-e-ascii-planning (planning contents info)
1430 "Transcode a PLANNING element from Org to ASCII.
1431 CONTENTS is nil. INFO is a plist used as a communication
1432 channel."
1433 (mapconcat
1434 'identity
1435 (delq nil
1436 (list (let ((closed (org-element-property :closed planning)))
1437 (when closed
1438 (concat org-closed-string " "
1439 (org-translate-time
1440 (org-element-property :raw-value closed)))))
1441 (let ((deadline (org-element-property :deadline planning)))
1442 (when deadline
1443 (concat org-deadline-string " "
1444 (org-translate-time
1445 (org-element-property :raw-value deadline)))))
1446 (let ((scheduled (org-element-property :scheduled planning)))
1447 (when scheduled
1448 (concat org-scheduled-string " "
1449 (org-translate-time
1450 (org-element-property :raw-value scheduled)))))))
1451 " "))
1454 ;;;; Property Drawer
1456 ;; Property drawers are ignored.
1459 ;;;; Quote Block
1461 (defun org-e-ascii-quote-block (quote-block contents info)
1462 "Transcode a QUOTE-BLOCK element from Org to ASCII.
1463 CONTENTS holds the contents of the block. INFO is a plist
1464 holding contextual information."
1465 (let ((width (org-e-ascii--current-text-width quote-block info)))
1466 (org-e-ascii--indent-string
1467 (org-remove-indentation
1468 (org-e-ascii--fill-string contents width info))
1469 org-e-ascii-quote-margin)))
1472 ;;;; Quote Section
1474 (defun org-e-ascii-quote-section (quote-section contents info)
1475 "Transcode a QUOTE-SECTION element from Org to ASCII.
1476 CONTENTS is nil. INFO is a plist holding contextual information."
1477 (let ((width (org-e-ascii--current-text-width quote-section info))
1478 (value
1479 (org-export-data
1480 (org-remove-indentation (org-element-property :value quote-section))
1481 info)))
1482 (org-e-ascii--indent-string
1483 value
1484 (+ org-e-ascii-quote-margin
1485 ;; Don't apply inner margin if parent headline is low level.
1486 (let ((headline (org-export-get-parent-headline quote-section)))
1487 (if (org-export-low-level-p headline info) 0
1488 org-e-ascii-inner-margin))))))
1491 ;;;; Radio Target
1493 (defun org-e-ascii-radio-target (radio-target contents info)
1494 "Transcode a RADIO-TARGET object from Org to ASCII.
1495 CONTENTS is the contents of the target. INFO is a plist holding
1496 contextual information."
1497 contents)
1499 ;;;; Section
1501 (defun org-e-ascii-section (section contents info)
1502 "Transcode a SECTION element from Org to ASCII.
1503 CONTENTS is the contents of the section. INFO is a plist holding
1504 contextual information."
1505 (org-e-ascii--indent-string
1506 (concat
1507 contents
1508 (when org-e-ascii-links-to-notes
1509 ;; Add list of links at the end of SECTION.
1510 (let ((links (org-e-ascii--describe-links
1511 (org-e-ascii--unique-links section info)
1512 (org-e-ascii--current-text-width section info) info)))
1513 ;; Separate list of links and section contents.
1514 (when (org-string-nw-p links) (concat "\n\n" links)))))
1515 ;; Do not apply inner margin if parent headline is low level.
1516 (let ((headline (org-export-get-parent-headline section)))
1517 (if (or (not headline) (org-export-low-level-p headline info)) 0
1518 org-e-ascii-inner-margin))))
1521 ;;;; Special Block
1523 (defun org-e-ascii-special-block (special-block contents info)
1524 "Transcode a SPECIAL-BLOCK element from Org to ASCII.
1525 CONTENTS holds the contents of the block. INFO is a plist
1526 holding contextual information."
1527 contents)
1530 ;;;; Src Block
1532 (defun org-e-ascii-src-block (src-block contents info)
1533 "Transcode a SRC-BLOCK element from Org to ASCII.
1534 CONTENTS holds the contents of the item. INFO is a plist holding
1535 contextual information."
1536 (let ((caption (org-e-ascii--build-caption src-block info)))
1537 (concat
1538 (when (and caption org-e-ascii-caption-above) (concat caption "\n"))
1539 (org-e-ascii--box-string
1540 (org-export-format-code-default src-block info) info)
1541 (when (and caption (not org-e-ascii-caption-above))
1542 (concat "\n" caption)))))
1544 ;;;; Statistics Cookie
1546 (defun org-e-ascii-statistics-cookie (statistics-cookie contents info)
1547 "Transcode a STATISTICS-COOKIE object from Org to ASCII.
1548 CONTENTS is nil. INFO is a plist holding contextual information."
1549 (org-element-property :value statistics-cookie))
1552 ;;;; Subscript
1554 (defun org-e-ascii-subscript (subscript contents info)
1555 "Transcode a SUBSCRIPT object from Org to ASCII.
1556 CONTENTS is the contents of the object. INFO is a plist holding
1557 contextual information."
1558 (if (org-element-property :use-brackets-p subscript)
1559 (format "_{%s}" contents)
1560 (format "_%s" contents)))
1563 ;;;; Superscript
1565 (defun org-e-ascii-superscript (superscript contents info)
1566 "Transcode a SUPERSCRIPT object from Org to ASCII.
1567 CONTENTS is the contents of the object. INFO is a plist holding
1568 contextual information."
1569 (if (org-element-property :use-brackets-p superscript)
1570 (format "_{%s}" contents)
1571 (format "_%s" contents)))
1574 ;;;; Strike-through
1576 (defun org-e-ascii-strike-through (strike-through contents info)
1577 "Transcode STRIKE-THROUGH from Org to ASCII.
1578 CONTENTS is text with strike-through markup. INFO is a plist
1579 holding contextual information."
1580 (format "+%s+" contents))
1583 ;;;; Table
1585 (defun org-e-ascii-table (table contents info)
1586 "Transcode a TABLE element from Org to ASCII.
1587 CONTENTS is the contents of the table. INFO is a plist holding
1588 contextual information."
1589 (let ((caption (org-e-ascii--build-caption table info)))
1590 (concat
1591 ;; Possibly add a caption string above.
1592 (when (and caption org-e-ascii-caption-above) (concat caption "\n"))
1593 ;; Insert table. Note: "table.el" tables are left unmodified.
1594 (cond ((eq (org-element-property :type table) 'org) contents)
1595 ((and org-e-ascii-table-use-ascii-art
1596 (eq (plist-get info :ascii-charset) 'utf-8)
1597 (require 'ascii-art-to-unicode nil t))
1598 (with-temp-buffer
1599 (insert (org-remove-indentation
1600 (org-element-property :value table)))
1601 (goto-char (point-min))
1602 (aa2u)
1603 (goto-char (point-max))
1604 (skip-chars-backward " \r\t\n")
1605 (buffer-substring (point-min) (point))))
1606 (t (org-remove-indentation (org-element-property :value table))))
1607 ;; Possible add a caption string below.
1608 (when (and caption (not org-e-ascii-caption-above))
1609 (concat "\n" caption)))))
1612 ;;;; Table Cell
1614 (defun org-e-ascii--table-cell-width (table-cell info)
1615 "Return width of TABLE-CELL.
1617 INFO is a plist used as a communication channel.
1619 Width of a cell is determined either by a width cookie in the
1620 same column as the cell, or by the maximum cell's length in that
1621 column.
1623 When `org-e-ascii-table-widen-columns' is non-nil, width cookies
1624 are ignored."
1625 (or (and (not org-e-ascii-table-widen-columns)
1626 (org-export-table-cell-width table-cell info))
1627 (let* ((max-width 0)
1628 (table (org-export-get-parent-table table-cell))
1629 (specialp (org-export-table-has-special-column-p table))
1630 (col (cdr (org-export-table-cell-address table-cell info))))
1631 (org-element-map
1632 table 'table-row
1633 (lambda (row)
1634 (setq max-width
1635 (max (length
1636 (org-export-data
1637 (org-element-contents
1638 (elt (if specialp (cdr (org-element-contents row))
1639 (org-element-contents row))
1640 col))
1641 info))
1642 max-width)))
1643 info)
1644 max-width)))
1646 (defun org-e-ascii-table-cell (table-cell contents info)
1647 "Transcode a TABLE-CELL object from Org to ASCII.
1648 CONTENTS is the cell contents. INFO is a plist used as
1649 a communication channel."
1650 ;; Determine column width. When `org-e-ascii-table-widen-columns'
1651 ;; is nil and some width cookie has set it, use that value.
1652 ;; Otherwise, compute the maximum width among transcoded data of
1653 ;; each cell in the column.
1654 (let ((width (org-e-ascii--table-cell-width table-cell info)))
1655 ;; When contents are too large, truncate them.
1656 (unless (or org-e-ascii-table-widen-columns (<= (length contents) width))
1657 (setq contents (concat (substring contents 0 (- width 2)) "=>")))
1658 ;; Align contents correctly within the cell.
1659 (let* ((indent-tabs-mode nil)
1660 (data
1661 (when contents
1662 (org-e-ascii--justify-string
1663 contents width
1664 (org-export-table-cell-alignment table-cell info)))))
1665 (setq contents (concat data (make-string (- width (length data)) ? ))))
1666 ;; Return cell.
1667 (concat (format " %s " contents)
1668 (when (memq 'right (org-export-table-cell-borders table-cell info))
1669 (if (eq (plist-get info :ascii-charset) 'utf-8) "│" "|")))))
1672 ;;;; Table Row
1674 (defun org-e-ascii-table-row (table-row contents info)
1675 "Transcode a TABLE-ROW element from Org to ASCII.
1676 CONTENTS is the row contents. INFO is a plist used as
1677 a communication channel."
1678 (when (eq (org-element-property :type table-row) 'standard)
1679 (let ((build-hline
1680 (function
1681 (lambda (lcorner horiz vert rcorner)
1682 (concat
1683 (apply
1684 'concat
1685 (org-element-map
1686 table-row 'table-cell
1687 (lambda (cell)
1688 (let ((width (org-e-ascii--table-cell-width cell info))
1689 (borders (org-export-table-cell-borders cell info)))
1690 (concat
1691 ;; In order to know if CELL starts the row, do
1692 ;; not compare it with the first cell in the row
1693 ;; as there might be a special column. Instead,
1694 ;; compare it with the first exportable cell,
1695 ;; obtained with `org-element-map'.
1696 (when (and (memq 'left borders)
1697 (eq (org-element-map
1698 table-row 'table-cell 'identity info t)
1699 cell))
1700 lcorner)
1701 (make-string (+ 2 width) (string-to-char horiz))
1702 (cond
1703 ((not (memq 'right borders)) nil)
1704 ((eq (car (last (org-element-contents table-row))) cell)
1705 rcorner)
1706 (t vert)))))
1707 info)) "\n"))))
1708 (utf8p (eq (plist-get info :ascii-charset) 'utf-8))
1709 (borders (org-export-table-cell-borders
1710 (org-element-map table-row 'table-cell 'identity info t)
1711 info)))
1712 (concat (cond
1713 ((and (memq 'top borders) (or utf8p (memq 'above borders)))
1714 (if utf8p (funcall build-hline "┍" "━" "┯" "┑")
1715 (funcall build-hline "+" "-" "+" "+")))
1716 ((memq 'above borders)
1717 (if utf8p (funcall build-hline "├" "─" "┼" "┤")
1718 (funcall build-hline "+" "-" "+" "+"))))
1719 (when (memq 'left borders) (if utf8p "│" "|"))
1720 contents "\n"
1721 (when (and (memq 'bottom borders) (or utf8p (memq 'below borders)))
1722 (if utf8p (funcall build-hline "┕" "━" "┷" "┙")
1723 (funcall build-hline "+" "-" "+" "+")))))))
1726 ;;;; Target
1728 ;; Targets are invisible.
1731 ;;;; Timestamp
1733 (defun org-e-ascii-timestamp (timestamp contents info)
1734 "Transcode a TIMESTAMP object from Org to ASCII.
1735 CONTENTS is nil. INFO is a plist holding contextual information."
1736 (let ((value (org-translate-time
1737 (org-element-property :raw-value timestamp))))
1738 (if (not (eq (plist-get info :ascii-charset) 'utf-8)) value
1739 (replace-regexp-in-string "--" "–" value))))
1742 ;;;; Underline
1744 (defun org-e-ascii-underline (underline contents info)
1745 "Transcode UNDERLINE from Org to ASCII.
1746 CONTENTS is the text with underline markup. INFO is a plist
1747 holding contextual information."
1748 (format "_%s_" contents))
1751 ;;;; Verbatim
1753 (defun org-e-ascii-verbatim (verbatim contents info)
1754 "Return a VERBATIM object from Org to ASCII.
1755 CONTENTS is nil. INFO is a plist holding contextual information."
1756 (format org-e-ascii-verbatim-format
1757 (org-element-property :value verbatim)))
1760 ;;;; Verse Block
1762 (defun org-e-ascii-verse-block (verse-block contents info)
1763 "Transcode a VERSE-BLOCK element from Org to ASCII.
1764 CONTENTS is verse block contents. INFO is a plist holding
1765 contextual information."
1766 (let ((verse-width (org-e-ascii--current-text-width verse-block info)))
1767 (org-e-ascii--indent-string
1768 (org-e-ascii--justify-string contents verse-width 'left)
1769 org-e-ascii-quote-margin)))
1772 ;;; Filters
1774 (defun org-e-ascii-filter-headline-blank-lines (headline back-end info)
1775 "Filter controlling number of blank lines after an headline.
1777 HEADLINE is a string representing a transcoded headline.
1778 BACK-END is symbol specifying back-end used for export. INFO is
1779 plist containing the communication channel.
1781 This function only applies to `e-ascii' back-end. See
1782 `org-e-ascii-headline-spacing' for information."
1783 (if (not org-e-ascii-headline-spacing) headline
1784 (let ((blanks (make-string (1+ (cdr org-e-ascii-headline-spacing)) ?\n)))
1785 (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" blanks headline))))
1787 (defun org-e-ascii-filter-paragraph-spacing (tree back-end info)
1788 "Filter controlling number of blank lines between paragraphs.
1790 TREE is the parse tree. BACK-END is the symbol specifying
1791 back-end used for export. INFO is a plist used as
1792 a communication channel.
1794 This function only applies to `e-ascii' back-end. See
1795 `org-e-ascii-paragraph-spacing' for information."
1796 (when (wholenump org-e-ascii-paragraph-spacing)
1797 (org-element-map
1798 tree 'paragraph
1799 (lambda (p)
1800 (when (eq (org-element-type (org-export-get-next-element p info))
1801 'paragraph)
1802 (org-element-put-property
1803 p :post-blank org-e-ascii-paragraph-spacing)))))
1804 tree)
1808 ;;; End-user functions
1810 ;;;###autoload
1811 (defun org-e-ascii-export-as-ascii
1812 (&optional subtreep visible-only body-only ext-plist)
1813 "Export current buffer to a text buffer.
1815 If narrowing is active in the current buffer, only export its
1816 narrowed part.
1818 If a region is active, export that region.
1820 When optional argument SUBTREEP is non-nil, export the sub-tree
1821 at point, extracting information from the headline properties
1822 first.
1824 When optional argument VISIBLE-ONLY is non-nil, don't export
1825 contents of hidden elements.
1827 When optional argument BODY-ONLY is non-nil, strip title, table
1828 of contents and footnote definitions from output.
1830 EXT-PLIST, when provided, is a property list with external
1831 parameters overriding Org default settings, but still inferior to
1832 file-local settings.
1834 Export is done in a buffer named \"*Org E-ASCII Export*\", which
1835 will be displayed when `org-export-show-temporary-export-buffer'
1836 is non-nil."
1837 (interactive)
1838 (let ((outbuf (org-export-to-buffer
1839 'e-ascii "*Org E-ASCII Export*"
1840 subtreep visible-only body-only ext-plist)))
1841 (with-current-buffer outbuf (text-mode))
1842 (when org-export-show-temporary-export-buffer
1843 (switch-to-buffer-other-window outbuf))))
1845 ;;;###autoload
1846 (defun org-e-ascii-export-to-ascii
1847 (&optional subtreep visible-only body-only ext-plist pub-dir)
1848 "Export current buffer to a text file.
1850 If narrowing is active in the current buffer, only export its
1851 narrowed part.
1853 If a region is active, export that region.
1855 When optional argument SUBTREEP is non-nil, export the sub-tree
1856 at point, extracting information from the headline properties
1857 first.
1859 When optional argument VISIBLE-ONLY is non-nil, don't export
1860 contents of hidden elements.
1862 When optional argument BODY-ONLY is non-nil, strip title, table
1863 of contents and footnote definitions from output.
1865 EXT-PLIST, when provided, is a property list with external
1866 parameters overriding Org default settings, but still inferior to
1867 file-local settings.
1869 When optional argument PUB-DIR is set, use it as the publishing
1870 directory.
1872 Return output file's name."
1873 (interactive)
1874 (let ((outfile (org-export-output-file-name ".txt" subtreep pub-dir)))
1875 (org-export-to-file
1876 'e-ascii outfile subtreep visible-only body-only ext-plist)))
1878 ;;;###autoload
1879 (defun org-e-ascii-publish-to-ascii (plist filename pub-dir)
1880 "Publish an Org file to ASCII.
1882 FILENAME is the filename of the Org file to be published. PLIST
1883 is the property list for the given project. PUB-DIR is the
1884 publishing directory.
1886 Return output file name."
1887 (org-e-publish-org-to
1888 'e-ascii filename ".txt" `(:ascii-charset ascii ,@plist) pub-dir))
1890 ;;;###autoload
1891 (defun org-e-ascii-publish-to-latin1 (plist filename pub-dir)
1892 "Publish an Org file to Latin-1.
1894 FILENAME is the filename of the Org file to be published. PLIST
1895 is the property list for the given project. PUB-DIR is the
1896 publishing directory.
1898 Return output file name."
1899 (org-e-publish-org-to
1900 'e-ascii filename ".txt" `(:ascii-charset latin1 ,@plist) pub-dir))
1902 ;;;###autoload
1903 (defun org-e-ascii-publish-to-utf8 (plist filename pub-dir)
1904 "Publish an org file to UTF-8.
1906 FILENAME is the filename of the Org file to be published. PLIST
1907 is the property list for the given project. PUB-DIR is the
1908 publishing directory.
1910 Return output file name."
1911 (org-e-publish-org-to
1912 'e-ascii filename ".txt" `(:ascii-charset utf-8 ,@plist) pub-dir))
1915 (provide 'org-e-ascii)
1916 ;;; org-e-ascii.el ends here