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