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