🐞 Patch Changes
- Updated dependencies [
827093e]:- @astrojs/prism@3.2.0-beta.0
827093e]:
#12039 710a1a1 Thanks @ematipico! - Adds a markdown.shikiConfig.langAlias option that allows aliasing a non-supported code language to a known language. This is useful when the language of your code samples is not a built-in Shiki language, but you want your Markdown source to contain an accurate language while also displaying syntax highlighting.
The following example configures Shiki to highlight cjs code blocks using the javascript syntax highlighter:
import { defineConfig } from 'astro/config';
export default defineConfig({ markdown: { shikiConfig: { langAlias: { cjs: 'javascript', }, }, },});Then in your Markdown, you can use the alias as the language for a code block for syntax highlighting:
```cjs'use strict';
function commonJs() { return 'I am a commonjs file';}```#12008 5608338 Thanks @Princesseuh! - Welcome to the Astro 5 beta! This release has no changes from the latest alpha of this package, but it does bring us one step closer to the final, stable release.
Starting from this release, no breaking changes will be introduced unless absolutely necessary.
To learn how to upgrade, check out the Astro v5.0 upgrade guide in our beta docs site.
#11861 3ab3b4e Thanks @bluwy! - Cleans up Astro-specfic metadata attached to vfile.data in Remark and Rehype plugins. Previously, the metadata was attached in different locations with inconsistent names. The metadata is now renamed as below:
vfile.data.__astroHeadings -> vfile.data.astro.headingsvfile.data.imagePaths -> vfile.data.astro.imagePathsThe types of imagePaths has also been updated from Set<string> to string[]. The vfile.data.astro.frontmatter metadata is left unchanged.
While we don’t consider these APIs public, they can be accessed by Remark and Rehype plugins that want to re-use Astro’s metadata. If you are using these APIs, make sure to access them in the new locations.
#11825 560ef15 Thanks @bluwy! - Updates return object of createShikiHighlighter as codeToHast and codeToHtml to allow generating either the hast or html string directly
#11861 3ab3b4e Thanks @bluwy! - Removes InvalidAstroDataError, safelyGetAstroData, and setVfileFrontmatter APIs in favour of isFrontmatterValid
#11661 83a2a64 Thanks @bluwy! - Renames the following CSS variables theme color token names to better align with the Shiki v1 defaults:
--astro-code-color-text => --astro-code-foreground--astro-code-color-background => --astro-code-backgroundYou can perform a global find and replace in your project to migrate to the new token names.
#11341 49b5145 Thanks @madcampos! - Adds support for Shiki’s defaultColor option.
This option allows you to override the values of a theme’s inline style, adding only CSS variables to give you more flexibility in applying multiple color themes.
Configure defaultColor: false in your Shiki config to apply throughout your site, or pass to Astro’s built-in <Code> component to style an individual code block.
import { defineConfig } from 'astro/config';export default defineConfig({ markdown: { shikiConfig: { themes: { light: 'github-light', dark: 'github-dark', }, defaultColor: false, }, },});---import { Code } from 'astro:components';---
<Code code={`const useMyColors = true`} lang="js" defaultColor={false} />#10538 ccafa8d230f65c9302421a0ce0a0adc5824bfd55 Thanks @604qgc! - Adds a data-language attribute on the rendered pre elements to expose the highlighted syntax language.
For example, the following Markdown code block will expose data-language="python":
\```pythondef func(): print('Hello Astro!')\```This allows retrieving the language in a rehype plugin from node.properties.dataLanguage by accessing the <pre> element using { tagName: "pre" }:
import { visit } from "unist-util-visit";export default function myRehypePre() { return (tree) => { visit(tree, { tagName: "pre" }, (node) => { const lang = node.properties.dataLanguage; [...] }); };}Note: The <pre> element is not exposed when using Astro’s <Code /> component which outputs flattened HTML.
The data-language attribute may also be used in css rules:
pre::before { content: attr(data-language);}
pre[data-language='javascript'] { font-size: 2rem;}683d51a5eecafbbfbfed3910a3f1fbf0b3531b99]:
#10629 2cf116f80cb5e421ab5cc5eb4a654e7b78c1b8de Thanks @bluwy! - Removes deprecated APIs including remarkShiki, remarkPrism, replaceCssVariables and several unused types
#10618 374efcdff9625ca43309d89e3b9cfc9174351512 Thanks @43081j! - Updates Shiki syntax highlighting to lazily load shiki languages by default (only preloading plaintext). Additionally, the createShikiHighlighter() API now returns an asynchronous highlight() function due to this.
c585528f446ccca3d4c643f4af5d550b93c18902 Thanks @imkunet! - This patch allows Shiki to use all of its reserved languages instead of the
previous behavior of forcing unknown languages to plaintext.19e42c368184013fc30d1e46753b9e9383bb2bdf Thanks @bluwy! - Fixes support for Shiki transformers that access the meta to conditionally perform transformations#9960 c081adf998d30419fed97d8fccc11340cdc512e0 Thanks @StandardGage! - Allows passing any props to the <Code /> component
#10130 5a9528741fa98d017b269c7e4f013058028bdc5d Thanks @bluwy! - Migrates shikiji to shiki 1.0
#10104 a31bbd7ff8f3ec62ee507f72d1d25140b82ffc18 Thanks @remcohaszing! - Changes Astro’s internal syntax highlighting to use rehype plugins instead of remark plugins. This provides better interoperability with other rehype plugins that deal with code blocks, in particular with third party syntax highlighting plugins and rehype-mermaid.
This may be a breaking change if you are currently using:
htmlraw.Please review your rendered code samples carefully, and if necessary, consider using a rehype plugin that deals with the generated element nodes instead. You can transform the AST of raw HTML strings, or alternatively use hast-util-to-html to get a string from a raw node.
44c957f893c6bf5f5b7c78301de7b21c5975584d Thanks @ktym4a! - Fixes a bug where non-UTF-8 file names are not displayed when using relative paths in markdowns.a505190933365268d48139a5f197a3cfb5570870 Thanks @bluwy! - Fixes usage in browser environments by using subpath imports#9736 53c69dcc82cdf4000aff13a6c11fffe19096cf45 Thanks @bluwy! - Initializes internal cwdUrlStr variable lazily for performance, and workaround Rollup side-effect detection bug when building for non-Node runtimes
#9723 2f81cffa9da9db0e2802d303f94feaee8d2f54ec Thanks @blackmann! - Fixes a case where transformers wouldn’t work on the class property
#9566 165cfc154be477337037185c32b308616d1ed6fa Thanks @OliverSpeir! - Allows remark plugins to pass options specifying how images in .md files will be optimized
#9643 e9a72d9a91a3741566866bcaab11172cb0dc7d31 Thanks @blackmann! - Adds a new markdown.shikiConfig.transformers config option. You can use this option to transform the Shikiji hast (AST format of the generated HTML) to customize the final HTML. Also updates Shikiji to the latest stable version.
See Shikiji’s documentation for more details about creating your own custom transformers, and a list of common transformers you can add directly to your project.
#9138 abf601233 Thanks @bluwy! - Updates the unified, remark, and rehype dependencies to latest. Make sure to update your custom remark and rehype plugins as well to be compatible with the latest versions.
Potentially breaking change: The default value of markdown.remarkRehype.footnoteBackLabel is changed from "Back to content" to "Back to reference 1". See the mdast-util-to-hast commit for more information.
#9182 c7953645e Thanks @bluwy! - Removes deprecated APIs. All Astro packages had been refactored to not use these APIs.
#9138 abf601233 Thanks @bluwy! - Updates the unified, remark, and rehype dependencies to latest. Make sure to update your custom remark and rehype plugins as well to be compatible with the latest versions.
Potentially breaking change: The default value of markdown.remarkRehype.footnoteBackLabel is changed from "Back to content" to "Back to reference 1". See the mdast-util-to-hast commit for more information.
#9182 c7953645e Thanks @bluwy! - Removes deprecated APIs. All Astro packages had been refactored to not use these APIs.