Support new lines in description

Created on 28 March 2024, 3 months ago
Updated 29 March 2024, 3 months ago

Problem/Motivation

The description property/field does not support the ICS syntax for a new line (\n). If you have a field that is already formatted for use in an ICS file, that has HTML stripped and uses \n, and you use that as the token for the description field, the generated ICS file escapes all new lines like this: \\n. Calendar apps then interpret this literally as "\\n". From what I've seen, the only reliable way to get line breaks in an ICS file description is to use \n, because not all calendar apps support HTML.

I've dug into it, and this is mostly a problem with the eluceo/ical library (or the older version of the library we're using). There's an issue for it here: https://github.com/markuspoerschke/iCal/issues/62

Apparently it may be resolved in the 2.x version of the library, but I imagine upgrading would be a pain.

I'm going to attach a patch to ics_field, and a patch to eluceo/ical to work around the issue. I don't think it's worth opening a PR on the eluco/ical repo since the version is so outdated that I imagine they would never commit it. Unfortunately because of the patch to the library, I also imagine the patch to ics_field module will never be committed either. Still I wanted to share this in case it's helpful for somebody else.

Steps to reproduce

  1. Create a long plain text field on same content type you have a calendar download field.
  2. Create a node of that content type...
  3. Set value of new field to:
    Join remotely:\n\nThis is some info about the remote location. It is a link (https://www.google.com/).\n\n\n\n\n\n-------------\n\nDetails:\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. \n\n\n\n\n\n-------------\n\nMore information:\n\nhttps://ohsuo2.lndo.site/events/test-event-2\n\n
    
  4. Set value of calendar download field description to token for new field.
  5. Save.
  6. Click link to download ICS file.
  7. Import the ICS file into any calendar app. Notice that you don't see new lines, instead you see "\\n".

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States maskedjellybean Portland, OR

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @maskedjellybean
  • πŸ‡ΊπŸ‡ΈUnited States maskedjellybean Portland, OR

    Attaching patches. Be sure to apply ical-make-description-escaping-optional.patch to eluceo/ical, not drupal/ics_field.

    After following the Steps to reproduce, and then applying the patches, you can verify they work by doing this:

    1. Resave node to trigger regenerating of ICS file.
    2. Click link to download ICS file.
    3. Import the ICS file into any calendar app. You should see new lines instead of "\\n".
  • πŸ‡ΊπŸ‡ΈUnited States maskedjellybean Portland, OR
  • πŸ‡ΊπŸ‡ΈUnited States maskedjellybean Portland, OR

    Realized that this was not working in Outlook. This new patch fixes that. It does a more generic check for HTML in the description. If there is HTML, it runs html2text and calls $iCalendarEvent->setDescription($this->getCalendarProperty('description')) with escaping enabled. If there is no HTML it calls $iCalendarEvent->setDescription($this->getCalendarProperty('description'), FALSE) with escaping disabled and calls $iCalendarEvent->setDescriptionHTML('') in order to set it to an empty string. This last piece is what fixes the Outlook compatibility.

    Also, in order to make this work in Outlook you will need the patch from https://www.drupal.org/project/ics_field/issues/2946641#comment-15523825 ✨ Support date_recur field type. Active , because the module as it stands currently (with no patches applied) is not compatible with Outlook. Somehow I stumbled on a fix for Outlook in that otherwise unrelated patch.

Production build 0.69.0 2024