tecosaur / org-glossary

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

References in unexported sections show up in the glossary #22

Open neuhalje opened 5 months ago

neuhalje commented 5 months 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 5 months 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 5 months 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
tecosaur commented 4 months ago

:filter-parse-tree would be a good place to auto-apply terms (we can just use org-export-filter-parse-tree-functions), however org-glossary--prepare-buffer is rather based around operating on the org text content directly, before parsing, and changing that would be quite a bit of work.

I'm not sure when I'll have the time to do this, but as a quick fix I can check for :noexport: and COMMENT headings and ignore terms inside of them.

tecosaur commented 4 months ago

Demo

#+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

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

* COMMENT Also hidden
This instance of DEMO should not show up in the glossary

* TODO Not hidden

This instance of DEMO shows up, even though it shouldn't

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

Now exports to

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

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

As of bf0b72685342454c23104f455f63e0aaa70121f7