首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >主题-ui/prism不适用于gatsbyjs markdown文件

主题-ui/prism不适用于gatsbyjs markdown文件
EN

Stack Overflow用户
提问于 2020-08-14 21:51:30
回答 1查看 157关注 0票数 1

我使用@theme-ui/prism来格式化markdown文件中的代码块文本。im使用的markdown插件是gatsby- plugin -mdx。它似乎不起作用,因为我在代码块中看不到黑色背景。

下面是我所做的:

代码语言:javascript
复制
yarn add @theme-ui/prism

创建src/gatsby-plugin-theme ui/Components.ts:

代码语言:javascript
复制
import Prism from '@theme-ui/prism'
const components = {
  pre: props => props.children,
  code: Prism,
}
export default components

在src/gatsby-plugin-theme-ui/index.ts中,我为pre定义了一种样式

代码语言:javascript
复制
import nightOwl from '@theme-ui/prism/presets/night-owl.json';
import colors from "./colors";
import headings from "./headings";

const systemFonts =
  '-apple-system, BlinkMacSystemFont, San Francisco, Helvetica Neue, Helvetica, Ubuntu, Roboto, Noto, Segoe UI, Arial, sans-serif';
const transition = '0.2s ease-out';

export default {
  useColorSchemeMediaQuery: true,
  colors,
  initialColorMode: `dark`,
  fonts: {
    body: systemFonts,
    heading: "Avenir Next",
    monospace: 'Menlo, monospace'
  },
  fontSizes: [12, 14, 16, 24, 28, 36, 48, 64],
  fontWeights: {
    body: 400,
    heading: 500,
    bold: 600,
  },
  lineHeights: {
    body: 1.7,
    heading: 1.1275,
  },
  letterSpacings: {
    body: 'normal',
    caps: '0.2em'
  },
  breakpoints: [
    '320px', '376px', '540px', '735px', '1070px', '1280px', '1640px', '1880px'
  ],
  transition,
  styles: {
    root: {
      fontFamily: 'body',
      lineHeight: 'body',
      fontWeight: 'body',
      ...headings
    },
    ...headings,
    p: {
      my: 4,
    },
    a: {
      color: 'secondary',
      transition: `color ${transition}`,
      ':hover,:focus': {
        color: 'text'
      }
    },
    pre: {
      ...nightOwl,
      fontFamily: `"Operator Mono", monospace`,
      fontSize: '0.9rem',
      tabSize: 4,
      hyphens: `none`,
      overflow: `auto`,
      borderRadius: 6,
      p: 3,
      my: 4
    },
    inlineCode: {
      color: `primary`,
      background: `rgba(233, 218, 172, 0.15)`,
      borderRadius: 3,
      px: `0.4rem`,
      py: `0.2rem`
    },
    table: {
      width: '100%',
      borderCollapse: 'separate',
      borderSpacing: 0
    },
    th: {
      textAlign: 'left',
      borderBottomStyle: 'solid'
    },
    td: {
      textAlign: 'left',
      borderBottomStyle: 'solid'
    }
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-30 02:55:51

棱镜特性实际上似乎是针对theme-ui的未来版本的,所以默认(在撰写本文时是v0.3.x) doesn't support it

为了解决这个问题,你可以把你的theme-ui*gatsby-plugin-theme-ui包版本改为^0.4.0-rc.1 (rc.3实际上已经过时了,但是it's broken自动柜员机,所以不要使用它)。

代码语言:javascript
复制
// package.json
{
  ...
  "dependencies": {
    "gatsby-plugin-theme-ui": "^0.4.0-rc.1",
    "@theme-ui/prism": "^0.4.0-rc.1",
    "theme-ui": "^0.4.0-rc.1",
  }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63414103

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档