Skip to content

feat(calendar): add an iCalendar (.ics) backend - #4880

Merged
ceberam merged 13 commits into
docling-project:mainfrom
DanielNg0729:feat/calendar-ics-backend
Nov 5, 2026
Merged

ceberam merged 13 commits into
docling-project:mainfrom
DanielNg0729:feat/calendar-ics-backend

Conversation

@DanielNg0729

Copy link
Copy Markdown
Member

Summary

Hi maintainers, Issue #327 asked for email and calendar formats. Email (.eml, .msg) is already supported, so this PR adds the calendar half, starting with iCalendar files.

No new dependency! The parser uses only the Python standard library.

Changes

  • Adds InputFormat.CALENDAR for .ics, .ical, .icalendar and .ifb (free/busy) files, with the text/calendar MIME type.
  • Detects a calendar file that has no known extension, for example one from a URL, by its first line BEGIN:VCALENDAR. A .txt file stays Markdown, as with the LaTeX check.
  • Adds CalendarDocumentBackend, CalendarFormatOption and CalendarBackendOptions. The options class extends TextBackendOptions, so the encoding override works as it does for Markdown, CSV and AsciiDoc.
  • Adds the docling/backend/calendar/ package:
    • parser.py reads content lines into a component tree. It handles quoted parameters, RFC 6868 caret escapes and TEXT escapes.
    • values.py makes dates, durations and recurrence rules readable.
    • render.py adds the tree to a DoclingDocument. It takes a parent and a heading level, so the email backend can reuse it later for meeting invitations.
  • Renders events, tasks, journal entries and free/busy times, with their attendees, reminders and attachment names. VTIMEZONE and X- properties are not rendered.
  • Updates the supported formats table, the README and the docs index.

Usage

A calendar file converts like any other input. The format is detected from the extension, or from the first line when there is no extension:

from docling.document_converter import DocumentConverter

result = DocumentConverter().convert("invite.ics")
print(result.document.export_to_markdown())
docling invite.ics --to md

For a file in an encoding that docling cannot detect, set the encoding as for Markdown or CSV files:

from docling.datamodel.backend_options import CalendarBackendOptions
from docling.datamodel.base_models import InputFormat
from docling.document_converter import CalendarFormatOption, DocumentConverter

converter = DocumentConverter(
    format_options={
        InputFormat.CALENDAR: CalendarFormatOption(
            backend_options=CalendarBackendOptions(encoding="cp1252")
        )
    }
)

Output

The body is flat, like the email backend's output: a heading for each entry, Key: value paragraphs, the description, and then lists. This is a shortened example from tests/data/calendar/sources/outlook_invite.ics:

Message type: Invitation

## Q4 budget review

Start: 2026-11-05 14:00 W. Europe Standard Time

End: 2026-11-05 15:30 W. Europe Standard Time

Organizer: "Martin, Carla" <[email protected]>

Conference: https://teams.microsoft.com/l/meetup-join/example

Hello all,

please review the Q4 budget before the meeting. The draft is attached.

### Attendees

- Dan Moreau <[email protected]> (required, awaiting response)
- Room Atlas <[email protected]> (resource, for information, accepted)

### Reminders

- Display, 15 minutes before start

### Attachments

- budget-draft.txt (text/plain)

I used plain paragraphs instead of key-value or field items, because the Markdown serializer and the chunkers output nothing for field regions.

Decisions you may want to change

  • Folded lines are joined on the bytes, before decoding. RFC 5545 (section 3.1) allows a fold inside a multi-byte UTF-8 character. If the text is decoded first, the file fails as damaged UTF-8, or the cp1252 fallback garbles the character. UTF-16 and UTF-32 files are decoded first.
  • Times are shown as written, with their TZID. There is no time-zone conversion and no recurrence expansion, so no time-zone database is needed.
  • All-day end dates are inclusive. An all-day DTEND is exclusive. Thus a one-day event shows one date, and an event from 24 December to 27 December shows "Start: 2026-12-24 (all day)" and "End: 2026-12-26 (all day)".
  • A recurrence rule is described in full or shown raw. If a rule has a part that the description does not cover, such as BYSETPOS or BYHOUR, the whole rule is shown raw. A partial description would state a different schedule.
  • Inline attachments are listed by name and type. Their base64 content is never decoded or copied.
  • A missing END does not hide the next entry. A BEGIN that the open component cannot contain closes that component first. Truncated files and stray END lines still convert.

