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