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