Depends on docling-core

  • DocumentOrigin accepts only MIME types from the host table or from its own list, and CPython's built-in table has no text/calendar. CI passes without the core change, because Ubuntu has /etc/mime.types and importing the converter loads it. A host without that file rejects every calendar conversion. Code that loads the saved JSON with docling-core only, in a new process, also rejects it, even on a host that has the type. docling-project/docling-core#<CORE_PR> adds the type. Please merge this PR after that change is released. I will then raise the docling-core pin here.

  • docling-serve and the remote CLI default to list(InputFormat), so a server that runs an older docling rejects the new calendar value. The same thing happened when AFP and EBCDIC were added.
    I'll make a follow up after this. Thank you!

Issue resolved by this Pull Request:
Resolves #327

Checklist:

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

Read RFC 5545 content lines into a component tree with the standard
library only, make dates, durations and recurrence rules readable, and
add events, tasks, journal entries and free/busy times to a
DoclingDocument. The renderer takes a parent and a heading level, so
another backend can reuse it.

Signed-off-by: Daniel Nguyen <[email protected]>
Add InputFormat.CALENDAR for .ics, .ical, .icalendar and .ifb files,
CalendarDocumentBackend with its format and backend options, and a
content check on the first line, so a calendar without a known
extension is recognized. Folded lines are joined on the bytes before
decoding, because a fold may split a UTF-8 character.

Signed-off-by: Daniel Nguyen <[email protected]>
Synthetic Google, Outlook and Apple style calendars with reference
outputs, plus tests for folding, line endings, encodings, recovery
from a missing END, all-day and duration handling, recurrence rules,
alarms and format detection.

Signed-off-by: Daniel Nguyen <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @DanielNg0729, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 All 2 merge protections satisfied — ready to merge.

Show 2 satisfied protections

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

🟢 Require two reviewer for test updates

When test data is updated, we require two reviewers

  • #approved-reviews-by >= 2

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) enhancement New feature or request mimetype labels Oct 18, 2026
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit 1f1801f0d1. The analysis read the diff only. It did not run code from this pull request.

Adds a new CalendarDocumentBackend that converts iCalendar (.ics, .ical, .icalendar, .ifb) files into a DoclingDocument, using only the Python standard library. Registers InputFormat.CALENDAR with MIME type text/calendar and adds content-based detection from the BEGIN:VCALENDAR first line.

CI safety: no concern found. A maintainer must still approve CI.

Reference data changes

Change Files
added 12
  • added tests/data/calendar/groundtruth/apple_mixed.ics.itxt
  • added tests/data/calendar/groundtruth/apple_mixed.ics.json
  • added tests/data/calendar/groundtruth/apple_mixed.ics.md
  • added tests/data/calendar/groundtruth/google_export.ics.itxt
  • added tests/data/calendar/groundtruth/google_export.ics.json
  • added tests/data/calendar/groundtruth/google_export.ics.md
  • added tests/data/calendar/groundtruth/outlook_cancel.ics.itxt
  • added tests/data/calendar/groundtruth/outlook_cancel.ics.json
  • added tests/data/calendar/groundtruth/outlook_cancel.ics.md
  • added tests/data/calendar/groundtruth/outlook_invite.ics.itxt
  • added tests/data/calendar/groundtruth/outlook_invite.ics.json
  • added tests/data/calendar/groundtruth/outlook_invite.ics.md

Assessment: expected. The 12 added groundtruth files (JSON, Markdown, and indented-text exports for 4 new source .ics files) are exactly the reference output a new backend is required to ship, and they match the test inputs added in the same PR.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

@codecov

codecov Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI first review (advisory): no blocker found

This review covers the full diff at 56d534767e. It read the code and did not run it.

The pull request adds an iCalendar backend that parses .ics and .ifb files into DoclingDocument structures with standard library tools. We checked format detection, line unfolding across multi-byte character boundaries, date and recurrence rendering, and error handling for malformed components. The implementation integrates correctly with DocumentConverter and includes comprehensive regression tests.

A maintainer makes the merge decision. This review never approves the pull request.

@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Oct 18, 2026
docling-core 2.103.0 accepts text/calendar in DocumentOrigin without a
system MIME table. Raise the minimum in the three pins and lock 2.103.1;
only the docling-core entries of uv.lock change.

Signed-off-by: Daniel Nguyen <[email protected]>
@github-actions github-actions Bot added ai:ci-needs-care AI triage: check CI-safety findings before you approve CI and removed ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) labels Oct 21, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI first review (advisory): no blocker found

