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

Document how to use a custom Shiki theme #1749

Merged
merged 5 commits into from
Oct 28, 2022
Merged

Conversation

nujovich
Copy link
Contributor

@nujovich nujovich commented Oct 8, 2022

What kind of changes does this PR include?

  • New or updated content

Description

Before

image

After

image

I am actively participating in Hacktoberfest and Hacksquad 2022 🙌.

@netlify
Copy link

netlify bot commented Oct 8, 2022

Deploy Preview for astro-docs-2 ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 586d4af
🔍 Latest deploy log https://app.netlify.com/sites/astro-docs-2/deploys/635bb3d5cb4c500009a1402e
😎 Deploy Preview https://deploy-preview-1749--astro-docs-2.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 site settings.

@sarah11918 sarah11918 added add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. hacktoberfest-accepted Mark a PR as accepted to contribute towards Hacktoberfest labels Oct 10, 2022
@sarah11918
Copy link
Member

Thanks for tackling this issue, @nujovich! 🥳 A great first contribution!

I'm wondering whether this deserves an entire new code block, though, and maybe we can work it into the existing example itself? Or at the very least, what about a condensed second example that just shows the theme property and not the whole thing? Would you be willing to make that second code example smaller so we can see what that looks like?

@nujovich
Copy link
Contributor Author

Sure @sarah11918! Let me work on that!

@sarah11918 sarah11918 added improve documentation Enhance existing documentation (e.g. add an example, improve description) and removed add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. labels Oct 13, 2022
@sarah11918 sarah11918 self-assigned this Oct 20, 2022
@kevinzunigacuellar
Copy link
Member

kevinzunigacuellar commented Oct 21, 2022

Hello @nujovich and @sarah11918,

I was trying to add a new theme to my config file. I noticed that any string passed to shikiConfig.theme will try to resolve to the themes folder inside the shiki package.

So in order to add your own theme to the package you will need follow shiki's guide: add a new theme. This will modify your shiki package and add the theme to the list of themes.

However, shiki is not a direct dependency of your project then there would be more steps to add your own theme 😥

An easier way to do this is to import the json and pass it to shikiConfig.theme

import { defineConfig } from 'astro/config';
import customTheme from './src/custom-themes/dracula.json';

export default defineConfig({
  site: 'https://example.com',
  markdown: {
    shikiConfig: {
      theme: customTheme,
    },
  },
});

Hope this helps 😇

Oh btw here is the stackblitz

@nujovich
Copy link
Contributor Author

Hello @nujovich and @sarah11918,

I was trying to add a new theme to my config file. I noticed that any string passed to shikiConfig.theme will try to resolve to the themes folder inside the shiki package.

So in order to add your own theme to the package you will need follow shiki's guide: add a new theme. This will modify your shiki package and add the theme to the list of themes.

However, shiki is not a direct dependency of your project then there would be more steps to add your own theme 😥

An easier way to do this is to import the json and pass it to shikiConfig.theme

import { defineConfig } from 'astro/config';
import customTheme from './src/custom-themes/dracula.json';

export default defineConfig({
  site: 'https://example.com',
  markdown: {
    shikiConfig: {
      theme: customTheme,
    },
  },
});

Hope this helps 😇

Oh btw here is the stackblitz

Awesome ! I will try that and add it to the docs.

@delucis delucis changed the title Update markdown-content.md Document how to use a custom Shiki theme Oct 28, 2022
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
@sarah11918 sarah11918 merged commit e0a5bba into withastro:main Oct 28, 2022
@delucis
Copy link
Member

delucis commented Oct 28, 2022

Thanks again for your contribution @nujovich! Welcome to team docs 🥳

kevinzunigacuellar added a commit that referenced this pull request Oct 31, 2022
* i18n(es): add docs for alternative markdown file extensions

* i18n(es): document how to escape special characters in markdown

* i18n(es): apply review suggestions

* i18n(es): document how to use a custom Shiki theme (#1749)

Co-authored-by: Kevin Zuniga Cuellar <46791833+kevinzunigacuellar@users.noreply.github.com>
@Ivluengo
Copy link

Hello @nujovich and @sarah11918,

I was trying to add a new theme to my config file. I noticed that any string passed to shikiConfig.theme will try to resolve to the themes folder inside the shiki package.

So in order to add your own theme to the package you will need follow shiki's guide: add a new theme. This will modify your shiki package and add the theme to the list of themes.

However, shiki is not a direct dependency of your project then there would be more steps to add your own theme 😥

An easier way to do this is to import the json and pass it to shikiConfig.theme

import { defineConfig } from 'astro/config';
import customTheme from './src/custom-themes/dracula.json';

export default defineConfig({
  site: 'https://example.com',
  markdown: {
    shikiConfig: {
      theme: customTheme,
    },
  },
});

Hope this helps 😇

Oh btw here is the stackblitz

Hi!! I tryed this with a custom theme. The thing is when I change anything on the astro.config.mjs I don't see any changes at all. Even if I use this shikiConfig: { theme: 'dracula' }. IT won't work so when I use my customThem like this shikiConfig: { theme: customTheme } it doesn't work either.

Any thoughts why it doesn't work??

thanks a lot!!

@delucis
Copy link
Member

delucis commented Nov 10, 2022

Hey @Ivluengo! Little bit hard to see without seeing more of your project. If this isn’t working, the best would be to create a bug report with a reproduction in the astro repo so we can look at fixing it: https://github.com/withastro/astro/issues/new/choose

Alternatively, we have a really active #support channel in the Astro Discord server which is a great place to share code examples and troubleshoot — https://astro.build/chat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted Mark a PR as accepted to contribute towards Hacktoberfest improve documentation Enhance existing documentation (e.g. add an example, improve description)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document that markdown.shikiConfig.theme can be a relative path
5 participants