Re: ISSUE: org publish document processor silently inserts licensed content into targets by default

2020-05-26 Thread Anthony Carrico
On 5/22/20 11:10 AM, Bastien wrote:
> If you think it is useful as a patch against Org, not just as a way to
> customize a setup, can you send a patch?
> 
> See https://orgmode.org/worg/org-contribute.html on how to contribute.

Ok, it is on my list, thanks.

-- 
Anthony Carrico




Re: ISSUE: org publish document processor silently inserts licensed content into targets by default

2020-05-22 Thread Bastien
Hi Anthony,

Anthony Carrico  writes:

> ISSUE: An author should expect a compiler to avoid claiming authorship
> over target code, however, currently the org-mode publish document 
> processor silently inserts licensed content into target documents by
> default.
>
> SOLUTION: The following script is a drop-in-replacement which provides
> the same API as the original, without a license. It also opts not to 
> highlight code links, but only their targets, which seems less
> distracting (it is a simple change to keep the original behavior if 
> preferred).

If you think it is useful as a patch against Org, not just as a way to
customize a setup, can you send a patch?

See https://orgmode.org/worg/org-contribute.html on how to contribute.

Thanks,

-- 
 Bastien



ISSUE: org publish document processor silently inserts licensed content into targets by default

2020-05-18 Thread Anthony Carrico
ISSUE: An author should expect a compiler to avoid claiming authorship 
over target code, however, currently the org-mode publish document 
processor silently inserts licensed content into target documents by 
default.


SOLUTION: The following script is a drop-in-replacement which provides 
the same API as the original, without a license. It also opts not to 
highlight code links, but only their targets, which seems less 
distracting (it is a simple change to keep the original behavior if 
preferred).


The public domain version works in a different way than the original, 
fixing a potential bug. It adds(removes) highlighting rather than 
replacing the original format. Ignoring the boilerplate, the new script is:


  target.classList.add("code-highlighted")

The add method is idempotent. In contrast, the old version caches(restores):

  elem.cacheClassTarget = target.className;
  target.className = "code-highlighted";

Note that the cached value would be lost if this was called twice in 
succession.


I've added the comment, "any content added to the source document by the 
document processor, including this script, is in the public domain". 
This statement may seem superfluous, since an author should expect the 
compiler to avoid claiming authorship over target code anyway. I've only 
added it in contrast with the original claim.


Assuming the org-mode authors agree with the goal of publish acting as 
pure compiler, and if it seems more appropriate not to pass the notice 
through to the target html, then feel free to remove this notice from 
the org-html-scripts definition, perhaps retaining it above the 
definition as an as an elisp comment and/or as a note in the documentation.


One last note: users can attempt to fix this issue by disabling 
:html-head-include-scripts, but doing so will provoke an error when a 
reader's browser attempts to highlight links to source code literal 
lines, so it is probably better to patch the script.


Anyway here is my patch, you can adapt it to your emacs init, or call it 
from the command line as "emacs --batch -l publish".


I declare that this patch is in the public domain.

Enjoy.

;;; publish.el --- publish project with org publish -*- lexical-binding: 
t; -*-


;; To use this from the shell:
;;
;; emacs --batch -l publish

(require 'org)
(require 'ox-publish)

(defconst public-domain-scripts
"
 /* Any content added to the source document by the document
 processor, including this script, are in the public domain */
 function CodeHighlightOn(elem, id)
 {
   const target = document.getElementById(id);
   if(null != target) {
 target.classList.add(\"code-highlighted\");
   }
 }
 function CodeHighlightOff(elem, id)
 {
   const target = document.getElementById(id);
   if(null != target) {
 target.classList.remove(\"code-highlighted\");
   }
 }
")

;; patch globally:
(setq org-html-scripts public-domain-scripts)
(org-publish-all)

;; or patch locally:
;;
;; (let ((org-html-scripts public-domain-scripts)) (org-publish-all))

--
Anthony Carrico