prism-react-renderer icon indicating copy to clipboard operation
prism-react-renderer copied to clipboard

Finer grained theme type selectors

Open tim-soft opened this issue 6 years ago • 3 comments

Let's say I have three different punctuation tokens: span.token.tag.spread.punctuation, span.token.tag.script.punctuation and span.token.tag.punctuation.

To get closer to a vscode dark+ theme, the first two tags are actually a different color than the last.

As far as I can tell, the theme type only allows for styling all three as the same color

{
  types: ['punctuation'],
  style: {
    color: 'rgb(212, 212, 212)'
  }
}

Is there currently a way to select all three types individually in the theme?

edit: doesn't seem likely at the moment https://github.com/FormidableLabs/prism-react-renderer/blob/64f879aa396107457770a117f4b6178078b11000/src/components/Highlight.js#L94

an extra check if the token's entire classname list matches a type in the theme could get around this, so the theme would look like

{
  types: ['tag script punctuation',  'tag spread punctuation'],
  style: {
    color: 'rgb(212, 212, 212)'
  }
},
{
  types: ['tag punctuation'],
  style: {
    color: 'rgb(212, 212, 212)'
  }
}

tim-soft avatar Jun 14 '19 17:06 tim-soft

Additionally, for this example:

const prismIncludeLanguages = (Prism) => {
  // ...

  additionalLanguages.forEach((lang) => {
    require(`prismjs/components/prism-${lang}`); // eslint-disable-line
  });

  require('/path/to/your/prism-language-definition');

  // ...
};
  1. { on line 1 gets:
    <span class="token punctuation">{</span>
    
  2. ${ on line 5 gets:
    <span class="token template-string interpolation interpolation-punctuation punctuation">${</span>
    

How would you determine the precedence of punctuation and interpolation-punctuation?

{
  styles: [
    {
      types: ['punctuation'],
      style: {
        color: '#DEE0E3'
      }
    },
    {
      types: ['interpolation-punctuation'],
      style: {
        color: '#F3AFE6'
      }
    }
  ]
}

I would have figured the last one defined in the styles property would take precedence, but that not the way things current work. But, even swapping the order doesn't change anything either.

roydukkey avatar Feb 24 '21 02:02 roydukkey

@kitten I guess there's no way to achieve this currently, right?

I'm improving the VS Code Dark theme with my changes from the react-syntax-highlighter theme, but there are some things that prism-react-renderer doesn't seem to be able to represent...

karlhorky avatar May 15 '21 13:05 karlhorky

FWIW I implemented something similar in react-syntax-highlighter last year, and it wasn't a crazy big change:

https://github.com/react-syntax-highlighter/react-syntax-highlighter/pull/305

karlhorky avatar May 15 '21 13:05 karlhorky

@carbonrobot is this really completed? Where can we see the documentation of this feature?

karlhorky avatar Feb 07 '24 15:02 karlhorky

We don't have any plans to support this at this time.

carbonrobot avatar Feb 07 '24 16:02 carbonrobot

Ok, thanks for the reply. I guess the close reason is "Not Planned" then - I was confused by the "Completed" reason selected above.

karlhorky avatar Feb 07 '24 16:02 karlhorky

Sorry about that, our script is a little overzealous as we go through and try to clean up issues in our open source that is several years old.

carbonrobot avatar Feb 07 '24 16:02 carbonrobot