This review covers the changes since 56d534767e at 7b3cbef1fb. It read the code and did not run it.

We checked the incremental changes from the rebase onto the main branch for regressions and integration conflicts with the calendar backend.

A maintainer makes the merge decision. This review never approves the pull request.

@github-actions github-actions Bot added ai:review-lgtm AI first review found no blocker or major issue (advisory) and removed ai:ci-needs-care AI triage: check CI-safety findings before you approve CI ai:review-lgtm AI first review found no blocker or major issue (advisory) labels Oct 21, 2026
@DanielNg0729
DanielNg0729 requested a review from cau-git October 21, 2026 12:37
@DanielNg0729

Copy link
Copy Markdown
Member Author

Hi @PeterStaar-IBM, @dolfim-ibm and @cau-git, as docling-project/docling-core#892 is merged and released in docling-core 2.103.0. I have raised the docling-core minimum here and updated uv.lock, and merged main. When you have time, could you please review this PR? Thank you very much!

docling-core 2.103.0 no longer reads local image files unless the caller
opts in, so a JSON input converted with enable_local_fetch=True kept its
file references but failed on the first image export. Load them with
DoclingDocument.load_local_images(), the opt-in docling-core provides.

Signed-off-by: Daniel Nguyen <[email protected]>
docling-core 2.103.0 puts formatting tags inside the <p> element instead
of around it (docling-project/docling-core#879).

Signed-off-by: Daniel Nguyen <[email protected]>
@github-actions github-actions Bot added ai:ci-needs-care AI triage: check CI-safety findings before you approve CI and removed ai:ci-needs-care AI triage: check CI-safety findings before you approve CI labels Oct 21, 2026
@DanielNg0729

Copy link
Copy Markdown
Member Author

Hi @PeterStaar-IBM, thank you very much, Both failures came from the docling-core 2.103 upgrade that this PR needs, not from the calendar code: The test_local_image_uri_is_embedded_with_enable_local_fetch: docling-core 2.103.0 reads local image files only after an explicit opt-in (docling-project/docling-core#900). The JSON backend now calls DoclingDocument.load_local_images() when enable_local_fetch is set. Another thing is that test_e2e_docx_conversions: docling-core 2.103.0 puts formatting tags inside (docling-project/docling-core#879), so I updated 9 lines of docx_rich_cells.docx.html. CI is green now. Thank you very much!

PeterStaar-IBM
PeterStaar-IBM previously approved these changes Oct 22, 2026

@PeterStaar-IBM PeterStaar-IBM left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:ci-needs-care AI triage: check CI-safety findings before you approve CI labels Oct 23, 2026
@cau-git
cau-git requested a review from ceberam October 27, 2026 10:37

@ceberam ceberam left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @DanielNg0729 for this new feature!
The new backend implementation looks very robust and aligned to the other declarative backends. The amount and type of examples provided is just fine.

Not major concerns. Just minor observations about the code style.

Comment thread docling/backend/calendar_backend.py Resolved
Comment thread docling/backend/calendar_backend.py Resolved
Comment thread docs/usage/supported_formats.md Resolved
Comment thread docling/backend/calendar/values.py Resolved
Comment thread docs/index.md Resolved
Use `X | None` and `A | B` instead of typing.Optional and typing.Union in
the new calendar modules, annotate CalendarDocumentBackend.unload, and add
Google-style docstrings to the public classes and functions.

Signed-off-by: Daniel Nguyen <[email protected]>
@github-actions github-actions Bot removed the ai:ci-safe AI triage found no CI-safety concern (advisory) label Oct 29, 2026
@DanielNg0729

Copy link
Copy Markdown
Member Author

Thank you very much @ceberam for your review! I applied all your suggestions. Could you please have another look when you have time? Thank you!

@DanielNg0729
DanielNg0729 requested a review from ceberam October 29, 2026 05:17
@github-actions github-actions Bot added the ai:ci-safe AI triage found no CI-safety concern (advisory) label Oct 29, 2026
@DanielNg0729

Copy link
Copy Markdown
Member Author

Hi @ceberam @PeterStaar-IBM! Just following up on this PR. I've addressed all the suggestions from your previous review. When you have a chance, could you please take another look? Thank you very much!

@PeterStaar-IBM PeterStaar-IBM left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@ceberam
ceberam merged commit e461fa3 into docling-project:main Nov 5, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ci-safe AI triage found no CI-safety concern (advisory) enhancement New feature or request mimetype

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Standardized Access to Common Email and Calendar Formats

3 participants