Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions crates/apple-note/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# apple-note

A Rust library for parsing Apple Notes protobuf data, extracting text content, and handling embedded objects like tables.

## Credits

This crate is a Rust port of [apple_cloud_notes_parser](https://github.com/threeplanetssoftware/apple_cloud_notes_parser) by [Three Planets Software](https://github.com/threeplanetssoftware). The original Ruby implementation provides comprehensive parsing of Apple Notes data from iOS and macOS backups.

The test suite in this crate follows the structure and test cases from the original Ruby implementation's spec directory to ensure compatibility and correctness.

## Features

- Parse Apple Notes protobuf data (gzipped and uncompressed)
- Extract plaintext and formatted text spans from notes
- Handle various text formatting (bold, italic, underline, strikethrough, links, colors)
- Parse embedded tables with support for RTL languages
- Detect and classify embedded object types (images, drawings, PDFs, audio, video, etc.)
- Convert notes to Markdown format

## Usage

```rust
use apple_note::{parse_note_store_proto, note_to_markdown, extract_plaintext};

// Parse a note from gzipped protobuf data
let data = std::fs::read("note_data.bin")?;
let proto = parse_note_store_proto(&data)?;

// Extract plaintext
let text = extract_plaintext(&proto.document.note);

// Convert to markdown
let markdown = note_to_markdown(&proto.document.note);
```

## Test Data

The test data files in `tests/data/` are derived from the test fixtures in the original apple_cloud_notes_parser repository.

## License

See the repository root for license information.
8 changes: 8 additions & 0 deletions crates/apple-note/tests/attribute_run_tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
//! AttributeRun tests
//!
//! These tests correspond to the AttributeRun tests in the apple_cloud_notes_parser Ruby implementation:
//! https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/spec/base_classes/proto_patches.rb
//!
//! Tests cover style comparison between attribute runs, including font weight, underlined,
//! strikethrough, superscript, link, paragraph style, font, and color comparisons.

use apple_note::{AttributeRun, Color, Font, ParagraphStyle};

#[test]
Expand Down
7 changes: 7 additions & 0 deletions crates/apple-note/tests/color_tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//! Color tests
//!
//! These tests correspond to the Color tests in the apple_cloud_notes_parser Ruby implementation:
//! https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/spec/base_classes/proto_patches.rb
//!
//! Tests cover hex string generation for RGB color values.

use apple_note::Color;

#[test]
Expand Down
8 changes: 8 additions & 0 deletions crates/apple-note/tests/embedded_tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
//! Embedded object tests
//!
//! These tests correspond to the embedded object and UTI tests in the apple_cloud_notes_parser Ruby implementation:
//! - https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/spec/utilities/apple_uniform_type_identifier.rb
//! - https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/spec/embedded_objects/embedded_objects.rb
//!
//! Tests cover UTI type detection, embedded object extraction, and type classification.

use apple_note::{EmbeddedObjectType, extract_embedded_objects};

#[test]
Expand Down
15 changes: 15 additions & 0 deletions crates/apple-note/tests/parser_tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
//! Parser tests
//!
//! These tests correspond to the AppleNote tests in the apple_cloud_notes_parser Ruby implementation:
//! https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/spec/base_classes/apple_note.rb
//!
//! Tests cover:
//! - Note parsing (simple notes, compressed/uncompressed)
//! - Text decorations (bold, italic, underline, strikethrough)
//! - Block quotes and list indents
//! - URL/link formatting
//! - Color formatting
//! - Emoji and wide character handling
//! - HTML content escaping
//! - Various heading and style types

use apple_note::{note_to_markdown, parse_note_store_proto};
use std::fs;

Expand Down
9 changes: 9 additions & 0 deletions crates/apple-note/tests/proto_tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
//! Proto type tests
//!
//! These tests correspond to the proto_patches tests in the apple_cloud_notes_parser Ruby implementation:
//! https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/spec/base_classes/proto_patches.rb
//!
//! Tests cover Color hex string generation and AttributeRun style comparison.
//! Note: Some tests in this file overlap with color_tests.rs and attribute_run_tests.rs
//! for additional coverage of the proto module types.

use apple_note::proto::{AttributeRun, Color, Font, ParagraphStyle};

#[cfg(test)]
Expand Down
7 changes: 7 additions & 0 deletions crates/apple-note/tests/table_tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//! Table tests
//!
//! These tests correspond to the table tests in the apple_cloud_notes_parser Ruby implementation:
//! https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/spec/embedded_objects/tables.rb
//!
//! Tests cover table parsing, reconstruction, row ordering, RTL table support, and output generation.

use apple_note::{parse_mergable_data_proto, table::Table, table::parse_table};
use std::fs;

Expand Down
10 changes: 10 additions & 0 deletions crates/apple-note/tests/text_extraction_tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
//! Text extraction tests
//!
//! These tests correspond to the content extraction tests in the apple_cloud_notes_parser Ruby implementation:
//! https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/spec/base_classes/apple_note.rb
//!
//! Tests cover:
//! - Plaintext extraction from notes
//! - Text span extraction with formatting attributes
//! - Handling of attachments during extraction

use apple_note::{
AttributeRun, Note, ParagraphStyle,
extract::{TextSpan, extract_plaintext, extract_text_spans},
Expand Down
10 changes: 10 additions & 0 deletions crates/apple-note/tests/utils_tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
//! Utility function tests
//!
//! These tests correspond to the helper tests in the apple_cloud_notes_parser Ruby implementation:
//! https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/spec/base_classes/apple_note.rb
//!
//! Tests cover:
//! - Core time to Unix time conversion (convert_core_time in Ruby)
//! - GZIP detection (is_gzip in Ruby)
//! - GZIP decompression

use apple_note::utils::{core_time_to_unix, decompress_gzip, is_gzip};
use std::fs;

Expand Down
Loading