Skip to content
Open
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
22 changes: 8 additions & 14 deletions frontend/apps/cli/src/commands/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import {resolveKey} from '../utils/keyring'
import {resolveIdWithClient} from '../utils/resolve-id'
import {createSignerFromKey} from '../utils/signer'
import {resolveDocumentState} from '../utils/depth'
import {parseMarkdown, flattenToOperations, type BlockNode} from '../utils/markdown'
import {parseMarkdown} from '../utils/markdown'
import {parseBlocksJson, hmBlockNodesToOperations} from '../utils/blocks-json'
import {createBlocksMap, computeReplaceOps, hmBlockNodeToBlockNode, type APIBlockNode} from '../utils/block-diff'
import {createBlocksMap, computeReplaceOps, type APIBlockNode} from '../utils/block-diff'
import {resolveFileLinks} from '../utils/file-links'
import type {HMBlockNode, HMDocument, HMMetadata} from '@seed-hypermedia/client/hm-types'

Expand Down Expand Up @@ -96,7 +96,7 @@ export type ParsedInput = {
ops: DocumentOperation[]
metadata: HMMetadata
fileBlobs: CollectedBlob[]
tree?: BlockNode[] // parsed block tree for smart diffing in update
tree?: HMBlockNode[] // parsed block tree for smart diffing in update
blocks?: HMBlockNode[] // for dry-run rendering
source?: string // extraction method label
}
Expand Down Expand Up @@ -180,22 +180,16 @@ export async function readInput(options: {file?: string; grobidUrl?: string; qui
ops: hmBlockNodesToOperations(nodes),
metadata: {},
fileBlobs: resolved.blobs,
tree: nodes.map(hmBlockNodeToBlockNode),
tree: nodes,
}
}

// ── Markdown path ──
const {tree, metadata} = parseMarkdown(content!)
const ops = flattenToOperations(tree)
const {tree: hmNodes, metadata} = parseMarkdown(content!)
const resolved = await resolveFileLinks(hmNodes)
const ops = hmBlockNodesToOperations(resolved.nodes)

// Resolve file:// links in the tree (images with local paths)
// We need to convert BlockNode tree back through operations,
// but file:// links are in the operations already via the link field.
// For now, file:// resolution only applies to JSON blocks input.
// Markdown images get file:// prepended at tokenizer level and will
// be resolved when we add block-level file link resolution.

return {ops, metadata, fileBlobs: [], tree}
return {ops, metadata, fileBlobs: resolved.blobs, tree: resolved.nodes}
}

export function registerDocumentCommands(program: Command) {
Expand Down
5 changes: 3 additions & 2 deletions frontend/apps/cli/src/test/fixture-seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
FIXTURE_REGISTRATION_SECRET,
} from '../../../../../test-fixtures/minimal-fixtures'
import {deriveKeyPairFromMnemonic} from '../utils/key-derivation'
import {flattenToOperations, parseMarkdown} from '../utils/markdown'
import {parseMarkdown} from '../utils/markdown'
import {hmBlockNodesToOperations} from '../utils/blocks-json'
import {createDocumentUpdate, registerAccount, type TestAccount} from './account-helpers'

const fixtureKeyPair = deriveKeyPairFromMnemonic(FIXTURE_ACCOUNT_MNEMONIC, '')
Expand Down Expand Up @@ -41,7 +42,7 @@ export async function seedTestFixtures(serverUrl: string): Promise<void> {
type: 'SetAttributes',
attrs: [{key: ['name'], value: FIXTURE_HIERARCHY_TITLE}],
},
...flattenToOperations(tree),
...hmBlockNodesToOperations(tree),
])
}

Expand Down
Loading
Loading