From 65fc526220ff65ecbb63c1f7d9234895827412aa Mon Sep 17 00:00:00 2001 From: Frank Johnson Date: Sun, 19 Sep 2021 14:10:23 -0400 Subject: [PATCH] fixed my broken merge with kurt's branch commit, updated OpenSCAD contributors --- .../components/EditorGuide/EditorGuide.tsx | 4 +- .../helpers/cadPackages/openScad/userGuide.md | 2 +- app/web/src/helpers/markdown.ts | 40 +++++++++---------- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/app/web/src/components/EditorGuide/EditorGuide.tsx b/app/web/src/components/EditorGuide/EditorGuide.tsx index a5f53a6..bc4f374 100644 --- a/app/web/src/components/EditorGuide/EditorGuide.tsx +++ b/app/web/src/components/EditorGuide/EditorGuide.tsx @@ -1,10 +1,10 @@ -import { extractMetaData } from 'src/helpers/markdown' +import { useMarkdownMetaData } from 'src/helpers/markdown' import Editor from 'rich-markdown-editor' import { useRef } from 'react' import KeyValue from 'src/components/KeyValue/KeyValue' export default function EditorGuide({ content }) { - const [rawMetadata, metadata] = extractMetaData(content) + const [rawMetadata, metadata] = useMarkdownMetaData(content) const processedContent = rawMetadata ? content.replace(rawMetadata[0], '') diff --git a/app/web/src/helpers/cadPackages/openScad/userGuide.md b/app/web/src/helpers/cadPackages/openScad/userGuide.md index 412fe5f..ccc20b2 100644 --- a/app/web/src/helpers/cadPackages/openScad/userGuide.md +++ b/app/web/src/helpers/cadPackages/openScad/userGuide.md @@ -2,7 +2,7 @@ title: OpenSCAD Written with: Custom language Kernal type: BREP -Maintained by: [Marius Kintel + 15 members](https://github.com/openscad) +Maintained by: [Marius Kintel and contributors](https://github.com/openscad/openscad/graphs/contributors) Documentation: [openscad.org](https://openscad.org/) --- OpenSCAD is a solid 3D modeler that enables the creation of parametric models using its scripting language. Models are created by utilizing a technique called constructive solid geometry. According to this technique, simple objects can be transformed and combined in order to create almost any complex model. \ No newline at end of file diff --git a/app/web/src/helpers/markdown.ts b/app/web/src/helpers/markdown.ts index 4ae12da..5b67ff6 100644 --- a/app/web/src/helpers/markdown.ts +++ b/app/web/src/helpers/markdown.ts @@ -1,29 +1,25 @@ // Extracts YAML frontmatter from Markdown files // Gotten from this helpful comment on a react-markdown GitHub Issue: https://github.com/remarkjs/react-markdown/issues/164#issuecomment-890497653 export function useMarkdownMetaData(text: string): Array { + const metaData = {} as any return React.useMemo(() => { - const metaData = {} as any - /* ... */ + const metaRegExp = RegExp(/^---[\r\n](((?!---).|[\r\n])*)[\r\n]---$/m) as any + // get metadata + const rawMetaData = metaRegExp.exec(text) + + let keyValues + + if (rawMetaData !== null) { + // rawMeta[1] are the stuff between "---" + keyValues = rawMetaData[1].split('\n') + + // which returns a list of key values: ["key1: value", "key2: value"] + keyValues.forEach((keyValue) => { + // split each keyValue to keys and values + const [, key, value] = keyValue.split(/(.+): (.+)/) + metaData[key] = value.trim() + }) + } return [rawMetaData, metaData] }, [text]) } - - const metaRegExp = RegExp(/^---[\r\n](((?!---).|[\r\n])*)[\r\n]---$/m) - // get metadata - const rawMetaData = metaRegExp.exec(text) - - let keyValues - - if (rawMetaData!) { - // rawMeta[1] are the stuff between "---" - keyValues = rawMetaData[1].split('\n') - - // which returns a list of key values: ["key1: value", "key2: value"] - keyValues.forEach((keyValue) => { - // split each keyValue to keys and values - const [, key, value] = keyValue.split(/(.+): (.+)/) - metaData[key] = value.trim() - }) - } - return [rawMetaData, metaData] -}