tecosaur / org-glossary

Mirror of https://git.tecosaur.net/tec/org-glossary
GNU General Public License v3.0
91 stars 4 forks source link

References in unexported sections show up in the glossary #22

Open neuhalje opened 3 weeks ago

neuhalje commented 3 weeks ago

Observation

The following snippet, when exported with org-glossary enabled, will produce dead references in the result. Example with org-export-as-org.

#+title: test
#+OPTIONS: tasks:nil

This is a demonstration of a bug where references to non-exported elements show up in the acronyms/glossary

Expected: DEMO is only linked here

* TODO also hidden
This instance of DEMO should not show up in the glossary

* Not exported                                                                                                          :noexport:
This instance of DEMO should not show up in the glossary

* Glossary
- DEMO ::  mind that the export will also reference the hidden instances

Observed Export Result

#+options: tasks:nil
#+title: test
#+author: Jens Neuhalfen
This is a demonstration of a bug where references to non-exported elements show up in the acronyms/glossary

Expected:  (<<gr;37;1>>[[g;37][DEMO]]) is only linked here

* Glossary
- <<g;37>>DEMO :: mind that the export will also reference the hidden instances\ensp{}[[gr;37;1][1]], [[gr;37;2][2]], [[gr;37;3][3]]

After export [[gr;37;2][2]] and [[gr;37;3][3]] are dangling references.

Expected Export Result

#+options: tasks:nil
#+title: test
#+author: Jens Neuhalfen
This is a demonstration of a bug where references to non-exported elements show up in the acronyms/glossary

Expected:  (<<gr;37;1>>[[g;37][DEMO]]) is only linked here

* Glossary
- <<g;37>>DEMO :: mind that the export will also reference the hidden instances\ensp{}[[gr;37;1][1]]

After export only [[gr;37;1][1]] is referenced.

Analysis

The export settings will exclude the Not exported :noexport: section and the task from export.

Both the occurence of DEMO in the task and in the :noexport: section occur in the glosssary.

This also happens in PDF export.

Work around(?)

Not tried. But if first the document is exported with orrg->org and then run the glossary, the issue should be resolved.

tecosaur commented 2 weeks ago

Thanks, this is a very useful bug report. I have a feeling this may be a MWE for a problem I've been seeing myself.

I'll try to get to it sooner rather than later :)

neuhalje commented 1 week ago

The exporters :filter-parse-tree will be called with the hidden things already hidden.

(defun org-export--annotate-info (backend info &optional subtreep visible-only ext-plist)
;;...
    (setq tree
          (org-export-filter-apply-functions
           (plist-get info :filter-parse-tree) tree info))
;; ...

org-glossary--prepare-buffer gets called with the backend as a parameter. Maybe we could in org-glossary--prepare-buffer

  1. inject the glossary creation callback as :filter-parse-tree in the backend
  2. in the :filter-parse-tree callback "do the thing" via the API
  3. (optionally) self-remove the hook