update packages
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
;;; ox-ascii.el --- ASCII Back-End for Org Export Engine -*- lexical-binding: t; -*-
|
||||
;;; ox-ascii.el --- ASCII Backend for Org Export Engine -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2012-2023 Free Software Foundation, Inc.
|
||||
;; Copyright (C) 2012-2025 Free Software Foundation, Inc.
|
||||
|
||||
;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
|
||||
;; Maintainer: Nicolas Goaziou <mail@nicolasgoaziou.fr>
|
||||
;; Keywords: outlines, hypermedia, calendar, wp
|
||||
;; Keywords: outlines, hypermedia, calendar, text
|
||||
|
||||
;; This file is part of GNU Emacs.
|
||||
|
||||
@@ -23,7 +22,7 @@
|
||||
|
||||
;;; Commentary:
|
||||
;;
|
||||
;; This library implements an ASCII back-end for Org generic exporter.
|
||||
;; This library implements an ASCII backend for Org generic exporter.
|
||||
;; See Org manual for more information.
|
||||
|
||||
;;; Code:
|
||||
@@ -42,7 +41,7 @@
|
||||
(declare-function org-back-to-heading "org" (&optional invisible-ok))
|
||||
(declare-function org-next-visible-heading "org" (arg))
|
||||
|
||||
;;; Define Back-End
|
||||
;;; Define Backend
|
||||
;;
|
||||
;; The following setting won't allow modifying preferred charset
|
||||
;; through a buffer keyword or an option item, but, since the property
|
||||
@@ -507,7 +506,7 @@ that is according to the widest non blank line in CONTENTS."
|
||||
(let ((text-width (org-ascii--current-text-width element info))
|
||||
(how (org-ascii--current-justification element)))
|
||||
(cond
|
||||
((eq (org-element-type element) 'paragraph)
|
||||
((org-element-type-p element 'paragraph)
|
||||
;; Paragraphs are treated specially as they need to be filled.
|
||||
(org-ascii--fill-string contents text-width info how))
|
||||
((eq how 'left) contents)
|
||||
@@ -575,13 +574,13 @@ INFO is a plist used as a communication channel."
|
||||
;; inline task among ELEMENT parents.
|
||||
(total-width
|
||||
(if (cl-some (lambda (parent)
|
||||
(eq (org-element-type parent) 'inlinetask))
|
||||
(org-element-type-p parent 'inlinetask))
|
||||
genealogy)
|
||||
(plist-get info :ascii-inlinetask-width)
|
||||
;; No inlinetask: Remove global margin from text width.
|
||||
(- (plist-get info :ascii-text-width)
|
||||
(plist-get info :ascii-global-margin)
|
||||
(let ((parent (org-export-get-parent-headline element)))
|
||||
(let ((parent (org-element-lineage element 'headline)))
|
||||
;; Inner margin doesn't apply to text before first
|
||||
;; headline.
|
||||
(if (not parent) 0
|
||||
@@ -596,8 +595,8 @@ INFO is a plist used as a communication channel."
|
||||
;; Each `quote-block' and `verse-block' above narrows text
|
||||
;; width by twice the standard margin size.
|
||||
(+ (* (cl-count-if (lambda (parent)
|
||||
(memq (org-element-type parent)
|
||||
'(quote-block verse-block)))
|
||||
(org-element-type-p
|
||||
parent '(quote-block verse-block)))
|
||||
genealogy)
|
||||
2
|
||||
(plist-get info :ascii-quote-margin))
|
||||
@@ -605,9 +604,9 @@ INFO is a plist used as a communication channel."
|
||||
;; containing current line
|
||||
(* (cl-count-if
|
||||
(lambda (e)
|
||||
(and (eq (org-element-type e) 'plain-list)
|
||||
(not (eq (org-element-type (org-export-get-parent e))
|
||||
'item))))
|
||||
(and (org-element-type-p e 'plain-list)
|
||||
(not (org-element-type-p
|
||||
(org-element-parent e) 'item))))
|
||||
genealogy)
|
||||
(plist-get info :ascii-list-margin))
|
||||
;; Compute indentation offset due to current list. It is
|
||||
@@ -616,8 +615,8 @@ INFO is a plist used as a communication channel."
|
||||
(let ((indentation 0))
|
||||
(dolist (e genealogy)
|
||||
(cond
|
||||
((not (eq 'item (org-element-type e))))
|
||||
((eq (org-element-property :type (org-export-get-parent e))
|
||||
((not (org-element-type-p e 'item)))
|
||||
((eq (org-element-property :type (org-element-parent e))
|
||||
'descriptive)
|
||||
(cl-incf indentation org-ascii-quote-margin))
|
||||
(t
|
||||
@@ -632,16 +631,19 @@ INFO is a plist used as a communication channel."
|
||||
"Return expected justification for ELEMENT's contents.
|
||||
Return value is a symbol among `left', `center', `right' and
|
||||
`full'."
|
||||
(let (justification)
|
||||
(while (and (not justification)
|
||||
(setq element (org-element-property :parent element)))
|
||||
(pcase (org-element-type element)
|
||||
(`center-block (setq justification 'center))
|
||||
(`special-block
|
||||
(let ((name (org-element-property :type element)))
|
||||
(cond ((string= name "JUSTIFYRIGHT") (setq justification 'right))
|
||||
((string= name "JUSTIFYLEFT") (setq justification 'left)))))))
|
||||
(or justification 'left)))
|
||||
(or (org-element-lineage-map
|
||||
element
|
||||
(lambda (el)
|
||||
(pcase (org-element-type el)
|
||||
(`center-block 'center)
|
||||
(`special-block
|
||||
(let ((name (org-element-property :type el)))
|
||||
(cond ((string= name "JUSTIFYRIGHT") 'right)
|
||||
((string= name "JUSTIFYLEFT") 'left))))))
|
||||
'(center-block special-block)
|
||||
nil 'first-match)
|
||||
;; default
|
||||
'left))
|
||||
|
||||
(defun org-ascii--build-title
|
||||
(element info text-width &optional underline notags toc)
|
||||
@@ -660,7 +662,7 @@ the title.
|
||||
|
||||
When optional argument TOC is non-nil, use optional title if
|
||||
possible. It doesn't apply to `inlinetask' elements."
|
||||
(let* ((headlinep (eq (org-element-type element) 'headline))
|
||||
(let* ((headlinep (org-element-type-p element 'headline))
|
||||
(numbers
|
||||
;; Numbering is specific to headlines.
|
||||
(and headlinep
|
||||
@@ -886,7 +888,7 @@ is a plist used as a communication channel."
|
||||
(gethash link (plist-get info :exported-data)))
|
||||
(not (member footprint seen)))
|
||||
(push footprint seen) link)))))
|
||||
(org-element-map (if (eq (org-element-type element) 'section)
|
||||
(org-element-map (if (org-element-type-p element 'section)
|
||||
element
|
||||
;; In a headline, only retrieve links in title
|
||||
;; and relative section, not in children.
|
||||
@@ -952,14 +954,15 @@ channel."
|
||||
;; Only links with a description need an entry. Other are
|
||||
;; already handled in `org-ascii-link'.
|
||||
(when description
|
||||
(let ((dest (if (equal type "fuzzy")
|
||||
(org-export-resolve-fuzzy-link link info)
|
||||
;; Ignore broken links. On broken link,
|
||||
;; `org-export-resolve-id-link' will throw an
|
||||
;; error and we will return nil.
|
||||
(condition-case nil
|
||||
(org-export-resolve-id-link link info)
|
||||
(org-link-broken nil)))))
|
||||
(let ((dest
|
||||
;; Ignore broken links. On broken link,
|
||||
;; `org-export-resolve-id-link' will throw an
|
||||
;; error and we will return nil.
|
||||
(condition-case nil
|
||||
(if (equal type "fuzzy")
|
||||
(org-export-resolve-fuzzy-link link info)
|
||||
(org-export-resolve-id-link link info))
|
||||
(org-link-broken nil))))
|
||||
(when dest
|
||||
(concat
|
||||
(org-ascii--fill-string
|
||||
@@ -1118,7 +1121,7 @@ holding export options."
|
||||
;; paragraph (FIRST), if any, to be sure
|
||||
;; filling will take it into consideration.
|
||||
(let ((first (car (org-element-contents def))))
|
||||
(if (not (eq (org-element-type first) 'paragraph))
|
||||
(if (not (org-element-type-p first 'paragraph))
|
||||
(concat id "\n" (org-export-data def info))
|
||||
(push id (nthcdr 2 first))
|
||||
(org-export-data def info)))
|
||||
@@ -1338,7 +1341,7 @@ holding contextual information."
|
||||
(if (not (org-string-nw-p links)) contents
|
||||
(let* ((contents (org-element-contents headline))
|
||||
(section (let ((first (car contents)))
|
||||
(and (eq (org-element-type first) 'section)
|
||||
(and (org-element-type-p first 'section)
|
||||
first))))
|
||||
(concat (and section
|
||||
(concat (org-element-normalize-string
|
||||
@@ -1395,7 +1398,7 @@ contextual information."
|
||||
(_todo _type _priority _name _tags contents width inlinetask info)
|
||||
"Format an inline task element for ASCII export.
|
||||
See `org-ascii-format-inlinetask-function' for a description
|
||||
of the parameters."
|
||||
of the parameters CONTENTS, WIDTH, INLINETASK, and INFO."
|
||||
(let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8))
|
||||
(width (or width (plist-get info :ascii-inlinetask-width))))
|
||||
(org-ascii--indent-string
|
||||
@@ -1416,7 +1419,7 @@ of the parameters."
|
||||
(make-string width (if utf8p ?━ ?_)))
|
||||
;; Flush the inlinetask to the right.
|
||||
(- (plist-get info :ascii-text-width) (plist-get info :ascii-global-margin)
|
||||
(if (not (org-export-get-parent-headline inlinetask)) 0
|
||||
(if (not (org-element-lineage inlinetask 'headline)) 0
|
||||
(plist-get info :ascii-inner-margin))
|
||||
(org-ascii--current-text-width inlinetask info)))))
|
||||
|
||||
@@ -1462,7 +1465,7 @@ CONTENTS holds the contents of the item. INFO is a plist holding
|
||||
contextual information."
|
||||
(let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8))
|
||||
(checkbox (org-ascii--checkbox item info))
|
||||
(list-type (org-element-property :type (org-export-get-parent item)))
|
||||
(list-type (org-element-property :type (org-element-parent item)))
|
||||
(bullet
|
||||
;; First parent of ITEM is always the plain-list. Get
|
||||
;; `:type' property from it.
|
||||
@@ -1479,11 +1482,11 @@ contextual information."
|
||||
(org-element-property :bullet item)))
|
||||
(num (number-to-string
|
||||
(car (last (org-list-get-item-number
|
||||
(org-element-property :begin item)
|
||||
(org-element-begin item)
|
||||
struct
|
||||
(org-list-prevs-alist struct)
|
||||
(org-list-parents-alist struct)))))))
|
||||
(replace-regexp-in-string "[0-9]+" num bul)))
|
||||
(replace-regexp-in-string "[0-9A-Za-z]+" num bul)))
|
||||
(_ (let ((bul (org-list-bullet-string
|
||||
(org-element-property :bullet item))))
|
||||
;; Change bullets into more visible form if UTF-8 is active.
|
||||
@@ -1604,9 +1607,9 @@ INFO is a plist holding contextual information."
|
||||
((guard desc)
|
||||
(if (plist-get info :ascii-links-to-notes)
|
||||
(format "[%s]" desc)
|
||||
(concat desc
|
||||
(format " (%s)"
|
||||
(org-ascii--describe-datum destination info)))))
|
||||
(format "[%s] (%s)"
|
||||
desc
|
||||
(org-ascii--describe-datum destination info))))
|
||||
;; External file.
|
||||
(`plain-text destination)
|
||||
(`headline
|
||||
@@ -1649,14 +1652,20 @@ information."
|
||||
"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."
|
||||
;; Ensure that we do not create multiple paragraphs, when a single
|
||||
;; paragraph is expected.
|
||||
;; Multiple newlines may appear in CONTENTS, for example, when
|
||||
;; certain objects are stripped from export, leaving single newlines
|
||||
;; before and after.
|
||||
(setq contents (org-remove-blank-lines contents))
|
||||
(org-ascii--justify-element
|
||||
(let ((indented-line-width (plist-get info :ascii-indented-line-width)))
|
||||
(if (not (wholenump indented-line-width)) contents
|
||||
(concat
|
||||
;; Do not indent first paragraph in a section.
|
||||
(unless (and (not (org-export-get-previous-element paragraph info))
|
||||
(eq (org-element-type (org-export-get-parent paragraph))
|
||||
'section))
|
||||
(org-element-type-p
|
||||
(org-element-parent paragraph) 'section))
|
||||
(make-string indented-line-width ?\s))
|
||||
(replace-regexp-in-string "\\`[ \t]+" "" contents))))
|
||||
paragraph info))
|
||||
@@ -1670,7 +1679,7 @@ CONTENTS is the contents of the list. INFO is a plist holding
|
||||
contextual information."
|
||||
(let ((margin (plist-get info :ascii-list-margin)))
|
||||
(if (or (< margin 1)
|
||||
(eq (org-element-type (org-export-get-parent plain-list)) 'item))
|
||||
(org-element-type-p (org-element-parent plain-list) 'item))
|
||||
contents
|
||||
(org-ascii--indent-string contents margin))))
|
||||
|
||||
@@ -1757,7 +1766,7 @@ contextual information."
|
||||
(let ((links
|
||||
(and (plist-get info :ascii-links-to-notes)
|
||||
;; Take care of links in first section of the document.
|
||||
(not (org-element-lineage section '(headline)))
|
||||
(not (org-element-lineage section 'headline))
|
||||
(org-ascii--describe-links
|
||||
(org-ascii--unique-links section info)
|
||||
(org-ascii--current-text-width section info)
|
||||
@@ -1766,7 +1775,7 @@ contextual information."
|
||||
(if (not (org-string-nw-p links)) contents
|
||||
(concat (org-element-normalize-string contents) "\n\n" links))
|
||||
;; Do not apply inner margin if parent headline is low level.
|
||||
(let ((headline (org-export-get-parent-headline section)))
|
||||
(let ((headline (org-element-lineage section 'headline)))
|
||||
(if (or (not headline) (org-export-low-level-p headline info)) 0
|
||||
(plist-get info :ascii-inner-margin))))))
|
||||
|
||||
@@ -1856,7 +1865,7 @@ contextual information."
|
||||
(cond ((eq (org-element-property :type table) 'org) contents)
|
||||
((and (plist-get info :ascii-table-use-ascii-art)
|
||||
(eq (plist-get info :ascii-charset) 'utf-8)
|
||||
(require 'ascii-art-to-unicode nil t))
|
||||
(org-require-package 'ascii-art-to-unicode nil 'noerror))
|
||||
(with-temp-buffer
|
||||
(insert (org-remove-indentation
|
||||
(org-element-property :value table)))
|
||||
@@ -1884,8 +1893,8 @@ column.
|
||||
|
||||
When `org-ascii-table-widen-columns' is non-nil, width cookies
|
||||
are ignored."
|
||||
(let* ((row (org-export-get-parent table-cell))
|
||||
(table (org-export-get-parent row))
|
||||
(let* ((row (org-element-parent table-cell))
|
||||
(table (org-element-parent row))
|
||||
(col (let ((cells (org-element-contents row)))
|
||||
(- (length cells) (length (memq table-cell cells)))))
|
||||
(cache
|
||||
@@ -2048,10 +2057,10 @@ contextual information."
|
||||
"Filter controlling number of blank lines after a headline.
|
||||
|
||||
HEADLINE is a string representing a transcoded headline. BACKEND
|
||||
is symbol specifying back-end used for export. INFO is plist
|
||||
is symbol specifying backend used for export. INFO is plist
|
||||
containing the communication channel.
|
||||
|
||||
This function only applies to `ascii' back-end. See
|
||||
This function only applies to `ascii' backend. See
|
||||
`org-ascii-headline-spacing' for information."
|
||||
(let ((headline-spacing (plist-get info :ascii-headline-spacing)))
|
||||
(if (not headline-spacing) headline
|
||||
@@ -2062,7 +2071,7 @@ This function only applies to `ascii' back-end. See
|
||||
"Filter controlling number of blank lines between paragraphs.
|
||||
|
||||
TREE is the parse tree. BACKEND is the symbol specifying
|
||||
back-end used for export. INFO is a plist used as
|
||||
backend used for export. INFO is a plist used as
|
||||
a communication channel.
|
||||
|
||||
See `org-ascii-paragraph-spacing' for information."
|
||||
@@ -2070,20 +2079,21 @@ See `org-ascii-paragraph-spacing' for information."
|
||||
(when (wholenump paragraph-spacing)
|
||||
(org-element-map tree 'paragraph
|
||||
(lambda (p)
|
||||
(when (eq (org-element-type (org-export-get-next-element p info))
|
||||
'paragraph)
|
||||
(when (org-element-type-p
|
||||
(org-export-get-next-element p info) 'paragraph)
|
||||
(org-element-put-property p :post-blank paragraph-spacing))))))
|
||||
tree)
|
||||
|
||||
(defun org-ascii-filter-comment-spacing (tree _backend info)
|
||||
"Filter removing blank lines between comments.
|
||||
TREE is the parse tree. BACKEND is the symbol specifying
|
||||
back-end used for export. INFO is a plist used as
|
||||
backend used for export. INFO is a plist used as
|
||||
a communication channel."
|
||||
(org-element-map tree '(comment comment-block)
|
||||
(lambda (c)
|
||||
(when (memq (org-element-type (org-export-get-next-element c info))
|
||||
'(comment comment-block))
|
||||
(when (org-element-type-p
|
||||
(org-export-get-next-element c info)
|
||||
'(comment comment-block))
|
||||
(org-element-put-property c :post-blank 0))))
|
||||
tree)
|
||||
|
||||
@@ -2098,6 +2108,8 @@ a communication channel."
|
||||
(let ((org-ascii-charset 'ascii))
|
||||
(org-export-replace-region-by 'ascii)))
|
||||
|
||||
(defalias 'org-export-region-to-ascii #'org-ascii-convert-region-to-ascii)
|
||||
|
||||
;;;###autoload
|
||||
(defun org-ascii-convert-region-to-utf8 ()
|
||||
"Assume region has Org syntax, and convert it to UTF-8."
|
||||
@@ -2105,6 +2117,8 @@ a communication channel."
|
||||
(let ((org-ascii-charset 'utf-8))
|
||||
(org-export-replace-region-by 'ascii)))
|
||||
|
||||
(defalias 'org-export-region-to-utf8 #'org-ascii-convert-region-to-utf8)
|
||||
|
||||
;;;###autoload
|
||||
(defun org-ascii-export-as-ascii
|
||||
(&optional async subtreep visible-only body-only ext-plist)
|
||||
|
||||
Reference in New Issue
Block a user