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