Generate anchor_ids for all block types, not just headings #120
No reviewers
Labels
No labels
domain:backend
domain:devops
domain:frontend
status:approved
status:in-progress
status:needs-fix
status:qa
type:bug
type:devops
type:feature
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
forgejo_admin/pal-e-api!120
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "119-block-anchor-ids"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Non-heading blocks (paragraph, list, table, code, mermaid) now receive deterministic anchor_ids using the format
{block_type}-{position}(e.g.,paragraph-3,list-7), making them addressable via block API endpoints. Headings retain their existing slugified text anchors. Includes Alembic migration to backfill existing null anchor_ids and add a unique constraint on(note_id, anchor_id).Changes
src/pal_e_docs/blocks/parser.py-- Generate{block_type}-{position}anchor_ids for non-heading blocks inparse_html_to_blocks(). Bare text nodes and fallback elements also get position-based anchors.src/pal_e_docs/models.py-- AddUniqueConstraint("note_id", "anchor_id")to Block model. ImportUniqueConstraintfrom SQLAlchemy.alembic/versions/k1f2g3h4i5j6_add_block_anchor_ids_and_unique_constraint.py-- New migration: backfills null anchor_ids withblock_type || '-' || position, then adds unique constraint on(note_id, anchor_id).tests/test_block_parser.py-- AddedTestAnchorIdGenerationclass (12 tests) covering all block types, uniqueness, idempotency, and position-based anchors. Updated existing assertions fromanchor_id is Noneto expected values.tests/test_backfill.py-- Updated assertions for paragraph and list block anchor_ids.Test Plan
pytest tests/ -v)Review Checklist
Related
todo-block-anchor-idsNon-heading blocks (paragraph, list, table, code, mermaid) now receive deterministic anchor_ids using the format {block_type}-{position}, making them addressable via the block API endpoints. Headings retain their existing slugified text anchors. Includes Alembic migration to backfill existing null anchor_ids and add a unique constraint on (note_id, anchor_id). Closes #119 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>The create_block API endpoint only auto-generated anchor_ids for heading blocks, leaving non-heading blocks with anchor_id=None. This was inconsistent with the parser's guarantee that all blocks have anchors. Non-heading blocks now get anchor_ids using the {block_type}-{position} pattern with uniqueness checking, matching the parser convention. Closes #119 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>