diff --git a/.build/src/app/patternfly-procedure-parser.ts b/.build/src/app/patternfly-procedure-parser.ts new file mode 100644 index 000000000..e61e09979 --- /dev/null +++ b/.build/src/app/patternfly-procedure-parser.ts @@ -0,0 +1,131 @@ +// COPIED FROM https://github.com/patternfly/patternfly-quickstarts/blob/main/packages/dev/src/quickstarts-data/asciidoc/procedure-parser.ts until it's published to NPMJS +/* eslint-disable */ + +import { QuickStart, QuickStartTask } from '@patternfly/quickstarts'; + +export const ProcQuickStartParser = ( + quickStart: QuickStart & { + spec: { + tasks: undefined | QuickStartTask[] | string[]; + }; + }, + environmentVariables?: { [name: string]: string }, +) => { + const replaceEnvironmentVariables = (s: string | undefined) => + s?.replace(/\${(\w+)}/, (substring, name) => { + return environmentVariables ? ([name] ? environmentVariables[name] : substring) : substring; + }); + + quickStart.spec.tasks = quickStart.spec.tasks?.map((task: QuickStartTask | string, index) => { + let proc: string; + let answer: QuickStartTask; + if (typeof task === 'string') { + proc = task; + answer = {}; + } else { + // @ts-ignore + proc = task.proc; + answer = task; + // @ts-ignore + delete task.proc; + } + + let description = '', + procedure, + verification, + title, + summaryFailed, + success, + reviewFailed: string | undefined, + prerequisites; + if (proc) { + const taskDOM = document.createElement('div'); + taskDOM.innerHTML = proc; + + // remove the screencapture images + taskDOM.querySelectorAll('.imageblock.screencapture').forEach((node) => { + node.parentElement?.removeChild(node); + }); + + title = taskDOM + .querySelector('h1:first-child,h2:first-child,h3:first-child,h4:first-child,h5:first-child') + ?.innerHTML.trim(); + let sectionBody = taskDOM.querySelector('.sectionbody'); + if (!sectionBody?.hasChildNodes()) { + // possibly in other templates, where we want to look for article + sectionBody = taskDOM.querySelector('article'); + } + if (sectionBody) { + for (let i = 0; i < sectionBody.children.length || 0; i++) { + /** + child typically looks like: + +
+
Procedure|Prerequisites|Verification|Note|Warning
+ +
  • +
  • ... + +
  • + + And the below code extracts the
      or