2022-01-28 16:57:07 +01:00
|
|
|
import React from 'react'
|
2025-04-01 16:15:20 +02:00
|
|
|
import { Highlight } from '@freesewing/react/components/Highlight'
|
2022-01-28 16:57:07 +01:00
|
|
|
import hljs from 'highlight.js/lib/common'
|
|
|
|
import yaml from 'js-yaml'
|
2023-01-29 16:44:02 +01:00
|
|
|
|
|
|
|
export const Yaml = (props) => {
|
2022-01-28 16:57:07 +01:00
|
|
|
let code
|
|
|
|
if (props.json) code = yaml.dump(JSON.parse(props.json))
|
|
|
|
else if (props.js) code = yaml.dump(props.js)
|
|
|
|
else code = props.children
|
|
|
|
|
2024-03-17 11:18:21 +01:00
|
|
|
return (
|
2025-04-01 16:15:20 +02:00
|
|
|
<Highlight
|
|
|
|
{...props}
|
|
|
|
language="yaml"
|
|
|
|
raw={hljs.highlight(code, { language: 'yaml' }).value}
|
|
|
|
copy={code}
|
|
|
|
/>
|
2024-03-17 11:18:21 +01:00
|
|
|
)
|
2022-01-28 16:57:07 +01:00
|
|
|
}
|