PrismJS / PrismJS/prism

An unchanged diff line takes only the last selector reading, so a construct spanning into a deleted line renders half-highlighted

Open
#4,118 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
13k
Forks
1.4k
Avg merge
15h 36m
Merged PRs (30d)
3

Description

Introduced by #4110. unchanged and ! blocks are named in both of diff's selectors, and documents.reverse() plus the done set make the last selector claim them — so an unchanged line always takes the inserted document's reading.

A construct opening on an unchanged line and closing on a deleted one then gets its two halves from different documents.

Repro

import { createInstance } from './tests/helper/prism-loader.js';

const prism = await createInstance(['diff', 'javascript', 'clike', 'markup']);

console.log(prism.highlight(' const t = `hi\n-  there`;\n const x = 1;', 'diff:javascript'));
v2   [deleted [prefix -]  there`[punctuation ;]                    ← nothing highlighted
new  [deleted [prefix -][template-string [string   there][template-punctuation `]][punctuation ;]

The closing half is a template-string; the opening backtick one line up is plain text. A closing token with no opener.

This one looks inherent

An unchanged line is genuinely in both versions of the file, and the two versions can tokenize it differently. Last-wins, first-wins, longest-wins — every assignment rule picks one document and leaves the other half disagreeing. There is no choice that makes both readings coherent, because the line has two truths.

It is milder than #4117: the damage stops at that container and does not run on. The trade is "no information" (v2) against "wrong-looking information" (now).

If it is worth addressing

When two documents produce different tokens for the same shared container, leave that container untokenized instead of picking a winner. That restores the v2 rendering exactly where the ambiguity exists, keeps the new behaviour everywhere else, and needs no new public API — cheaper than the separator concept #4117 would want.

Worth doing, or acceptable as-is?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the diff language's selectors and the document comparison logic described in the issue, then reproduce the output with the provided JavaScript snippet. Determine how shared containers with conflicting tokenization are handled; done means the ambiguous container remains untokenized while unaffected diff highlighting is preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.