Commit e5b766aa authored by drigle's avatar drigle

chore: sync subject schema definitions

parent a5ce9abc
...@@ -320,29 +320,14 @@ function replaceManagedBlock(document, block) { ...@@ -320,29 +320,14 @@ function replaceManagedBlock(document, block) {
const replaced = `${document.slice(0, start)}${block}${document.slice(end + END_MARKER.length)}`; const replaced = `${document.slice(0, start)}${block}${document.slice(end + END_MARKER.length)}`;
return removeLegacyDependencySection(replaced); return removeLegacyDependencySection(replaced);
} }
const heading = /^## 2\.\s*Subject Definitions[^\n]*\n?/m.exec(document); const heading = /^## \d+\.\s*Subject Definitions[^\n]*\n?/m.exec(document);
if (heading) { if (heading) {
const contentStart = heading.index + heading[0].length; const contentStart = heading.index + heading[0].length;
const nextHeading = /^## (?!#)[^\n]*\n?/gm; const nextHeading = /^## \d+\.\s+[^\n]*\n?/gm;
nextHeading.lastIndex = contentStart; nextHeading.lastIndex = contentStart;
const next = nextHeading.exec(document); const next = nextHeading.exec(document);
const sectionEnd = next ? next.index : document.length; const sectionEnd = next ? next.index : document.length;
const section = document.slice(contentStart, sectionEnd); const migrated = `${document.slice(0, contentStart)}\n${block}\n\n${document.slice(sectionEnd)}`;
const objectHeadings = [...section.matchAll(/^### [^\n]*`([A-Za-z][A-Za-z0-9_-]*)`[^\n]*\n?/gm)];
let migratedSection = section;
if (objectHeadings.length) {
for (let index = objectHeadings.length - 1; index >= 0; index -= 1) {
const current = objectHeadings[index];
const startIndex = current.index;
const endIndex = objectHeadings[index + 1]?.index ?? section.length;
migratedSection = `${migratedSection.slice(0, startIndex)}${migratedSection.slice(endIndex)}`;
}
const firstIndex = objectHeadings[0].index;
migratedSection = `${migratedSection.slice(0, firstIndex)}\n${block}\n\n${migratedSection.slice(firstIndex)}`;
} else {
migratedSection = `\n${block}\n\n${section}`;
}
let migrated = `${document.slice(0, contentStart)}${migratedSection}${document.slice(sectionEnd)}`;
return removeLegacyDependencySection(migrated); return removeLegacyDependencySection(migrated);
} }
return `${document.trimEnd()}\n\n## 2. Subject Definitions\n\n${block}\n`; return `${document.trimEnd()}\n\n## 2. Subject Definitions\n\n${block}\n`;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment