12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847 |
- (eval-when-compile (require 'cl))
- (declare-function org-element-contents "org-element" (element))
- (declare-function org-element-property "org-element" (property element))
- (declare-function org-element-normalize-string "org-element" (s))
- (declare-function org-element-map "org-element"
- (data types fun &optional info first-match))
- (declare-function org-export-collect-footnote-definitions
- "org-export" (data info))
- (declare-function org-export-collect-headlines "org-export" (info &optional n))
- (declare-function org-export-collect-listings "org-export" (info))
- (declare-function org-export-collect-tables "org-export" (info))
- (declare-function org-export-data "org-export" (data info))
- (declare-function org-export-expand-macro "org-export" (macro info))
- (declare-function org-export-format-code-default "org-export" (element info))
- (declare-function org-export-get-coderef-format "org-export" (path desc))
- (declare-function org-export-get-footnote-number "org-export" (footnote info))
- (declare-function org-export-get-headline-number "org-export" (headline info))
- (declare-function org-export-get-ordinal "org-export"
- (element info &optional types predicate))
- (declare-function org-export-get-parent-headline "org-export" (blob info))
- (declare-function org-export-get-relative-level "org-export" (headline info))
- (declare-function org-export-low-level-p "org-export" (headline info))
- (declare-function org-export-output-file-name "org-export"
- (extension &optional subtreep pub-dir))
- (declare-function org-export-resolve-coderef "org-export" (ref info))
- (declare-function org-export-resolve-fuzzy-link "org-export" (link info))
- (declare-function org-export-resolve-id-link "org-export" (link info))
- (declare-function org-export-resolve-ref-link "org-export" (link info))
- (declare-function org-export-secondary-string "org-export" (secondary info))
- (declare-function
- org-export-to-file "org-export"
- (backend file &optional subtreep visible-only body-only ext-plist))
- (defconst org-e-ascii-option-alist
- '((:ascii-charset nil nil org-e-ascii-charset))
- "Alist between ASCII export properties and ways to set them.
- See `org-export-option-alist' for more information on the
- structure or the values.")
- (defconst org-e-ascii-filters-alist
- '((:filter-headline . org-e-ascii-filter-headline-blank-lines)
- (:filter-section . org-e-ascii-filter-headline-blank-lines))
- "Alist between filters keywords and back-end specific filters.
- See `org-export-filters-alist' for more information.")
- (defconst org-e-ascii-dictionary
- '(("Footnotes\n"
- ("en"
- :ascii "Footnotes\n"
- :latin1 "Footnotes\n"
- :utf-8 "Footnotes\n")
- ("fr"
- :ascii "Notes de bas de page\n"
- :latin1 "Notes de bas de page\n"
- :utf-8 "Notes de bas de page\n"))
- ("Listing %d: %s"
- ("en"
- :ascii "Listing %d: %s"
- :latin1 "Listing %d: %s"
- :utf-8 "Listing %d: %s")
- ("fr"
- :ascii "Programme %d : %s"
- :latin1 "Programme %d : %s"
- :utf-8 "Programme nº %d : %s"))
- ("List Of Listings\n"
- ("en"
- :ascii "List Of Listings\n"
- :latin1 "List Of Listings\n"
- :utf-8 "List Of Listings\n")
- ("fr"
- :ascii "Liste des programmes\n"
- :latin1 "Liste des programmes\n"
- :utf-8 "Liste des programmes\n"))
- ("List Of Tables\n"
- ("en"
- :ascii "List Of Tables\n"
- :latin1 "List Of Tables\n"
- :utf-8 "List Of Tables\n")
- ("fr"
- :ascii "Liste des tableaux\n"
- :latin1 "Liste des tableaux\n"
- :utf-8 "Liste des tableaux\n"))
- ("Listing %d: "
- ("en"
- :ascii "Listing %d: "
- :latin1 "Listing %d: "
- :utf-8 "Listing %d: ")
- ("fr"
- :ascii "Programme %d : "
- :latin1 "Programme %d : "
- :utf-8 "Programme nº %d : "))
- ("Table Of Contents\n"
- ("en"
- :ascii "Table Of Contents\n"
- :latin1 "Table Of Contents\n"
- :utf-8 "Table Of Contents\n")
- ("fr"
- :ascii "Sommaire\n"
- :latin1 "Table des matières\n"
- :utf-8 "Table des matières\n"))
- ("Table %d: %s"
- ("en"
- :ascii "Table %d: %s"
- :latin1 "Table %d: %s"
- :utf-8 "Table %d: %s")
- ("fr"
- :ascii "Tableau %d : %s"
- :latin1 "Tableau %d : %s"
- :utf-8 "Tableau nº %d : %s"))
- ("See section %s"
- ("en"
- :ascii "See section %s"
- :latin1 "See section %s"
- :utf-8 "See section %s")
- ("fr"
- :ascii "cf. section %s"
- :latin1 "cf. section %s"
- :utf-8 "cf. section %s"))
- ("Table %d: "
- ("en"
- :ascii "Table %d: "
- :latin1 "Table %d: "
- :utf-8 "Table %d: ")
- ("fr"
- :ascii "Tableau %d : "
- :latin1 "Tableau %d : "
- :utf-8 "Tableau nº %d : "))
- ("Unknown reference"
- ("en"
- :ascii "Unknown reference"
- :latin1 "Unknown reference"
- :utf-8 "Unknown reference")
- ("fr"
- :ascii "Destination inconnue"
- :latin1 "Référence inconnue"
- :utf-8 "Référence inconnue")))
- "Dictionary for ASCII back-end.
- Alist whose car is the string to translate and cdr is an alist
- whose car is the language string and cdr is a plist whose
- properties are possible charsets and value the translated term.
- It is used as a database for `org-e-ascii--translate'.")
- (defgroup org-export-e-ascii nil
- "Options for exporting Org mode files to ASCII."
- :tag "Org Export ASCII"
- :group 'org-export)
- (defcustom org-e-ascii-text-width 72
- "Maximum width of exported text.
- This number includes margin size, as set in
- `org-e-ascii-global-margin'."
- :group 'org-export-e-ascii
- :type 'integer)
- (defcustom org-e-ascii-global-margin 0
- "Width of the left margin, in number of characters."
- :group 'org-export-e-ascii
- :type 'integer)
- (defcustom org-e-ascii-inner-margin 2
- "Width of the inner margin, in number of characters.
- Inner margin is applied between each headline."
- :group 'org-export-e-ascii
- :type 'integer)
- (defcustom org-e-ascii-quote-margin 6
- "Width of margin used for quoting text, in characters.
- This margin is applied on both sides of the text."
- :group 'org-export-e-ascii
- :type 'integer)
- (defcustom org-e-ascii-inlinetask-width 30
- "Width of inline tasks, in number of characters.
- This number ignores any margin."
- :group 'org-export-e-ascii
- :type 'integer)
- (defcustom org-e-ascii-headline-spacing '(1 . 2)
- "Number of blank lines inserted around headlines.
- This variable can be set to a cons cell. In that case, its car
- represents the number of blank lines present before headline
- contents whereas its cdr reflects the number of blank lines after
- contents.
- A nil value replicates the number of blank lines found in the
- original Org buffer at the same place."
- :group 'org-export-e-ascii
- :type '(choice
- (const :tag "Replicate original spacing" nil)
- (cons :tag "Set an uniform spacing"
- (integer :tag "Number of blank lines before contents")
- (integer :tag "Number of blank lines after contents"))))
- (defcustom org-e-ascii-charset 'ascii
- "The charset allowed to represent various elements and objects.
- Possible values are:
- `ascii' Only use plain ASCII characters
- `latin1' Include Latin-1 characters
- `utf-8' Use all UTF-8 characters"
- :group 'org-export-e-ascii
- :type '(choice
- (const :tag "ASCII" ascii)
- (const :tag "Latin-1" latin1)
- (const :tag "UTF-8" utf-8)))
- (defcustom org-e-ascii-underline '((ascii ?= ?~ ?-)
- (latin1 ?= ?~ ?-)
- (utf-8 ?═ ?─ ?╌ ?┄ ?┈))
- "Characters for underlining headings in ASCII export.
- Alist whose key is a symbol among `ascii', `latin1' and `utf-8'
- and whose value is a list of characters.
- For each supported charset, this variable associates a sequence
- of underline characters. In a sequence, the characters will be
- used in order for headlines level 1, 2, ... If no character is
- available for a given level, the headline won't be underlined."
- :group 'org-export-e-ascii
- :type '(list
- (cons :tag "Underline characters sequence"
- (const :tag "ASCII charset" ascii)
- (repeat character))
- (cons :tag "Underline characters sequence"
- (const :tag "Latin-1 charset" latin1)
- (repeat character))
- (cons :tag "Underline characters sequence"
- (const :tag "UTF-8 charset" utf-8)
- (repeat character))))
- (defcustom org-e-ascii-bullets '((ascii ?* ?+ ?-)
- (latin1 ?§ ?¶)
- (utf-8 ?◊))
- "Bullet characters for headlines converted to lists in ASCII export.
- Alist whose key is a symbol among `ascii', `latin1' and `utf-8'
- and whose value is a list of characters.
- The first character is used for the first level considered as low
- level, and so on. If there are more levels than characters given
- here, the list will be repeated.
- Note that this variable doesn't affect plain lists
- representation."
- :group 'org-export-e-ascii
- :type '(list
- (cons :tag "Bullet characters for low level headlines"
- (const :tag "ASCII charset" ascii)
- (repeat character))
- (cons :tag "Bullet characters for low level headlines"
- (const :tag "Latin-1 charset" latin1)
- (repeat character))
- (cons :tag "Bullet characters for low level headlines"
- (const :tag "UTF-8 charset" utf-8)
- (repeat character))))
- (defcustom org-e-ascii-links-to-notes t
- "Non-nil means convert links to notes before the next headline.
- When nil, the link will be exported in place. If the line
- becomes long in this way, it will be wrapped."
- :group 'org-export-e-ascii
- :type 'boolean)
- (defcustom org-e-ascii-table-keep-all-vertical-lines nil
- "Non-nil means keep all vertical lines in ASCII tables.
- When nil, vertical lines will be removed except for those needed
- for column grouping."
- :group 'org-export-e-ascii
- :type 'boolean)
- (defcustom org-e-ascii-table-widen-columns t
- "Non-nil means widen narrowed columns for export.
- When nil, narrowed columns will look in ASCII export just like in
- Org mode, i.e. with \"=>\" as ellipsis."
- :group 'org-export-e-ascii
- :type 'boolean)
- (defcustom org-e-ascii-caption-above nil
- "When non-nil, place caption string before the element.
- Otherwise, place it right after it."
- :group 'org-export-e-ascii
- :type 'boolean)
- (defcustom org-e-ascii-verbatim-format "`%s'"
- "Format string used for verbatim text and inline code."
- :group 'org-export-e-ascii
- :type 'string)
- (defcustom org-e-ascii-format-drawer-function nil
- "Function called to format a drawer in ASCII.
- The function must accept two parameters:
- NAME the drawer name, like \"LOGBOOK\"
- CONTENTS the contents of the drawer.
- WIDTH the text width within the drawer.
- The function should return either the string to be exported or
- nil to ignore the drawer.
- For example, the variable could be set to the following function
- in order to mimic default behaviour:
- \(defun org-e-ascii-format-drawer-default \(name contents width\)
- \"Format a drawer element for ASCII export.\"
- contents\)"
- :group 'org-export-e-ascii
- :type 'function)
- (defcustom org-e-ascii-format-inlinetask-function nil
- "Function called to format an inlinetask in ASCII.
- The function must accept six parameters:
- TODO the todo keyword, as a string
- TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
- PRIORITY the inlinetask priority, as a string
- NAME the inlinetask name, as a string.
- TAGS the inlinetask tags, as a string.
- CONTENTS the contents of the inlinetask, as a string.
- The function should return either the string to be exported or
- nil to ignore the inline task.
- For example, the variable could be set to the following function
- in order to mimic default behaviour:
- \(defun org-e-ascii-format-inlinetask-default
- \(todo type priority name tags contents\)
- \"Format an inline task element for ASCII export.\"
- \(let* \(\(utf8p \(eq \(plist-get info :ascii-charset\) 'utf-8\)\)
- \(width org-e-ascii-inlinetask-width\)
- \(org-e-ascii--indent-string
- \(concat
- ;; Top line, with an additional blank line if not in UTF-8.
- \(make-string width \(if utf8p ?━ ?_\)\) \"\\n\"
- \(unless utf8p \(concat \(make-string width ? \) \"\\n\"\)\)
- ;; Add title. Fill it if wider than inlinetask.
- \(let \(\(title \(org-e-ascii--build-title inlinetask info width\)\)\)
- \(if \(<= \(length title\) width\) title
- \(org-e-ascii--fill-string title width info\)\)\)
- \"\\n\"
- ;; If CONTENTS is not empty, insert it along with
- ;; a separator.
- \(when \(org-string-nw-p contents\)
- \(concat \(make-string width \(if utf8p ?─ ?-\)\) \"\\n\" contents\)\)
- ;; Bottom line.
- \(make-string width \(if utf8p ?━ ?_\)\)\)
- ;; Flush the inlinetask to the right.
- \(- \(plist-get info :ascii-width\)
- \(plist-get info :ascii-margin\)
- \(plist-get info :ascii-inner-margin\)
- \(org-e-ascii--current-text-width inlinetask info\)\)"
- :group 'org-export-e-ascii
- :type 'function)
- (defun org-e-ascii--fill-string (s text-width info &optional justify)
- "Fill a string with specified text-width and return it.
- S is the string being filled. TEXT-WIDTH is an integer
- specifying maximum length of a line. INFO is the plist used as
- a communication channel.
- Optional argument JUSTIFY can specify any type of justification
- among `left', `center', `right' or `full'. A nil value is
- equivalent to `left'. For a justification that doesn't also fill
- string, see `org-e-ascii--justify-string'.
- Return nil if S isn't a string."
-
- (cond ((not (stringp s)) nil)
- ((plist-get info :preserve-breaks) s)
- (t (with-temp-buffer
- (let ((fill-column text-width)
- (use-hard-newlines t))
- (insert s)
- (fill-region (point-min) (point-max) justify))
- (buffer-string)))))
- (defun org-e-ascii--justify-string (s text-width how)
- "Justify string S.
- TEXT-WIDTH is an integer specifying maximum length of a line.
- HOW determines the type of justification: it can be `left',
- `right', `full' or `center'."
- (with-temp-buffer
- (insert s)
- (goto-char (point-min))
- (let ((fill-column text-width))
- (while (< (point) (point-max))
- (justify-current-line how)
- (forward-line)))
- (buffer-string)))
- (defun org-e-ascii--indent-string (s width)
- "Indent string S by WIDTH white spaces.
- Empty lines are not indented."
- (when (stringp s)
- (replace-regexp-in-string
- "\\(^\\)\\(?:.*\\S-\\)" (make-string width ? ) s nil nil 1)))
- (defun org-e-ascii--box-string (s info)
- "Return string S with a partial box to its left.
- INFO is a plist used as a communicaton channel."
- (let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
- (format (if utf8p "╭────\n%s\n╰────" ",----\n%s\n`----")
- (replace-regexp-in-string
- "^" (if utf8p "│ " "| ")
-
- (replace-regexp-in-string "\n[ \t]*\\'" "" s)))))
- (defun org-e-ascii--current-text-width (element info)
- "Return maximum text width for ELEMENT's contents.
- INFO is a plist used as a communication channel."
- (case (org-element-type element)
-
- (inlinetask org-e-ascii-inlinetask-width)
- ('headline
- (- org-e-ascii-text-width
- (let ((low-level-rank (org-export-low-level-p element info)))
- (if low-level-rank (* low-level-rank 2) org-e-ascii-global-margin))))
-
-
- (otherwise
- (let* ((genealogy (cons element (org-export-get-genealogy element info)))
-
-
- (total-width
- (if (loop for parent in genealogy
- thereis (eq (org-element-type parent) 'inlinetask))
- org-e-ascii-inlinetask-width
-
- (- org-e-ascii-text-width
- org-e-ascii-global-margin
- (let ((parent (org-export-get-parent-headline element info)))
-
-
- (if (not parent) 0
- (let ((low-level-rank
- (org-export-low-level-p parent info)))
-
-
-
- (if low-level-rank (* low-level-rank 2)
- org-e-ascii-inner-margin))))))))
- (- total-width
-
-
- (+ (* (loop for parent in genealogy
- when (memq (org-element-type parent)
- '(quote-block quote-section verse-block))
- count parent)
- 2 org-e-ascii-quote-margin)
-
-
-
-
- (let ((parent-item
- (if (eq (org-element-type element) 'item) element
- (loop for parent in genealogy
- when (eq (org-element-type parent) 'item)
- return parent))))
- (if (not parent-item) 0
-
-
-
-
-
-
- (let ((struct (org-element-property :structure parent-item))
- (beg-item (org-element-property :begin parent-item)))
- (+ (- (org-list-get-ind beg-item struct)
- (org-list-get-ind
- (org-list-get-top-point struct) struct))
- (length
- (or (org-list-get-tag beg-item struct)
- (org-list-get-bullet beg-item struct)))))))))))))
- (defun org-e-ascii--build-title
- (element info text-width &optional underline notags)
- "Format ELEMENT title and return it.
- ELEMENT is either an `headline' or `inlinetask' element. INFO is
- a plist used as a communication channel. TEXT-WIDTH is an
- integer representing the maximum length of a line.
- When optional argument UNDERLINE is non-nil, underline title,
- without the tags, according to `org-e-ascii-underline'
- specifications.
- if optional argument NOTAGS is nil, no tags will be added to the
- title."
- (let* ((headlinep (eq (org-element-type element) 'headline))
- (numbers
-
- (and headlinep (org-export-numbered-headline-p element info)
-
- (concat
- (mapconcat
- #'number-to-string
- (org-export-get-headline-number element info) ".")
- " ")))
- (text (org-export-secondary-string
- (org-element-property :title element) info))
- (todo
- (and (plist-get info :with-todo-keywords)
- (let ((todo (org-element-property :todo-keyword element)))
- (and todo
- (concat (org-export-secondary-string todo info) " ")))))
- (tags (and (not notags)
- (plist-get info :with-tags)
- (org-element-property :tags element)))
- (priority
- (and (plist-get info :with-priority)
- (concat (org-element-property :priority element) " ")))
- (first-part (concat numbers todo priority text)))
- (concat
- first-part
-
- (when tags
- (format
- (format " %%%ds"
- (max (- text-width (1+ (length first-part))) (length tags)))
- tags))
-
-
- (when (and underline headlinep)
- (let ((under-char
- (nth (1- (org-export-get-relative-level element info))
- (cdr (assq (plist-get info :ascii-charset)
- org-e-ascii-underline)))))
- (and under-char
- (concat "\n"
- (make-string (length first-part) under-char))))))))
- (defun org-e-ascii--build-caption (element info)
- "Return caption string for ELEMENT, if applicable.
- INFO is a plist used as a communication channel.
- The caption string contains the sequence number of ELEMENT if it
- has a name affiliated keyword, along with the real caption, if
- any. Return nil when ELEMENT has no affiliated caption or name
- keyword."
- (let ((caption (org-element-property :caption element))
- (name (org-element-property :name element)))
- (when (or caption name)
-
-
- (let ((reference
- (org-export-get-ordinal
- element info nil
- (lambda (el info) (or (org-element-property :caption el)
- (org-element-property :name el)))))
- (title-fmt (org-e-ascii--translate
- (case (org-element-type element)
- (table "Table %d: %s")
- (src-block "Listing %d: %s")) info)))
- (org-e-ascii--fill-string
- (format
- title-fmt reference
- (if (not caption) name
- (org-export-secondary-string (car caption) info)))
- (org-e-ascii--current-text-width element info) info)))))
- (defun org-e-ascii--build-toc (info &optional n keyword)
- "Return a table of contents.
- INFO is a plist used as a communication channel.
- Optional argument N, when non-nil, is an integer specifying the
- depth of the table.
- Optional argument KEYWORD specifies the TOC keyword, if any, from
- which the table of contents generation has been initiated."
- (let ((title (org-e-ascii--translate "Table Of Contents\n" info)))
- (concat
- title
- (make-string (1- (length title))
- (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))
- "\n\n"
- (let ((text-width
- (if keyword (org-e-ascii--current-text-width keyword info)
- (- org-e-ascii-text-width org-e-ascii-global-margin))))
- (mapconcat
- (lambda (headline)
- (let* ((level (org-export-get-relative-level headline info))
- (indent (* (1- level) 3)))
- (concat
- (unless (zerop indent) (concat (make-string (1- indent) ?.) " "))
- (org-e-ascii--build-title
- headline info (- text-width indent) nil
- (eq (plist-get info :with-tags) 'not-in-toc)))))
- (org-export-collect-headlines info n) "\n")))))
- (defun org-e-ascii--list-listings (keyword info)
- "Return a list of listings.
- KEYWORD is the keyword that initiated the list of listings
- generation. INFO is a plist used as a communication channel."
- (let ((title (org-e-ascii--translate "List Of Listings\n" info)))
- (concat
- title
- (make-string (1- (length title))
- (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))
- "\n\n"
- (let ((text-width
- (if keyword (org-e-ascii--current-text-width keyword info)
- (- org-e-ascii-text-width org-e-ascii-global-margin)))
-
-
- (count 0))
- (mapconcat
- (lambda (src-block)
-
-
-
- (let ((initial-text
- (format (org-e-ascii--translate "Listing %d: " info)
- (incf count))))
- (concat
- initial-text
- (org-trim
- (org-e-ascii--indent-string
- (org-e-ascii--fill-string
- (let ((caption (org-element-property :caption src-block)))
- (if (not caption) (org-element-property :name src-block)
- (org-export-secondary-string
-
- (or (cdr caption) (car caption)) info)))
- (- text-width (length initial-text)) info)
- (length initial-text))))))
- (org-export-collect-listings info) "\n")))))
- (defun org-e-ascii--list-tables (keyword info)
- "Return a list of listings.
- KEYWORD is the keyword that initiated the list of listings
- generation. INFO is a plist used as a communication channel."
- (let ((title (org-e-ascii--translate "List Of Tables\n" info)))
- (concat
- title
- (make-string (1- (length title))
- (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))
- "\n\n"
- (let ((text-width
- (if keyword (org-e-ascii--current-text-width keyword info)
- (- org-e-ascii-text-width org-e-ascii-global-margin)))
-
-
- (count 0))
- (mapconcat
- (lambda (table)
-
-
-
- (let ((initial-text
- (format (org-e-ascii--translate "Table %d: " info)
- (incf count))))
- (concat
- initial-text
- (org-trim
- (org-e-ascii--indent-string
- (org-e-ascii--fill-string
- (let ((caption (org-element-property :caption table)))
- (if (not caption) (org-element-property :name table)
-
- (org-export-secondary-string
- (or (cdr caption) (car caption)) info)))
- (- text-width (length initial-text)) info)
- (length initial-text))))))
- (org-export-collect-tables info) "\n")))))
- (defun org-e-ascii--unique-links (element info)
- "Return a list of unique link references in ELEMENT.
- ELEMENT is either an headline element or a section element. INFO
- is a plist used as a communication channel.
- It covers links that may be found current headline's title, in
- the following section and in any inlinetask's title there."
- (let* (seen
- (unique-link-p
- (function
-
-
- (lambda (link)
- (let ((footprint
- (cons (org-element-property :raw-link link)
- (org-element-contents link))))
- (unless (member footprint seen)
- (push footprint seen) link)))))
- (harvest-links-in-title
- (function
-
-
- (lambda (element)
- (let (acc)
- (dolist (obj (org-element-property :title element) acc)
- (when (eq (org-element-type obj) 'link)
- (let ((link (funcall unique-link-p obj)))
- (and link (push link acc)))))))))
-
- (section (if (eq (org-element-type element) 'section) element
- (let ((sec (car (org-element-contents element))))
- (and (eq (org-element-type sec) 'section) sec))))
- (headline (if (eq (org-element-type element) 'headline) element
- (org-export-get-parent-headline element info))))
- (append
-
- (funcall harvest-links-in-title headline)
-
- (org-element-map
- section 'link (lambda (link) (funcall unique-link-p link)) info))))
- (defun org-e-ascii--describe-links (links width info)
- "Return a string describing a list of links.
- LINKS is a list of link type objects, as returned by
- `org-e-ascii--unique-links'. WIDTH is the text width allowed for
- the output string. INFO is a plist used as a communication
- channel."
- (mapconcat
- (lambda (link)
- (let ((type (org-element-property :type link))
- (anchor (let ((desc (org-element-contents link)))
- (if (not desc) (org-element-property :raw-link link)
- (org-export-secondary-string desc info)))))
- (cond
-
- ((member type '("coderef" "radio" "fuzzy")) nil)
-
- ((member type '("custom-id" "id"))
- (let ((dest (org-export-resolve-id-link link info)))
- (concat
- (org-e-ascii--fill-string
- (format
- "[%s] %s"
- anchor
- (if (not dest) (org-e-ascii--translate "Unknown reference" info)
- (format
- (org-e-ascii--translate "See section %s" info)
- (mapconcat 'number-to-string
- (org-export-get-headline-number dest info) "."))))
- width info) "\n\n")))
-
-
-
- ((not (org-element-contents link)) nil)
- (t
- (concat
- (org-e-ascii--fill-string
- (format "[%s] %s" anchor (org-element-property :raw-link link))
- width info)
- "\n\n")))))
- links ""))
- (defun org-e-ascii-template--document-title (info)
- "Return document title, as a string.
- INFO is a plist used as a communication channel."
- (let ((text-width org-e-ascii-text-width)
- (title (org-export-secondary-string (plist-get info :title) info))
- (author (and (plist-get info :with-author)
- (let ((auth (plist-get info :author)))
- (and auth (org-export-secondary-string auth info)))))
- (email (and (plist-get info :with-email)
- (org-export-secondary-string (plist-get info :email) info)))
- (date (plist-get info :date)))
-
-
- (if (string= title "")
-
-
-
- (cond
- ((and (org-string-nw-p date) (org-string-nw-p author))
- (concat
- author
- (make-string (- text-width (length date) (length author)) ? )
- date
- (when (org-string-nw-p email) (concat "\n" email))
- "\n\n\n"))
- ((and (org-string-nw-p date) (org-string-nw-p email))
- (concat
- email
- (make-string (- text-width (length date) (length email)) ? )
- date "\n\n\n"))
- ((org-string-nw-p date)
- (concat
- (org-e-ascii--justify-string date text-width 'right)
- "\n\n\n"))
- ((and (org-string-nw-p author) (org-string-nw-p email))
- (concat author "\n" email "\n\n\n"))
- ((org-string-nw-p author) (concat author "\n\n\n"))
- ((org-string-nw-p email) (concat email "\n\n\n")))
-
-
-
- (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8))
-
-
- (title-len (min (length title) (/ (* 2 text-width) 3)))
- (formatted-title (org-e-ascii--fill-string title title-len info))
- (line
- (make-string
- (min (+ (max title-len (length author) (length email)) 2)
- text-width) (if utf8p ?━ ?_))))
- (org-e-ascii--justify-string
- (concat line "\n"
- (unless utf8p "\n")
- (upcase formatted-title)
- (cond
- ((and (org-string-nw-p author) (org-string-nw-p email))
- (concat (if utf8p "\n\n\n" "\n\n") author "\n" email))
- ((org-string-nw-p author)
- (concat (if utf8p "\n\n\n" "\n\n") author))
- ((org-string-nw-p email)
- (concat (if utf8p "\n\n\n" "\n\n") email)))
- "\n" line
- (when (org-string-nw-p date) (concat "\n\n\n" date))
- "\n\n\n") text-width 'center)))))
- (defun org-e-ascii-template (contents info)
- "Return complete document string after ASCII conversion.
- CONTENTS is the transcoded contents string. INFO is a plist
- holding export options."
- (org-element-normalize-string
- (org-e-ascii--indent-string
- (let ((text-width (- org-e-ascii-text-width org-e-ascii-global-margin)))
-
- (concat
- (org-e-ascii-template--document-title info)
-
- (let ((depth (plist-get info :with-toc)))
- (when depth
- (concat
- (org-e-ascii--build-toc info (and (wholenump depth) depth))
- "\n\n\n")))
-
- contents
-
- (let ((definitions (org-export-collect-footnote-definitions
- (plist-get info :parse-tree) info))
-
-
- (org-e-ascii-links-to-notes nil))
- (when definitions
- (concat
- "\n\n\n"
- (let ((title (org-e-ascii--translate "Footnotes\n" info)))
- (concat
- title
- (make-string
- (1- (length title))
- (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))))
- "\n\n"
- (mapconcat
- (lambda (ref)
- (let ((id (format "[%s] " (car ref))))
-
-
- (org-trim
- (let ((def (nth 2 ref)))
- (if (eq (org-element-type def) 'org-data)
-
-
-
-
- (let ((first (car (org-element-contents def))))
- (if (not (eq (org-element-type first) 'paragraph))
- (concat id "\n" (org-export-data def info))
- (push id (nthcdr 2 first))
- (org-export-data def info)))
-
-
- (org-e-ascii--fill-string
- (concat id (org-export-secondary-string def info))
- text-width info))))))
- definitions "\n\n"))))
-
-
- (let ((creator-info (plist-get info :with-creator)))
- (unless (or (not creator-info) (eq creator-info 'comment))
- (concat
- "\n\n\n"
- (org-e-ascii--fill-string
- (plist-get info :creator) text-width info 'right))))))
- org-e-ascii-global-margin)))
- (defun org-e-ascii--translate (s info)
- "Translate string S.
- INFO is a plist used as a communication channel.
- Translation depends on `:language' property and allowed charset.
- If no translation in found for a given language and a given
- charset, fall-back to S."
- (let* ((charset (intern (format ":%s" (plist-get info :ascii-charset))))
- (lang (plist-get info :language))
- (translations (cdr (assoc s org-e-ascii-dictionary))))
- (or (plist-get (cdr (assoc lang translations)) charset) s)))
- (defun org-e-ascii-bold (bold contents info)
- "Transcode BOLD from Org to ASCII.
- CONTENTS is the text with bold markup. INFO is a plist holding
- contextual information."
- (format "*%s*" contents))
- (defun org-e-ascii-center-block (center-block contents info)
- "Transcode a CENTER-BLOCK element from Org to ASCII.
- CONTENTS holds the contents of the block. INFO is a plist
- holding contextual information."
- (org-e-ascii--justify-string
- contents (org-e-ascii--current-text-width center-block info) 'center))
- (defun org-e-ascii-clock (clock contents info)
- "Transcode a CLOCK object from Org to ASCII.
- CONTENTS is nil. INFO is a plist holding contextual
- information."
- (concat org-clock-string " "
- (org-translate-time (org-element-property :value clock))
- (let ((time (org-element-property :time clock)))
- (and time
- (concat " => "
- (apply 'format
- "%2s:%02s"
- (org-split-string time ":")))))))
- (defun org-e-ascii-code (code contents info)
- "Return a CODE object from Org to ASCII.
- CONTENTS is nil. INFO is a plist holding contextual
- information."
- (format org-e-ascii-verbatim-format (org-element-property :value code)))
- (defun org-e-ascii-drawer (drawer contents info)
- "Transcode a DRAWER element from Org to ASCII.
- CONTENTS holds the contents of the block. INFO is a plist
- holding contextual information."
- (let ((name (org-element-property :drawer-name drawer))
- (width (org-e-ascii--current-text-width drawer info)))
- (if (functionp org-e-ascii-format-drawer-function)
- (funcall org-e-ascii-format-drawer-function name contents width)
-
-
- contents)))
- (defun org-e-ascii-dynamic-block (dynamic-block contents info)
- "Transcode a DYNAMIC-BLOCK element from Org to ASCII.
- CONTENTS holds the contents of the block. INFO is a plist
- holding contextual information. See `org-export-data'."
- contents)
- (defun org-e-ascii-entity (entity contents info)
- "Transcode an ENTITY object from Org to ASCII.
- CONTENTS are the definition itself. INFO is a plist holding
- contextual information."
- (org-element-property
- (intern (concat ":" (symbol-name (plist-get info :ascii-charset))))
- entity))
- (defun org-e-ascii-example-block (example-block contents info)
- "Transcode a EXAMPLE-BLOCK element from Org to ASCII.
- CONTENTS is nil. INFO is a plist holding contextual information."
- (org-e-ascii--box-string
- (org-export-format-code-default example-block info) info))
- (defun org-e-ascii-export-snippet (export-snippet contents info)
- "Transcode a EXPORT-SNIPPET object from Org to ASCII.
- CONTENTS is nil. INFO is a plist holding contextual information."
- (when (eq (org-export-snippet-backend export-snippet) 'e-ascii)
- (org-element-property :value export-snippet)))
- (defun org-e-ascii-export-block (export-block contents info)
- "Transcode a EXPORT-BLOCK element from Org to ASCII.
- CONTENTS is nil. INFO is a plist holding contextual information."
- (when (string= (org-element-property :type export-block) "ascii")
- (org-remove-indentation (org-element-property :value export-block))))
- (defun org-e-ascii-fixed-width (fixed-width contents info)
- "Transcode a FIXED-WIDTH element from Org to ASCII.
- CONTENTS is nil. INFO is a plist holding contextual information."
- (org-e-ascii--box-string
- (replace-regexp-in-string
- "^[ \t]*: ?" "" (org-element-property :value fixed-width)) info))
- (defun org-e-ascii-footnote-reference (footnote-reference contents info)
- "Transcode a FOOTNOTE-REFERENCE element from Org to ASCII.
- CONTENTS is nil. INFO is a plist holding contextual information."
- (format "[%s]" (org-export-get-footnote-number footnote-reference info)))
- (defun org-e-ascii-headline (headline contents info)
- "Transcode an HEADLINE element from Org to ASCII.
- CONTENTS holds the contents of the headline. INFO is a plist
- holding contextual information."
-
-
- (unless (org-element-property :footnote-section-p headline)
- (let* ((low-level-rank (org-export-low-level-p headline info))
- (width (org-e-ascii--current-text-width headline info))
-
-
-
- (pre-blanks
- (make-string
- (if org-e-ascii-headline-spacing (car org-e-ascii-headline-spacing)
- (org-element-property :pre-blank headline)) ?\n))
-
-
- (links
- (unless (eq (caar (org-element-contents headline)) 'section)
- (org-e-ascii--describe-links
- (org-e-ascii--unique-links headline info) width info))))
-
- (if low-level-rank
- (concat
-
- (let ((bullets (cdr (assq (plist-get info :ascii-charset)
- org-e-ascii-bullets))))
- (char-to-string
- (nth (mod (1- low-level-rank) (length bullets)) bullets)))
- " "
-
- (org-e-ascii--build-title headline info width) "\n"
-
- pre-blanks
- (org-e-ascii--indent-string
- (concat contents
- (when (org-string-nw-p links) (concat "\n\n" links)))
- 2))
-
- (concat
- (org-e-ascii--build-title headline info width 'underline)
- "\n" pre-blanks
- (concat (when (org-string-nw-p links) links) contents))))))
- (defun org-e-ascii-horizontal-rule (horizontal-rule contents info)
- "Transcode an HORIZONTAL-RULE object from Org to ASCII.
- CONTENTS is nil. INFO is a plist holding contextual
- information."
- (let ((attr
- (read
- (format
- "(%s)"
- (mapconcat
- #'identity
- (org-element-property :attr_ascii horizontal-rule)
- " ")))))
- (make-string (or (and (wholenump (plist-get attr :width))
- (plist-get attr :width))
- (org-e-ascii--current-text-width horizontal-rule info))
- (if (eq (plist-get info :ascii-charset) 'utf-8) ?― ?-))))
- (defun org-e-ascii-inline-src-block (inline-src-block contents info)
- "Transcode an INLINE-SRC-BLOCK element from Org to ASCII.
- CONTENTS holds the contents of the item. INFO is a plist holding
- contextual information."
- (format org-e-ascii-verbatim-format
- (org-element-property :value inline-src-block)))
- (defun org-e-ascii-inlinetask (inlinetask contents info)
- "Transcode an INLINETASK element from Org to ASCII.
- CONTENTS holds the contents of the block. INFO is a plist
- holding contextual information."
- (let ((width (org-e-ascii--current-text-width inlinetask info))
- (title (org-export-secondary-string
- (org-element-property :title inlinetask) info))
- (todo (and (plist-get info :with-todo-keywords)
- (let ((todo (org-element-property
- :todo-keyword inlinetask)))
- (and todo
- (org-export-secondary-string todo info)))))
- (todo-type (org-element-property :todo-type inlinetask))
- (tags (and (plist-get info :with-tags)
- (org-element-property :tags inlinetask)))
- (priority (and (plist-get info :with-priority)
- (org-element-property :priority inlinetask))))
-
-
- (if (functionp org-e-ascii-format-inlinetask-function)
- (funcall org-e-ascii-format-inlinetask-function
- todo todo-type priority title tags contents width)
-
- (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
- (org-e-ascii--indent-string
- (concat
-
- (make-string width (if utf8p ?━ ?_)) "\n"
- (unless utf8p (concat (make-string width ? ) "\n"))
-
- (let ((title (org-e-ascii--build-title inlinetask info width)))
- (if (<= (length title) width) title
- (org-e-ascii--fill-string title width info)))
- "\n"
-
-
- (when (org-string-nw-p contents)
- (concat (make-string width (if utf8p ?─ ?-)) "\n" contents))
-
- (make-string width (if utf8p ?━ ?_)))
-
- (- org-e-ascii-text-width org-e-ascii-global-margin
- (if (not (org-export-get-parent-headline inlinetask info)) 0
- org-e-ascii-inner-margin)
- (org-e-ascii--current-text-width inlinetask info)))))))
- (defun org-e-ascii-italic (italic contents info)
- "Transcode italic from Org to ASCII.
- CONTENTS is the text with italic markup. INFO is a plist holding
- contextual information."
- (format "/%s/" contents))
- (defun org-e-ascii-item (item contents info)
- "Transcode an ITEM element from Org to ASCII.
- CONTENTS holds the contents of the item. INFO is a plist holding
- contextual information."
- (let ((bullet
-
-
- (org-list-bullet-string
- (case (org-element-property :type (org-export-get-parent item info))
- (descriptive
- (concat
- (org-export-secondary-string
- (org-element-property :tag item) info)
- ": "))
- (ordered
-
-
- (let* ((struct (org-element-property :structure item))
- (bul (org-element-property :bullet item))
- (num
- (number-to-string
- (car (last (org-list-get-item-number
- (org-element-property :begin item)
- struct
- (org-list-prevs-alist struct)
- (org-list-parents-alist struct)))))))
- (replace-regexp-in-string "[0-9]+" num bul)))
- (t (let ((bul (org-element-property :bullet item)))
-
- (if (not (eq (plist-get info :ascii-charset) 'utf-8)) bul
- (replace-regexp-in-string
- "-" "•"
- (replace-regexp-in-string
- "+" "⁃"
- (replace-regexp-in-string "*" "‣" bul))))))))))
- (concat
- bullet
-
-
-
- (let ((contents (org-e-ascii--indent-string contents (length bullet))))
- (if (eq (caar (org-element-contents item)) 'paragraph)
- (org-trim contents)
- (concat "\n" contents))))))
- (defun org-e-ascii-keyword (keyword contents info)
- "Transcode a KEYWORD element from Org to ASCII.
- CONTENTS is nil. INFO is a plist holding contextual
- information."
- (let ((key (org-element-property :key keyword))
- (value (org-element-property :value keyword)))
- (cond
- ((string= key "ASCII") value)
- ((string= key "TOC")
- (let ((value (downcase value)))
- (cond
- ((string-match "\\<headlines\\>" value)
- (let ((depth (or (and (string-match "[0-9]+" value)
- (string-to-number (match-string 0 value)))
- (plist-get info :with-toc))))
- (org-e-ascii--build-toc
- info (and (wholenump depth) depth) keyword)))
- ((string= "tables" value)
- (org-e-ascii--list-tables keyword info))
- ((string= "listings" value)
- (org-e-ascii--list-listings keyword info))))))))
- (defun org-e-ascii-latex-environment (latex-environment contents info)
- "Transcode a LATEX-ENVIRONMENT element from Org to ASCII.
- CONTENTS is nil. INFO is a plist holding contextual
- information."
- (org-remove-indentation (org-element-property :value latex-environment)))
- (defun org-e-ascii-latex-fragment (latex-fragment contents info)
- "Transcode a LATEX-FRAGMENT object from Org to ASCII.
- CONTENTS is nil. INFO is a plist holding contextual
- information."
- (org-element-property :value latex-fragment))
- (defun org-e-ascii-line-break (line-break contents info)
- "Transcode a LINE-BREAK object from Org to ASCII.
- CONTENTS is nil. INFO is a plist holding contextual
- information." hard-newline)
- (defun org-e-ascii-link (link desc info)
- "Transcode a LINK object from Org to ASCII.
- DESC is the description part of the link, or the empty string.
- INFO is a plist holding contextual information."
- (let ((raw-link (org-element-property :raw-link link))
- (type (org-element-property :type link)))
- (cond
- ((string= type "coderef")
- (let ((ref (org-element-property :path link)))
- (format (org-export-get-coderef-format ref desc)
- (org-export-resolve-coderef ref info))))
-
-
- ((string= type "radio")
- (org-export-secondary-string
- (org-element-parse-secondary-string
- (org-element-property :path link)
- (cdr (assq 'radio-target org-element-object-restrictions)))
- info))
-
-
- ((string= type "fuzzy")
- (let ((destination (org-export-resolve-fuzzy-link link info)))
-
- (unless (eq (org-element-type destination) 'keyword)
- (if (org-string-nw-p desc) desc
- (when destination
- (let ((number (org-export-get-ordinal destination info)))
- (when number
- (if (atom number) (number-to-string number)
- (mapconcat 'number-to-string number ".")))))))))
- (t
- (if (not (org-string-nw-p desc)) (format "[%s]" raw-link)
- (concat
- (format "[%s]" desc)
- (unless org-e-ascii-links-to-notes (format " (%s)" raw-link))))))))
- (defun org-e-ascii-macro (macro contents info)
- "Transcode a MACRO element from Org to ASCII.
- CONTENTS is nil. INFO is a plist holding contextual
- information."
- (org-export-expand-macro macro info))
- (defun org-e-ascii-paragraph (paragraph contents info)
- "Transcode a PARAGRAPH element from Org to ASCII.
- CONTENTS is the contents of the paragraph, as a string. INFO is
- the plist used as a communication channel."
- (org-e-ascii--fill-string
- (let ((parent (org-export-get-parent paragraph info)))
-
-
-
- (if (and (eq (org-element-type parent) 'item)
- (equal (car (org-element-contents parent)) paragraph))
- (let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
- (concat (case (org-element-property :checkbox parent)
- (on (if utf8p "☑ " "[X] "))
- (off (if utf8p "☐ " "[ ] "))
- (trans (if utf8p "☒ " "[-] ")))
- contents))
- contents))
- (org-e-ascii--current-text-width paragraph info) info))
- (defun org-e-ascii-plain-list (plain-list contents info)
- "Transcode a PLAIN-LIST element from Org to ASCII.
- CONTENTS is the contents of the list. INFO is a plist holding
- contextual information."
- contents)
- (defun org-e-ascii-plain-text (text info)
- "Transcode a TEXT string from Org to ASCII.
- INFO is a plist used as a communication channel."
- (if (not (and (eq (plist-get info :ascii-charset) 'utf-8)
- (plist-get info :with-special-strings)))
- text
-
- (replace-regexp-in-string
- "\\.\\.\\." "…"
- (replace-regexp-in-string
- "--" "–"
- (replace-regexp-in-string "---" "—" text)))))
- (defun org-e-ascii-planning (planning contents info)
- "Transcode a PLANNING element from Org to ASCII.
- CONTENTS is nil. INFO is a plist used as a communication
- channel."
- (mapconcat
- 'identity
- (delq nil
- (list (let ((closed (org-element-property :closed planning)))
- (when closed (concat org-closed-string " "
- (org-translate-time closed))))
- (let ((deadline (org-element-property :deadline planning)))
- (when deadline (concat org-deadline-string " "
- (org-translate-time deadline))))
- (let ((scheduled (org-element-property :scheduled planning)))
- (when scheduled (concat org-scheduled-string " "
- (org-translate-time scheduled))))))
- " "))
- (defun org-e-ascii-quote-block (quote-block contents info)
- "Transcode a QUOTE-BLOCK element from Org to ASCII.
- CONTENTS holds the contents of the block. INFO is a plist
- holding contextual information."
- (let ((width (org-e-ascii--current-text-width quote-block info)))
- (org-e-ascii--indent-string
- (org-remove-indentation
- (org-e-ascii--fill-string contents width info))
- org-e-ascii-quote-margin)))
- (defun org-e-ascii-quote-section (quote-section contents info)
- "Transcode a QUOTE-SECTION element from Org to ASCII.
- CONTENTS is nil. INFO is a plist holding contextual information."
- (let ((width (org-e-ascii--current-text-width quote-section info))
- (value
- (org-export-secondary-string
- (org-remove-indentation
- (org-element-property :value quote-section))
- info)))
- (org-e-ascii--indent-string
- value
- (+ org-e-ascii-quote-margin
-
- (let ((headline (org-export-get-parent-headline quote-section info)))
- (if (org-export-low-level-p headline info) 0
- org-e-ascii-inner-margin))))))
- (defun org-e-ascii-radio-target (radio-target contents info)
- "Transcode a RADIO-TARGET object from Org to ASCII.
- CONTENTS is the contents of the target. INFO is a plist holding
- contextual information."
- contents)
- (defun org-e-ascii-section (section contents info)
- "Transcode a SECTION element from Org to ASCII.
- CONTENTS is the contents of the section. INFO is a plist holding
- contextual information."
- (org-e-ascii--indent-string
- (concat
- contents
- (when org-e-ascii-links-to-notes
-
- (let ((links (org-e-ascii--describe-links
- (org-e-ascii--unique-links section info)
- (org-e-ascii--current-text-width section info) info)))
-
- (when (org-string-nw-p links) (concat "\n\n" links)))))
-
- (let ((headline (org-export-get-parent-headline section info)))
- (if (or (not headline) (org-export-low-level-p headline info)) 0
- org-e-ascii-inner-margin))))
- (defun org-e-ascii-special-block (special-block contents info)
- "Transcode a SPECIAL-BLOCK element from Org to ASCII.
- CONTENTS holds the contents of the block. INFO is a plist
- holding contextual information."
- contents)
- (defun org-e-ascii-src-block (src-block contents info)
- "Transcode a SRC-BLOCK element from Org to ASCII.
- CONTENTS holds the contents of the item. INFO is a plist holding
- contextual information."
- (let ((caption (org-e-ascii--build-caption src-block info)))
- (concat
- (when (and caption org-e-ascii-caption-above) (concat caption "\n"))
- (org-e-ascii--box-string
- (org-export-format-code-default src-block info) info)
- (when (and caption (not org-e-ascii-caption-above))
- (concat "\n" caption)))))
- (defun org-e-ascii-statistics-cookie (statistics-cookie contents info)
- "Transcode a STATISTICS-COOKIE object from Org to ASCII.
- CONTENTS is nil. INFO is a plist holding contextual information."
- (org-element-property :value statistics-cookie))
- (defun org-e-ascii-subscript (subscript contents info)
- "Transcode a SUBSCRIPT object from Org to ASCII.
- CONTENTS is the contents of the object. INFO is a plist holding
- contextual information."
- (if (org-element-property :use-brackets-p subscript)
- (format "_{%s}" contents)
- (format "_%s" contents)))
- (defun org-e-ascii-superscript (superscript contents info)
- "Transcode a SUPERSCRIPT object from Org to ASCII.
- CONTENTS is the contents of the object. INFO is a plist holding
- contextual information."
- (if (org-element-property :use-brackets-p superscript)
- (format "_{%s}" contents)
- (format "_%s" contents)))
- (defun org-e-ascii-strike-through (strike-through contents info)
- "Transcode STRIKE-THROUGH from Org to ASCII.
- CONTENTS is text with strike-through markup. INFO is a plist
- holding contextual information."
- (format "+%s+" contents))
- (defun org-e-ascii-table (table contents info)
- "Transcode a TABLE element from Org to ASCII.
- CONTENTS is nil. INFO is a plist holding contextual information."
- (let ((caption (org-e-ascii--build-caption table info)))
- (concat
-
- (when (and caption org-e-ascii-caption-above) (concat caption "\n"))
-
- (if (eq (org-element-property :type table) 'org) contents
- (org-remove-indentation (org-element-property :value table)))
-
- (when (and caption (not org-e-ascii-caption-above))
- (concat "\n" caption)))))
- (defun org-e-ascii--table-cell-width (table-cell info)
- "Return width of TABLE-CELL.
- Width of a cell is determined either by a width cookie in the
- same column as the cell, or by the length of its contents.
- When `org-e-ascii-table-widen-columns' is non-nil, width cookies
- are ignored. "
- (or (and (not org-e-ascii-table-widen-columns)
- (org-export-table-cell-width table-cell info))
- (let* ((max-width 0)
- (table (org-export-get-parent-table table-cell info))
- (specialp (org-export-table-has-special-column-p table))
- (col (cdr (org-export-table-cell-address table-cell info))))
- (org-element-map
- table 'table-row
- (lambda (row)
- (setq max-width
- (max (length
- (org-export-data
- (elt (if specialp (car (org-element-contents row))
- (org-element-contents row))
- col)
- info))
- max-width))))
- max-width)))
- (defun org-e-ascii-table-cell (table-cell contents info)
- "Transcode a TABLE-CELL object from Org to ASCII.
- CONTENTS is the cell contents. INFO is a plist used as
- a communication channel."
-
-
-
-
- (let ((width (org-e-ascii--table-cell-width table-cell info)))
-
- (unless (or org-e-ascii-table-widen-columns (<= (length contents) width))
- (setq contents (concat (substring contents 0 (- width 2)) "=>")))
-
- (let* ((indent-tabs-mode nil)
- (data
- (when contents
- (org-e-ascii--justify-string
- contents width
- (org-export-table-cell-alignment table-cell info)))))
- (setq contents (concat data (make-string (- width (length data)) ? ))))
-
- (concat (format " %s " contents)
- (when (memq 'right (org-export-table-cell-borders table-cell info))
- (if (eq (plist-get info :ascii-charset) 'utf-8) "│" "|")))))
- (defun org-e-ascii-table-row (table-row contents info)
- "Transcode a TABLE-ROW element from Org to ASCII.
- CONTENTS is the row contents. INFO is a plist used as
- a communication channel."
- (when (eq (org-element-property :type table-row) 'standard)
- (let ((build-hline
- (function
- (lambda (lcorner horiz vert rcorner)
- (concat
- (apply
- 'concat
- (org-element-map
- table-row 'table-cell
- (lambda (cell)
- (let ((width (org-e-ascii--table-cell-width cell info))
- (borders (org-export-table-cell-borders cell info)))
- (concat
- (when (and (memq 'left borders)
- (equal (org-element-map
- table-row 'table-cell 'identity info t)
- cell)))
- (make-string (+ 2 width) (string-to-char horiz))
- (cond
- ((not (memq 'right borders)) nil)
- ((equal (car (last (org-element-contents table-row)))
- cell)
- rcorner)
- (t vert)))))
- info)) "\n"))))
- (utf8p (eq (plist-get info :ascii-charset) 'utf-8))
- (borders (org-export-table-cell-borders
- (org-element-map table-row 'table-cell 'identity info t)
- info)))
- (concat (cond
- ((and (memq 'top borders) (or utf8p (memq 'above borders)))
- (if utf8p (funcall build-hline "┍" "━" "┯" "┑")
- (funcall build-hline "+" "-" "+" "+")))
- ((memq 'above borders)
- (if utf8p (funcall build-hline "├" "─" "┼" "┤")
- (funcall build-hline "+" "-" "+" "+"))))
- (when (memq 'left borders) (if utf8p "│" "|"))
- contents "\n"
- (when (and (memq 'bottom borders) (or utf8p (memq 'below borders)))
- (if utf8p (funcall build-hline "┕" "━" "┷" "┙")
- (funcall build-hline "+" "-" "+" "+")))))))
- (defun org-e-ascii-timestamp (timestamp contents info)
- "Transcode a TIMESTAMP object from Org to ASCII.
- CONTENTS is nil. INFO is a plist holding contextual information."
- (org-translate-time (org-element-property :value timestamp)))
- (defun org-e-ascii-underline (underline contents info)
- "Transcode UNDERLINE from Org to ASCII.
- CONTENTS is the text with underline markup. INFO is a plist
- holding contextual information."
- (format "_%s_" contents))
- (defun org-e-ascii-verbatim (verbatim contents info)
- "Return a VERBATIM object from Org to ASCII.
- CONTENTS is nil. INFO is a plist holding contextual information."
- (format org-e-ascii-verbatim-format
- (org-element-property :value verbatim)))
- (defun org-e-ascii-verse-block (verse-block contents info)
- "Transcode a VERSE-BLOCK element from Org to ASCII.
- CONTENTS is verse block contents. INFO is a plist holding
- contextual information."
- (let ((verse-width (org-e-ascii--current-text-width verse-block info)))
- (org-e-ascii--indent-string
- (org-e-ascii--justify-string contents verse-width 'left)
- org-e-ascii-quote-margin)))
- (defun org-e-ascii-filter-headline-blank-lines (headline back-end info)
- "Filter controlling number of blank lines after an headline.
- HEADLINE is a string representing a transcoded headline.
- BACK-END is symbol specifying back-end used for export. INFO is
- plist containing the communication channel.
- This function only applies to `e-ascii' back-end. See
- `org-e-ascii-headline-spacing' for information.
- For any other back-end, HEADLINE is returned as-is."
- (if (not (and (eq back-end 'e-ascii) org-e-ascii-headline-spacing)) headline
- (let ((blanks (make-string (1+ (cdr org-e-ascii-headline-spacing)) ?\n)))
- (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" blanks headline))))
- (defun org-e-ascii-export-to-ascii
- (&optional subtreep visible-only body-only ext-plist pub-dir)
- "Export current buffer to a text file.
- If narrowing is active in the current buffer, only export its
- narrowed part.
- If a region is active, export that region.
- When optional argument SUBTREEP is non-nil, export the sub-tree
- at point, extracting information from the headline properties
- first.
- When optional argument VISIBLE-ONLY is non-nil, don't export
- contents of hidden elements.
- When optional argument BODY-ONLY is non-nil, strip title, table
- of contents and footnote definitions from output.
- EXT-PLIST, when provided, is a property list with external
- parameters overriding Org default settings, but still inferior to
- file-local settings.
- When optional argument PUB-DIR is set, use it as the publishing
- directory.
- Return output file's name."
- (interactive)
- (let ((outfile (org-export-output-file-name ".txt" subtreep pub-dir)))
- (org-export-to-file
- 'e-ascii outfile subtreep visible-only body-only ext-plist)))
- (provide 'org-e-ascii)
|