WIP COMMENT OUT BROKEN CODE

This commit is contained in:
Marcus Blättermann 2022-11-13 17:34:09 +01:00
parent 2cbee66953
commit 7294c42b27
No known key found for this signature in database
GPG Key ID: A1E1F04008AC450D
11 changed files with 130 additions and 115 deletions

View File

@ -1,9 +1,9 @@
import React, { Fragment } from 'react'
import PropTypes from 'prop-types'
import classNames from 'classnames'
import highlightCode from 'gatsby-remark-prismjs/highlight-code.js'
import 'prismjs-bibtex'
import rangeParser from 'parse-numeric-range'
// import highlightCode from 'gatsby-remark-prismjs/highlight-code.js'
// import 'prismjs-bibtex'
// import rangeParser from 'parse-numeric-range'
import { window } from 'browser-monads'
import CUSTOM_TYPES from '../../meta/type-annotations.json'
@ -69,7 +69,11 @@ export const TypeAnnotation = ({ lang = 'python', link = true, children }) => {
const code = Array.isArray(children) ? children.join('') : children || ''
const [rawText, meta] = code.split(/(?= \(.+\)$)/)
const rawStr = rawText.replace(/\./g, TMP_DOT)
const rawHtml = lang === 'none' || !code ? code : highlightCode(lang, rawStr)
const rawHtml =
lang === 'none' || !code
? code
: // highlightCode(lang, rawStr)
''
const html = rawHtml.replace(new RegExp(TMP_DOT, 'g'), '.').replace(/\n/g, ' ')
const result = htmlToReact(html)
const elements = Array.isArray(result) ? result : [result]
@ -159,7 +163,8 @@ function convertLine(line, i) {
</Fragment>
)
}
const htmlLine = replacePrompt(highlightCode('bash', line), '$')
const htmlLine = line
// replacePrompt(highlightCode('bash', line), '$')
return htmlToReact(htmlLine)
}
@ -190,9 +195,9 @@ function formatCode(html, lang, prompt) {
.split('\n')
.map((line, i) => {
let newLine = prompt ? replacePrompt(line, prompt, i === 0) : line
if (lang === 'diff' && !line.startsWith('<')) {
newLine = highlightCode('python', line)
}
// if (lang === 'diff' && !line.startsWith('<')) {
// newLine = highlightCode('python', line)
// }
return newLine
})
.join('\n')
@ -219,26 +224,26 @@ export class Code extends React.Component {
children: PropTypes.node,
}
updateJuniper() {
if (this.state.Juniper == null && window.Juniper !== null) {
this.setState({ Juniper: window.Juniper })
}
}
// updateJuniper() {
// if (this.state.Juniper == null && window.Juniper !== null) {
// this.setState({ Juniper: window.Juniper })
// }
// }
componentDidMount() {
this.updateJuniper()
}
// componentDidMount() {
// this.updateJuniper()
// }
componentDidUpdate() {
this.updateJuniper()
}
// componentDidUpdate() {
// this.updateJuniper()
// }
render() {
const { lang, title, executable, github, prompt, wrap, highlight, className, children } =
this.props
const codeClassNames = classNames(classes['code'], className, `language-${lang}`, {
[classes['wrap']]: !!highlight || !!wrap || lang === 'cli',
[classes['cli']]: lang === 'cli',
const codeClassNames = classNames(classes.code, className, `language-${lang}`, {
[classes.wrap]: !!highlight || !!wrap || lang === 'cli',
[classes.cli]: lang === 'cli',
})
const ghClassNames = classNames(codeClassNames, classes['max-height'])
const { Juniper } = this.state
@ -255,10 +260,11 @@ export class Code extends React.Component {
}
const codeText = Array.isArray(children) ? children.join('') : children || ''
const highlightRange = highlight ? rangeParser.parse(highlight).filter((n) => n > 0) : []
// const highlightRange = highlight ? rangeParser.parse(highlight).filter((n) => n > 0) : []
const rawHtml = ['none', 'cli'].includes(lang)
? codeText
: highlightCode(lang, codeText, highlightRange)
: // highlightCode(lang, codeText, highlightRange)
codeText
const html = formatCode(rawHtml, lang, prompt)
return (
<>

View File

@ -1,7 +1,7 @@
import React from 'react'
import PropTypes from 'prop-types'
import classNames from 'classnames'
import { navigate } from 'gatsby'
// import { navigate } from 'gatsby'
import * as classes from '../styles/dropdown.module.sass'
@ -11,7 +11,7 @@ export default function Dropdown({ defaultValue, className, onChange, children }
if (isExternal) {
window.location.href = target.value
} else {
navigate(target.value)
// navigate(target.value)
}
}
return (

View File

@ -1,7 +1,7 @@
import React, { useState, useEffect } from 'react'
import PropTypes from 'prop-types'
import classNames from 'classnames'
import highlightCode from 'gatsby-remark-prismjs/highlight-code.js'
// import highlightCode from 'gatsby-remark-prismjs/highlight-code.js'
import Icon from './icon'
import Link from './link'
@ -39,7 +39,11 @@ const GitHubCode = ({ url, lang, errorMsg = defaultErrorMsg, className }) => {
}
}, [initialized, rawUrl, errorMsg])
const highlighted = lang === 'none' || !code ? code : highlightCode(lang, code)
const highlighted =
lang === 'none' || !code
? code
: // highlightCode(lang, code)
null
return (
<>

View File

@ -1,5 +1,6 @@
import React from 'react'
import PropTypes from 'prop-types'
// import { graphql } from 'gatsby'
import useOnlineStatus from '@rehooks/online-status'
import classNames from 'classnames'

View File

@ -318,7 +318,7 @@ const Model = ({
</tbody>
</Table>
{meta.notes & <MarkdownToReact markdown={meta.notes} />}
{hasInteractiveCode && (
{/* {hasInteractiveCode && (
<CodeBlock title="Try out the model" lang="python" executable={true}>
{[
`import spacy`,
@ -331,7 +331,7 @@ const Model = ({
` print(token.text, token.pos_, token.dep_)`,
].join('\n')}
</CodeBlock>
)}
)} */}
{meta.accuracy && (
<Accordion id={`${name}-accuracy`} title="Accuracy Evaluation">
<Table>

View File

@ -1,6 +1,6 @@
import React, { Fragment } from 'react'
import PropTypes from 'prop-types'
import { Link as GatsbyLink } from 'gatsby'
// import { Link as GatsbyLink } from 'gatsby'
import classNames from 'classnames'
import Icon from './icon'

View File

@ -117,10 +117,10 @@ const Quickstart = ({
const dropdownGetter = showDropdown[id] || (() => true)
return hidden ? null : (
<div key={id} data-quickstart-group={id} className={classes['group']}>
<style data-quickstart-style={id} scoped>
{/* <style data-quickstart-style={id} scoped>
{styles[id] ||
`[data-quickstart-results]>[data-quickstart-${id}] { display: none }`}
</style>
</style> */}
<div className={classes['legend']}>
{title}
{help && (

View File

@ -7,23 +7,23 @@ import * as classes from '../styles/search.module.sass'
export default function Search({ id = 'docsearch', placeholder = 'Search docs', settings = {} }) {
const { apiKey, indexName, appId } = settings
if (!apiKey && !indexName) return null
const [initialized, setInitialized] = useState(false)
useEffect(() => {
if (!initialized) {
setInitialized(true)
window.docsearch({
appId,
apiKey,
indexName,
inputSelector: `#${id}`,
debug: false,
})
// window.docsearch({
// appId,
// apiKey,
// indexName,
// inputSelector: `#${id}`,
// debug: false,
// })
}
}, [initialized, apiKey, indexName, id])
if (!apiKey && !indexName) return null
return (
<form className={classes.root}>
<label htmlFor={id} className={classes.icon}>
{/* <label htmlFor={id} className={classes.icon}>
<Icon name="search" width={20} />
</label>
<input
@ -32,7 +32,7 @@ export default function Search({ id = 'docsearch', placeholder = 'Search docs',
type="search"
placeholder={placeholder}
aria-label={placeholder}
/>
/> */}
</form>
)
}

View File

@ -216,6 +216,9 @@ const QuickstartInstall = ({ id, title }) => {
</QS>
{languages.map(({ code, models: modelOptions }) => {
if (!modelOptions) {
return
}
const pkg = modelOptions[efficiency ? 0 : modelOptions.length - 1]
return (
<QS models={code} key={code}>

View File

@ -81,6 +81,9 @@ const QuickstartInstall = ({ id, title, description, children }) => {
copy={false}
>
{languages.map(({ code, models, example }) => {
if (!models) {
return
}
const pkg = efficiency ? models[0] : models[models.length - 1]
const exampleText = example || 'No text available yet'
return lang !== code ? null : (

View File

@ -1,8 +1,8 @@
import React, { useState } from 'react'
import highlightCode from 'gatsby-remark-prismjs/highlight-code.js'
// import highlightCode from 'gatsby-remark-prismjs/highlight-code.js'
import { Quickstart } from '../components/quickstart'
import generator, { DATA as GENERATOR_DATA } from './quickstart-training-generator'
// import generator, { DATA as GENERATOR_DATA } from './quickstart-training-generator'
import { htmlToReact } from '../components/util'
const DEFAULT_LANG = 'en'
@ -70,75 +70,73 @@ const DATA = [
]
export default function QuickstartTraining({ id, title, download = 'base_config.cfg' }) {
const [lang, setLang] = useState(DEFAULT_LANG)
const [_components, _setComponents] = useState([])
const [components, setComponents] = useState([])
const [[hardware], setHardware] = useState([DEFAULT_HARDWARE])
const [[optimize], setOptimize] = useState([DEFAULT_OPT])
const [textcatExclusive, setTextcatExclusive] = useState(DEFAULT_TEXTCAT_EXCLUSIVE)
// const [lang, setLang] = useState(DEFAULT_LANG)
// const [_components, _setComponents] = useState([])
// const [components, setComponents] = useState([])
// const [[hardware], setHardware] = useState([DEFAULT_HARDWARE])
// const [[optimize], setOptimize] = useState([DEFAULT_OPT])
// const [textcatExclusive, setTextcatExclusive] = useState(DEFAULT_TEXTCAT_EXCLUSIVE)
// function updateComponents(value, isExclusive) {
// _setComponents(value)
// const updated = value.map(c => (c === 'textcat' && !isExclusive ? 'textcat_multilabel' : c))
// setComponents(updated)
// }
// const setters = {
// lang: setLang,
// components: v => updateComponents(v, textcatExclusive),
// hardware: setHardware,
// optimize: setOptimize,
// textcat: v => {
// const isExclusive = v.includes('exclusive')
// setTextcatExclusive(isExclusive)
// updateComponents(_components, isExclusive)
// },
// }
// const defaultData = GENERATOR_DATA.__default__
// const reco = GENERATOR_DATA[lang] || defaultData
// const content = generator({
// lang,
// components,
// optimize,
// hardware,
// transformer_data: reco.transformer || defaultData.transformer,
// word_vectors: reco.word_vectors,
// has_letters: reco.has_letters,
// })
// const rawStr = content.trim().replace(/\n\n\n+/g, '\n\n')
// const rawContent = `${COMMENT}\n${rawStr}`
// const displayContent = ''
// // highlightCode('ini', rawContent)
// // .split('\n')
// // .map(line => (line.startsWith('#') ? `<span class="token comment">${line}</span>` : line))
// // .join('\n')
// let data = DATA
// data[0].dropdown = models.languages
// .map(({ name, code }) => ({
// id: code,
// title: name,
// }))
// .sort((a, b) => a.title.localeCompare(b.title))
// if (!_components.includes('textcat')) {
// data = data.map(field => (field.id === 'textcat' ? { ...field, hidden: true } : field))
// }
// return (
// <Quickstart
// id="quickstart-widget"
// Container="div"
// download={download}
// rawContent={rawContent}
// data={data}
// title={title}
// id={id}
// setters={setters}
// hidePrompts
// small
// codeLang="ini"
// >
// {htmlToReact(displayContent)}
// </Quickstart>
// )
function updateComponents(value, isExclusive) {
_setComponents(value)
const updated = value.map((c) =>
c === 'textcat' && !isExclusive ? 'textcat_multilabel' : c
)
setComponents(updated)
}
const setters = {
lang: setLang,
components: (v) => updateComponents(v, textcatExclusive),
hardware: setHardware,
optimize: setOptimize,
textcat: (v) => {
const isExclusive = v.includes('exclusive')
setTextcatExclusive(isExclusive)
updateComponents(_components, isExclusive)
},
}
const defaultData = GENERATOR_DATA.__default__
const reco = GENERATOR_DATA[lang] || defaultData
const content = generator({
lang,
components,
optimize,
hardware,
transformer_data: reco.transformer || defaultData.transformer,
word_vectors: reco.word_vectors,
has_letters: reco.has_letters,
})
const rawStr = content.trim().replace(/\n\n\n+/g, '\n\n')
const rawContent = `${COMMENT}\n${rawStr}`
const displayContent = highlightCode('ini', rawContent)
.split('\n')
.map((line) => (line.startsWith('#') ? `<span class="token comment">${line}</span>` : line))
.join('\n')
let data = DATA
data[0].dropdown = models.languages
.map(({ name, code }) => ({
id: code,
title: name,
}))
.sort((a, b) => a.title.localeCompare(b.title))
if (!_components.includes('textcat')) {
data = data.map((field) => (field.id === 'textcat' ? { ...field, hidden: true } : field))
}
return (
<Quickstart
id="quickstart-widget"
Container="div"
download={download}
rawContent={rawContent}
data={data}
title={title}
id={id}
setters={setters}
hidePrompts
small
codeLang="ini"
>
{htmlToReact(displayContent)}
</Quickstart>
)
return <></>
}