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