Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple themes #807

Closed
pawanrawal opened this issue Oct 13, 2015 · 9 comments
Closed

Support for multiple themes #807

pawanrawal opened this issue Oct 13, 2015 · 9 comments

Comments

@pawanrawal
Copy link

Is it possible to use multiple themes with the same app ? I want some piece of code using Coy and others using the Dark theme. Is there someway to do this ?

@Golmote
Copy link
Contributor

Golmote commented Oct 13, 2015

Hi! Prism does not currently provide a way to do this out of the box, though you could probably change the selectors used in those themes to fit your needs.
If it were to be a feature, how would you see it? How could we allow both a global default theme and block-specific ones?

@mAAdhaTTah
Copy link
Member

You'd have to scope the CSS or something to the context you want to highlight it in; I can't imagine how you'd support this by default, if you even wanted to.

@Golmote
Copy link
Contributor

Golmote commented Oct 13, 2015

We could try to rely on selectors specificity, but this would require all themes to properly reset any property the default theme would have set...

@pawanrawal
Copy link
Author

Hi, do you mean to say that I change the code and pre selectors in the css and js files of one of the themes to some other selectors and use the new selectors to style an element ?

@Golmote
Copy link
Contributor

Golmote commented Oct 15, 2015

You shouldn't have to change anything in the JS.

You just need to add a class name on every code blocks, for example:

<pre class="dark-block language-css"><code>

and change the dark theme like this, for example:

code.dark-block[class*="language-"],
pre.dark-block[class*="language-"] {

(just make sure you change all the required selectors in the theme)

And you can do the same with the Coy theme.

@pawanrawal
Copy link
Author

Thanks @Golmote that works. Please close this issue.

@Golmote Golmote closed this as completed Oct 22, 2015
@Stanzilla
Copy link

To pick this up again, could something be added that uses the preferred-color-scheme media query to switch themes automatically?

@RunDevelopment
Copy link
Member

prefers-color-scheme is very experimental at this point in time, so we won't use it as part of Prism.

Also, switching themes automatically with this won't be easy since the theme being switched to will have to override all rules of the default theme. This is simply not the reality of Prism's themes, so it's not doable right now.

@aSemy
Copy link

aSemy commented Dec 31, 2022

I've managed to implement this by

  1. depending on some new Prism themes in package.json

      "dependencies": {
        "prism-themes": "^1.9.0",
        "prismjs-darcula-theme": "^1.0.3",
      },
  2. Activating the Docusaurus Sass plugin

    • add "docusaurus-plugin-sass": "^0.2.2", in package.json,
    • in docusaurus.config.js activate the sass plugin: plugins: ['docusaurus-plugin-sass'],)
  3. in docusaurus.config.js, define a new global.scss client module

    const config = {
      clientModules: [
        require.resolve('./src/modules/global.scss'),
      ]
    }
  4. Then in ./src/modules/global.scss I @import the two Prism styles inside a css rule, which means the rule in each imported style will have an additional qualifier.

    .language-typescript {
      @import "prism-themes/themes/prism-vsc-dark-plus";
    }
    
    .language-kotlin {
      @import "prismjs-darcula-theme/darcula";
    }

    Because the Kotlin and TypeScript styles have different fonts/colours/sizes that look weird aside each other, I !important override the incongruent properties

    pre[class*="language-"], code[class*="language-"] {
      font-family: Source Code Pro, PT Mono, Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace !important;
      font-size: 1em !important;
      line-height: 1.3 !important;
      background: #1e1e1e !important;
    }

Now Kotlin and TypeScript have different colours, which makes the difference more apparent.

image

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

No branches or pull requests

6 participants