Skip to main content

develop-import-translator

Develop an import translator that parses a file format (JSON, XML, RIS, BibTeX, CSV, etc.) into Zotero items.

소스 정보

저장소
zotero/translators
최근 소스 활동
2026년 6월 1일 15:49
감지된 SKILL.md 언어
영어
스타
1,718
포크
925

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
develop-import-translator
description
Develop an import translator that parses a file format (JSON, XML, RIS, BibTeX, CSV, etc.) into Zotero items.
## Prerequisites Fetch and read the Zotero translator documentation: - https://www.zotero.org/support/_export/raw/dev/translators - https://www.zotero.org/support/_export/raw/dev/translators/coding Also read `index.d.ts` for type definitions. ## Step 1: Gather information 1. **Label**: The format name (e.g. "My Custom JSON") 2. **Creator**: The author's name 3. **Example data**: A sample of the format to import Look for existing import translators that handle similar formats: ``` grep -l "detectImport\|doImport" *.js ``` ## Step 2: Initialize ``` node .bin/init-translator.mjs --label "<Label>" --creator "<Creator>" --type import ``` This scaffolds the file from the import translator template at `.bin/templates/import.js`. That file is the canonical structure an import translator should follow — read it when you need to know the expected shape of `detectImport`/`doImport`, or when a task asks you to make an existing translator better conform to the template. If the translator should also export the same format, use `--type import,export` and implement `doExport()` as described in the `develop-export-translator` skill. Import translators have no `target` regex — they match on content via `detectImport()`. ## Step 3: Write the code ### `detectImport()` Read the first few lines with `Zotero.read()` and return `true` if the format matches. Be specific to avoid false positives with other formats. ```js function detectImport() { let start = ''; for (let i = 0; i < 10; i++) { let line = Zotero.read(); if (line === false) break; start += line; } // Check for a distinctive marker in the format return start.includes('"my_format_version"'); } ``` ### `doImport()` Read the full input, parse it, and create items. ```js async function doImport() { // Read all input let text = ''; let line; while ((line = Zotero.read()) !== false) { text += line; } let data = JSON.parse(text); for (let record of data.records) { let item = new Zotero.Item('journalArticle'); item.title = record.title; item.date = record.date; for (let author of record.authors) { item.creators.push({ firstName: author.first, lastName: author.last, creatorType: 'author', }); } // ... map other fields ... item.complete(); } } ``` Key APIs: - `Zotero.read(length)` — read characters from input. Returns `false` at EOF. With no argument, reads one line. - `new Zotero.Item(itemType)` — create an item. Set fields as properties, then call `.complete()`. - For XML: `(new DOMParser()).parseFromString(text, 'text/xml')` - For line-based formats (RIS, BibTeX): read and parse line by line. ## Step 4: Create tests ``` node .bin/create-test.mjs "<Label>.js" --input '<paste example data here>' ``` ## Step 5: Verify and submit **Update `lastUpdated` every time you modify translator code.** ``` node .bin/update-metadata.mjs "<Label>.js" npm run lint -- "<Label>.js" node .bin/run-tests.mjs "<Label>.js" ```
GitHub에서 보기