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