diff --git a/docs/README.md b/docs/README.md index e73eea988c..ec9546ba39 100644 --- a/docs/README.md +++ b/docs/README.md @@ -26,6 +26,16 @@ Cards allow to show content in a grid system with a title, a description, a type {% /cards %} ``` +#### Code + +You can add specific languages, a filename and allow or not to process interpolation _(default is `false`)_ on the code snippet displayed. + +```` +‎```javascript {% fileName="main.css" %} +‎ const code = "goes here"; +‎``` +```` + #### Custom iframes We can display a special iframe and setting its width inside the document. diff --git a/nx-dev/ui-markdoc/src/lib/nodes/fence.component.tsx b/nx-dev/ui-markdoc/src/lib/nodes/fence.component.tsx index 1954018034..137c507646 100644 --- a/nx-dev/ui-markdoc/src/lib/nodes/fence.component.tsx +++ b/nx-dev/ui-markdoc/src/lib/nodes/fence.component.tsx @@ -1,5 +1,5 @@ import { ClipboardDocumentIcon } from '@heroicons/react/24/outline'; -import React, { useEffect, useState } from 'react'; +import React, { ReactNode, useEffect, useState } from 'react'; // @ts-ignore import { CopyToClipboard } from 'react-copy-to-clipboard'; // @ts-ignore @@ -15,19 +15,28 @@ function resolveLanguage(lang: string) { return lang; } } -function CodeWrapper({ children }: any) { - return ( -
- {children} +function CodeWrapper( + fileName: string +): ({ children }: { children: ReactNode }) => JSX.Element { + return ({ children }: { children: ReactNode }) => ( +
+ {!!fileName && ( +
+ {fileName} +
+ )} +
{children}
); } export function Fence({ children, + fileName, language, }: { children: string; + fileName: string; language: string; }) { const [copied, setCopied] = useState(false); @@ -54,7 +63,7 @@ export function Fence({ >
diff --git a/nx-dev/ui-markdoc/src/lib/nodes/fence.schema.ts b/nx-dev/ui-markdoc/src/lib/nodes/fence.schema.ts index 08b95bba72..5b4212a9bf 100644 --- a/nx-dev/ui-markdoc/src/lib/nodes/fence.schema.ts +++ b/nx-dev/ui-markdoc/src/lib/nodes/fence.schema.ts @@ -5,6 +5,7 @@ export const fence: Schema = { attributes: { content: { type: 'String', render: false, required: true }, language: { type: 'String' }, + fileName: { type: 'String', default: '' }, process: { type: 'Boolean', render: false, default: true }, }, transform(node, config) {