Skip to content

Conversation

@alasdairwilson
Copy link

@alasdairwilson alasdairwilson commented Nov 28, 2025

I had discovered an issue where TOML table header parsing had undesired behaviour where table declarations like [table] and [[array]] were being split across multiple tokens, creating split spans when parsed. The bug was actually, for me, in refractor but refractor uses the same logic to parsing as prism so prism also should get a fix.

I have implemented a change in behaviour to toml header parsing in this PR which keeps the entire table header as a single token, you can see the change in the diff on the test output but basically [header] becomes [header] rather than "[", "header" ,"]" (and also made a simplification by removing insertkey in place of dottedkey

However, having thought about it a bit longer, I do recognise this is perhaps not an upgrade since no longer does this allow separate styling of the punctuation in the header compared to the key.

So what I would propose is to copy the approach used in parsing ini files, where the whole thing becomes a nested structure

using this:

inside: {
	table-name': {
			pattern: RegExp('(^\\[\\[?\\s*)' + dottedKey),
			lookbehind: true,
			alias: 'class-name',
		},
		'punctuation': /\[|\]/,
	},

to produce this output:

	["table", [
		["punctuation", "["],
		["table-name", "table"],
		["punctuation", "]"]
	]],
	["table", [
		["punctuation", "["],
		["punctuation", "["],
		["table-name", "array"],
		["punctuation", "]"],
		["punctuation", "]"]
	]],

I swapped to this approach that mirrors ini as, on reflection, it is clearly the best choice.

@netlify
Copy link

netlify bot commented Nov 28, 2025

Deploy Preview for dev-prismjs-com ready!

Name Link
🔨 Latest commit ae5d09d
🔍 Latest deploy log https://app.netlify.com/projects/dev-prismjs-com/deploys/692d8423e80ead00083bcfa5
😎 Deploy Preview https://deploy-preview-4045--dev-prismjs-com.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions
Copy link

github-actions bot commented Nov 28, 2025

No JS Changes

Generated by 🚫 dangerJS against ae5d09d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant