-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,738 additions
and
14 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,6 +173,7 @@ async function run(request, ctx) { | |
mediaHandler, | ||
log, | ||
url, | ||
reqHeaders, | ||
}); | ||
|
||
const headers = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2023 Adobe. All rights reserved. | ||
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
|
||
/* eslint-disable no-param-reassign */ | ||
import { visit } from 'unist-util-visit'; | ||
import { getAllForms } from '@aemforms/forms-importer'; | ||
|
||
export async function getForms(html, options) { | ||
const { log } = options; | ||
const formNameDefMap = {}; | ||
try { | ||
const forms = await getAllForms(html); | ||
forms?.forEach((form) => { | ||
formNameDefMap[form.name] = form; | ||
}); | ||
} catch (e) { | ||
// Ignore errors | ||
log.warn(`Failed to retrieve forms from content ': ${e.message}`); | ||
} | ||
return formNameDefMap; | ||
} | ||
|
||
export function processForms(tree, formNameDefMap) { | ||
visit(tree, 'element', (node) => { | ||
if (node.tagName === 'form') { | ||
const name = node?.properties?.id || node?.properties?.name; | ||
const formDef = formNameDefMap[name]; | ||
if (formDef) { | ||
node.tagName = 'block'; | ||
node.properties = {}; | ||
node.children = [ | ||
{ | ||
type: 'element', | ||
tagName: 'tr', | ||
children: [{ | ||
type: 'element', | ||
tagName: 'td', | ||
children: [{ | ||
type: 'element', | ||
tagName: 'pre', | ||
children: [{ | ||
type: 'text', | ||
tagName: 'code', | ||
value: JSON.stringify(formDef), | ||
}], | ||
}], | ||
}], | ||
}, | ||
]; | ||
node.data = { | ||
type: 'Form', | ||
}; | ||
} | ||
} | ||
}); | ||
} |
Oops, something went wrong.