mirror of
https://github.com/explosion/spaCy.git
synced 2025-08-06 21:30:22 +03:00
Fix TypeAnnotation
This commit is contained in:
parent
1cc2d0ce42
commit
7b3725df20
|
@ -1,11 +1,13 @@
|
||||||
import MDX from '@next/mdx'
|
import MDX from '@next/mdx'
|
||||||
|
|
||||||
import remarkPlugins from './plugins/index.mjs'
|
import remarkPlugins from './plugins/index.mjs'
|
||||||
|
import rehypePlugins from './plugins/rehypePlugins.mjs'
|
||||||
|
|
||||||
const withMDX = MDX({
|
const withMDX = MDX({
|
||||||
extension: /\.mdx?$/,
|
extension: /\.mdx?$/,
|
||||||
options: {
|
options: {
|
||||||
remarkPlugins,
|
remarkPlugins,
|
||||||
|
rehypePlugins,
|
||||||
providerImportSource: '@mdx-js/react',
|
providerImportSource: '@mdx-js/react',
|
||||||
},
|
},
|
||||||
experimental: {
|
experimental: {
|
||||||
|
|
4935
website/package-lock.json
generated
4935
website/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -14,6 +14,7 @@
|
||||||
"prettier": "prettier . --write"
|
"prettier": "prettier . --write"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@mapbox/rehype-prism": "^0.8.0",
|
||||||
"@mdx-js/loader": "^2.1.5",
|
"@mdx-js/loader": "^2.1.5",
|
||||||
"@mdx-js/react": "^2.1.5",
|
"@mdx-js/react": "^2.1.5",
|
||||||
"@next/mdx": "^13.0.2",
|
"@next/mdx": "^13.0.2",
|
||||||
|
@ -33,6 +34,7 @@
|
||||||
"next-mdx-remote": "^4.2.0",
|
"next-mdx-remote": "^4.2.0",
|
||||||
"parse-numeric-range": "^1.3.0",
|
"parse-numeric-range": "^1.3.0",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
|
"prismjs": "^1.29.0",
|
||||||
"prop-types": "^15.8.1",
|
"prop-types": "^15.8.1",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-dom": "18.2.0",
|
"react-dom": "18.2.0",
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { MDXRemote, MDXRemoteSerializeResult } from 'next-mdx-remote'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import Layout from '../src/templates'
|
import Layout from '../src/templates'
|
||||||
import remarkPlugins from '../plugins/index.mjs'
|
import remarkPlugins from '../plugins/index.mjs'
|
||||||
|
import rehypePlugins from '../plugins/rehypePlugins.mjs'
|
||||||
|
|
||||||
import recordSection from '../meta/recordSections'
|
import recordSection from '../meta/recordSections'
|
||||||
|
|
||||||
|
@ -94,6 +95,7 @@ export const getStaticProps: GetStaticProps<PropsPage, ParsedUrlQuery> = async (
|
||||||
parseFrontmatter: true,
|
parseFrontmatter: true,
|
||||||
mdxOptions: {
|
mdxOptions: {
|
||||||
remarkPlugins,
|
remarkPlugins,
|
||||||
|
rehypePlugins,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
5
website/plugins/rehypePlugins.mjs
Normal file
5
website/plugins/rehypePlugins.mjs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import rehypePrism from '@mapbox/rehype-prism'
|
||||||
|
|
||||||
|
const rehypePlugins = [rehypePrism]
|
||||||
|
|
||||||
|
export default rehypePlugins
|
|
@ -1,10 +1,11 @@
|
||||||
import React, { Fragment, useEffect, useState } from 'react'
|
import React, { Fragment, useEffect, useState } from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
import highlightCode from 'gatsby-remark-prismjs/highlight-code.js'
|
|
||||||
import 'prismjs-bibtex'
|
|
||||||
import rangeParser from 'parse-numeric-range'
|
import rangeParser from 'parse-numeric-range'
|
||||||
import { window } from 'browser-monads'
|
import { window } from 'browser-monads'
|
||||||
|
import Prism from 'prismjs'
|
||||||
|
|
||||||
|
import 'prismjs/components/prism-python.min.js'
|
||||||
|
|
||||||
import CUSTOM_TYPES from '../../meta/type-annotations.json'
|
import CUSTOM_TYPES from '../../meta/type-annotations.json'
|
||||||
import { isString, htmlToReact } from './util'
|
import { isString, htmlToReact } from './util'
|
||||||
|
@ -71,7 +72,8 @@ export const TypeAnnotation = ({ lang = 'python', link = true, children }) => {
|
||||||
const code = Array.isArray(children) ? children.join('') : children || ''
|
const code = Array.isArray(children) ? children.join('') : children || ''
|
||||||
const [rawText, meta] = code.split(/(?= \(.+\)$)/)
|
const [rawText, meta] = code.split(/(?= \(.+\)$)/)
|
||||||
const rawStr = rawText.replace(/\./g, TMP_DOT)
|
const rawStr = rawText.replace(/\./g, TMP_DOT)
|
||||||
const rawHtml = lang === 'none' || !code ? code : highlightCode(lang, rawStr)
|
const rawHtml =
|
||||||
|
lang === 'none' || !code ? code : Prism.highlight(rawStr, Prism.languages[lang], lang)
|
||||||
const html = rawHtml.replace(new RegExp(TMP_DOT, 'g'), '.').replace(/\n/g, ' ')
|
const html = rawHtml.replace(new RegExp(TMP_DOT, 'g'), '.').replace(/\n/g, ' ')
|
||||||
const result = htmlToReact(html)
|
const result = htmlToReact(html)
|
||||||
const elements = Array.isArray(result) ? result : [result]
|
const elements = Array.isArray(result) ? result : [result]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user