# Multi-Format Detection

> How jscpd detects duplicates across Svelte, Astro, Vue, and Markdown formats — vs other tools.

Component file formats (`.vue`, `.svelte`, `.astro`) and rich documents (`.md`) embed multiple languages in a single file — template, script, and style blocks in components; YAML frontmatter and fenced code blocks in markdown. A CPD tool's ability to parse these structures determines whether it can detect duplicates **within** each embedded language and **across** different file formats sharing the same code.

## Format Support Overview

<benchmark-cross-format>

## Cross-Format Detection (Svelte ↔ Astro)

The Svelte and Astro fixture components share ~60 lines of identical CSS and matching template structure. Only section-aware tools can attribute these matches to specific languages (CSS vs. markup vs. script).

<table>
<thead>
  <tr>
    <th>
      Tool
    </th>
    
    <th>
      Cross-Format Clones
    </th>
    
    <th>
      Lines
    </th>
    
    <th>
      Detail
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      jscpd-rs
    </td>
    
    <td>
      4
    </td>
    
    <td>
      235
    </td>
    
    <td>
      CSS (46 lines) + markup (7, 46, 136 lines)
    </td>
  </tr>
  
  <tr>
    <td>
      jscpd@4
    </td>
    
    <td>
      3
    </td>
    
    <td>
      189
    </td>
    
    <td>
      CSS (46 lines) + markup (7, 136 lines) + JS (28 lines)
    </td>
  </tr>
  
  <tr>
    <td>
      jscpd@5
    </td>
    
    <td>
      2
    </td>
    
    <td>
      53
    </td>
    
    <td>
      CSS (46 lines) + markup (7 lines)
    </td>
  </tr>
  
  <tr>
    <td>
      Duplo
    </td>
    
    <td>
      8
    </td>
    
    <td>
      92
    </td>
    
    <td>
      Raw text matches, no language attribution
    </td>
  </tr>
  
  <tr>
    <td>
      Simian
    </td>
    
    <td>
      1+
    </td>
    
    <td>
      —
    </td>
    
    <td>
      Aggregate text blocks, no language attribution
    </td>
  </tr>
  
  <tr>
    <td>
      PMD CPD
    </td>
    
    <td>
      0
    </td>
    
    <td>
      0
    </td>
    
    <td>
      Cannot detect cross-format duplicates
    </td>
  </tr>
  
  <tr>
    <td>
      Fallow
    </td>
    
    <td>
      0
    </td>
    
    <td>
      0
    </td>
    
    <td>
      JS/TS only
    </td>
  </tr>
</tbody>
</table>

## Markdown Embedded-Code Detection

`file3.md` and `file4.md` contain identical TypeScript and Python code blocks inside fenced code regions, plus matching YAML frontmatter. Section-aware tools detect these as separate language clones; flat-text tools match only the surrounding prose.

<table>
<thead>
  <tr>
    <th>
      Tool
    </th>
    
    <th>
      Detected Embedded Languages
    </th>
    
    <th>
      Clones
    </th>
    
    <th>
      Lines
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      jscpd@5
    </td>
    
    <td>
      TypeScript, Python, YAML, Markdown
    </td>
    
    <td>
      7
    </td>
    
    <td>
      356
    </td>
  </tr>
  
  <tr>
    <td>
      jscpd@4
    </td>
    
    <td>
      TypeScript, Python, YAML, Markdown
    </td>
    
    <td>
      7
    </td>
    
    <td>
      343
    </td>
  </tr>
  
  <tr>
    <td>
      jscpd-rs
    </td>
    
    <td>
      TypeScript, Python, YAML, Markdown, Coffeescript
    </td>
    
    <td>
      8
    </td>
    
    <td>
      350
    </td>
  </tr>
  
  <tr>
    <td>
      Duplo
    </td>
    
    <td>
      (flat text only)
    </td>
    
    <td>
      5
    </td>
    
    <td>
      195
    </td>
  </tr>
  
  <tr>
    <td>
      Simian
    </td>
    
    <td>
      (flat text only)
    </td>
    
    <td>
      4
    </td>
    
    <td>
      219
    </td>
  </tr>
  
  <tr>
    <td>
      PMD CPD
    </td>
    
    <td>
      —
    </td>
    
    <td>
      0
    </td>
    
    <td>
      0
    </td>
  </tr>
  
  <tr>
    <td>
      Fallow
    </td>
    
    <td>
      —
    </td>
    
    <td>
      0
    </td>
    
    <td>
      0
    </td>
  </tr>
</tbody>
</table>

## Key Findings

- **All jscpd variants** parse `.vue`, `.svelte`, `.astro`, and `.md` into separate language sections, detecting cross-format clones with language attribution. jscpd@5 is the most conservative, finding 2 cross-format clones (53 lines); jscpd@4 finds 3 (189 lines); jscpd-rs finds 4 (235 lines).
- **Simian and Duplo** find text overlaps between file types but report them as undifferentiated matches — there is no way to tell whether the duplication is in CSS, JavaScript, or template markup.
- **PMD CPD** cannot detect cross-format duplicates at all. It processes each language independently and has no concept of component file structure.
- **Fallow** only analyzes JS/TS, so it misses all CSS, template, and Markdown duplicates across formats.

## Methodology

- **Target:** `fixtures/` directory — 547 files, 21,645 lines across 150+ language formats
- **Within-format clones:** Duplicates detected within the same file type (e.g., Svelte→Svelte)
- **Cross-format clones:** Duplicates detected across different file types (e.g., Svelte↔Astro)
- **Embedded-code detection:** Duplicates found inside embedded language blocks within multi-language files
- **Hardware:** Apple Silicon (Darwin arm64)

Full methodology details are in the [jscpd repository](https://github.com/kucherenko/jscpd/blob/master/benchmark/BENCHMARK.md).

</benchmark-cross-format>
