Lukas Epple <em...@lukasepple.de> writes:

> If we are using HTML5 (<!doctype html>) to export, we are entitled to 
> use the <time> element [1] [2] which allows attaching a machine readable 
> date, time, datetime or duration to text. Consequently, I propose that 
> we change the rendering to something like the following if the user sets 
> org-html-doctype to use HTML5:
>
>      <span class="timestamp-wrapper">
>      <time class="timestamp" datetime="2025-01-31">[2025-01-31 Fri]
>      </time></span>

I see no downside doing this as long as user enables `org-html-html5-fancy'.

> * Proposed Implementation
>
> I would be happy to write the patch myself, but I figured I'd ask for
> feedback on the idea and some pointers first, especially since I've not
> yet assigned my copyright to the FSF. I've attached an (undocumented)
> proof of concept which implements this change for org-html-timestamp
> only (by overriding the function using advice-add).

Check out https://orgmode.org/worg/org-contribute.html#first-patch where
we list contribution guidelines and details on how to deal with
copyright assignment.

> As far as I can see, a concrete implementation could be achieved in the 
> following steps:
>
> 1) Add a new pair of timestamp formats to ox-html which are HTML
> compatible (i.e. ISO8601), e.g. '("%F" . "%FT%T%z").
>
> 2) Add a new function that handles rendering everything inside the
> timestamp-wrapper span (in my code, it is called le-org-html-format-
> timestamp). This function would be used by org-html-timestamp, org-html-
> planning and org-html-clock.
>
> It would switch between <span> and <time> based on org-html-html5-p. If
> HTML5, the datetime attribute is added based on the format from 1) via 
> org-format-timestamp. For the text inside the element, 
> org-timestamp-translate would be used in all cases, like before.

Better use `org-html--html5-fancy-p'.

> 3) For the duration part of org-html-clock we need to render a supported
> duration string (see [2]) inside the datetime (!) attribute. As far as I 
> know, there are no existing facilities to render a compatible output. It 
> shouldn't be difficult to write a function similar to 
> le-org-html-format-timestamp for durations. The formatted string would 
> probably need to be generated based on org-duration-to-minutes.

Sounds reasonable.

> ** Open Questions
>
> 1) In the example above, I've used an RFC3339 format string which
> includes the local time zone. Since I've written that code, I've become
> somewhat convinced that we should not include the timezone (at least not
> by default). While it is nice that this would actually make the
> timestamp fully determinate, timestamps in org files don't have the
> ability to prescribe the timezone, so the system time zone is used. As a
> result, exporting the same org file on machines with different time zone
> settings would reduce in HTML export that references different points in
> time.

Just make the timestamp format customizeable.
As for different timezone settings - Org implicitly uses current
timezone, so it is not an error to include it.

> 2) It also occurred to me that including the timezone would leak the
> user's timezone settings without them necessarily noticing. Browsers
> usually don't display the datetime attribute to users anywhere.

If you make the format customizeable, do not put timezone it in by
default, and leave the version with timezone as one of the available
custom options, it should be good enough.

> This got me wondering about a hypothetical scenario where a user
> deliberately uses org-display-custom-times to reduce the precision of
> timestamps in the output. With my proposed change, the full precision
> timestamp would still be recoverable via the datetime attribute. If the
> user were to do this for increased privacy, it would be problematic.

Again, custom format will work.
If users want to take full control of timestamp formatting, they have
many other mechanisms provided by Org export. Starting from export
filters, to writing a derived backend.

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