#!/usr/bin/env node
// Test document content that simulates the form field from the API response
const testDocumentWithForm = `
Form Example
Please complete the following form:
FORMTEXT
`;
// Test the improved form detection
function extractTextFromParagraph(paragraph) {
const textMatch = paragraph.match(/]*>(.*?)<\/w:t>/g);
if (!textMatch) return '';
return textMatch.map(match => match.replace(/<[^>]*>/g, '')).join(' ');
}
function getFormType(formIndex) {
const formTypes = [
'text-field', 'checkbox-field', 'dropdown-field', 'form-data-complete',
'form-data', 'checkbox-control', 'dropdown-control', 'text-input',
'content-control', 'content-control-data', 'field-character',
'formtext-simple', 'formcheckbox-simple', 'formdropdown-simple'
];
return formTypes[formIndex] || 'form-element';
}
function testImprovedFormDetection(documentXml) {
const results = [];
let paragraphCount = 0;
let currentHeading = null;
let approximatePageNumber = 1;
// Updated form detection patterns
const formElements = [
/]*FORMTEXT/, // Text form fields
/]*FORMCHECKBOX/, // Checkbox form fields
/]*FORMDROPDOWN/, // Dropdown form fields
//, // Form field data (complete tags)
//, // Form field data (opening tag)
//, // Structured document tags (content controls)
//, // Content control content
//, // Field character begin
/FORMTEXT/, // Simple FORMTEXT detection
/FORMCHECKBOX/, // Simple FORMCHECKBOX detection
/FORMDROPDOWN/ // Simple FORMDROPDOWN detection
];
const paragraphRegex = /]*>[\s\S]*?<\/w:p>/g;
const paragraphs = documentXml.match(paragraphRegex) || [];
paragraphs.forEach((paragraph, index) => {
paragraphCount++;
if (paragraphCount % 15 === 0) {
approximatePageNumber++;
}
if (/ detection');
console.log(' ⢠Added simple FORMTEXT/FORMCHECKBOX/FORMDROPDOWN patterns');
console.log(' ⢠Removed global flag (g) from regex patterns');
console.log(' ⢠Added more comprehensive form element detection');