"Jacob S. Gordon" <[email protected]> writes:

> ...  I’m not particularly happy with all the repetition
> transcoding links, but nothing unifying jumped out at me.  The backend
> is now registered as ‘strip-markup’ so that others can extend it.

You can map over org-element-all-elements/org-element-all-objects and
use the same transcoder that will (1) examine CONTENTS passed to the
transcoder; (2) if it is nil, check :value property. That will constitute
internal export backend. Then, you can create a derived backend that
will do more specific transcoding for individual object types we care about.

> | element          | markup                     | stripped              |
> |------------------+----------------------------+-----------------------|
> | emphasis         | *b* /i/ ~c~ =v= _u_ +s+    | b i c v u +s+         |
> | latex-fragment   | $x^2$ \(y^2\)              | $x^2$ \(y^2\)         |
> | inline-src-block | src_emacs_lisp{#'identity} | #'identity            |
> | sub/supersript   | a^b c_d                    | a^b c_d               |
> | timestamp        | [2025-12-31 Wed]           | [2025-12-31 Wed]      |
> | radio-target     | <<<radio>>>                | radio                 |
> | export-snippet   | @@html:text@@              | text                  |
> | link             | [[id:custom-id]]           | 1.1                   |
> |                  | [[#custom-id]]             | 1.1                   |
> |                  | [[*Heading]]               | 1.1                   |
> |                  | [[target]]                 | 1.1                   |
> |                  | [[link][description]]      | description           |
> |                  | https://orgmode.org        | <https://orgmode.org> |
> |                  | [[news:comp.emacs]]        | <news:comp.emacs>     |
> | link (HTML)      | [[./file.org]]             | <file.html>           |
> |                  | [[file:./file.org]]        | <file.html>           |
> |                  | [[file:./file.org.gpg]]    | <file.html>           |
>
> AFAICT, ‘footnote-references’ and ‘diary-sexps’ are always inserted
> verbatim.  Am I missing anything else that makes sense in a title?

Entities are missing, I think.

> +*** New option ~org-html-strip-title-tag-markup~
> +
> +By default, markup such as =*bold*= in the document title will make it
> +into the HTML =<title>= tag.  A non-nil ~org-html-strip-title-tag-markup~
> +will force this markup to be stripped.

Maybe we can make the stripping backend customizable by users.

> +(org-export-define-derived-backend 'html-strip-markup 'strip-markup
> +  :translate-alist '((link . org-html-strip-link-markup)))

I think we better use a variable (or defcustom) here, so that users can
re-assign to something custom.

> +(defun org-html-strip-link-markup (link desc info)
> +  "Transcoder that strips Org markup from a LINK object.
> +This accounts for `org-html-link-org-files-as-html' and publishing
> +settings for file links, and falls back to `org-export-strip-link-markup'
> +otherwise."
> +  (if (string= "file" (org-element-property :type link))
> +      (let* ((link-path (org-element-property :path link))
> +             (raw-path
> +              ;; Convert paths relative to publishing directory.
> +              (org-export-file-uri (org-publish-file-relative-name
> +                                    link-path info)))
> +             ;; Maybe convert ".org" -> ".html".
> +             (link-org-as-html
> +              (plist-get info :html-link-org-files-as-html))
> +             (html-ext (plist-get info :html-extension))
> +             (dot (when (> (length html-ext) 0) "."))
> +             ;; Maybe append `:html-link-home' to relative file name.
> +             (link-home (and (plist-get info :html-link-home)
> +                             (org-trim (plist-get info :html-link-home))))
> +             (append-link-home (and link-home
> +                                    (plist-get info :html-link-use-abs-url)
> +                                    (not (file-name-absolute-p raw-path))))
> +             ;; Maybe add search option.
> +             (search-option (org-element-property :search-option link)))

This is copy-paste from `org-html-link', right? It is probably better to
factor out the common code into a helper function.

> +;;;; For Stripping Markup
> +;;
> +;; The `strip-markup' backend removes Org markup from text.  All
> +;; emphasis markers are removed except for strike-through, as that
> +;; could change the meaning or create ambiguous text.  LaTeX
> +;; fragments, subscripts, and superscripts are inserted verbatim.  The
> +;; text of inline source blocks and radio targets are used.  Links are
> +;; transcoded acording to `org-export-strip-link-markup'.  Timestamps
> +;; and ranges are inserted according to `org-timestamp-translate'.
> +;; Other objects are not transcoded.
> +;;
> +;; `org-export-strip-markup' transcodes some Org elements to plain
> +;; text without markup using the `strip-markup' backend.
> +;;
> +;; `org-export-strip-link-markup' is the transcoder for links.
> +
> +(org-export-define-backend 'strip-markup

Same thing here. Maybe it is better to keep the backend in a variable.

> +    (latex-fragment . (lambda (f _ i)
> +                        (when (plist-get i :with-latex)
> +                          (org-element-property :value f))))

Why do you need :with-latex? `org-export--remove-uninterpreted-data'
should handle this export option.

> +(defun org-export-strip-link-markup (link desc info)
> +  "Strip markup from the LINK with DESC.
> +Link descriptions are preferred, followed by the ASCII export of the
> +link, with the raw link in angled brackets `<like this>' as a fallback."

I think we should not use ASCII export. For stripping, users can provide
dedicated export function for 'strip backend.

> +  (let ((type (org-element-property :type link)))
> +    (cond
> +     ;; prefer link descriptions
> +     ((or (org-string-nw-p desc) (string= type "radio")) desc)
> +     ((string= type "coderef")
> +      (let ((ref (org-element-property :path link)))
> +        (format (org-export-get-coderef-format ref desc)
> +                (org-export-resolve-coderef ref info))))
> +     ((member type '("custom-id" "fuzzy" "id"))
> +      (let ((dest (if (string= type "fuzzy")
> +                      (org-export-resolve-fuzzy-link link info)
> +                    (org-export-resolve-id-link link info))))
> +        (pcase (org-element-type dest)
> +          ;; points nowhere
> +          (`nil (format "<%s>" (org-element-property :raw-link link)))
> +          (`plain-text dest)
> +          (`headline
> +           (if (org-export-numbered-headline-p dest info)
> +               (mapconcat #'number-to-string
> +                          (org-export-get-headline-number dest info)
> +                          ".")
> +             (org-export-data (org-element-property :title dest) info)))
> +          ((and (let num (org-export-get-ordinal
> +                          dest info nil
> +                          #'(lambda (e _) (org-element-property :caption 
> e))))
> +                (guard num))
> +           (if (atom num)
> +               (number-to-string num)
> +             (mapconcat #'number-to-string num ".")))
> +          (_ "???"))))

I think we should not make assumptions about headline numbering. It
might get rather complex for some backends. I'd favor more simplistic approach.

-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

Reply via email to