abstract-document 12.0.4 → 12.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.d.ts +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.d.ts.map +1 -1
- package/lib/abstract-document-xml/index.d.ts +1 -1
- package/lib/abstract-document-xml/index.d.ts.map +1 -1
- package/lib/abstract-document-xml/index.js +1 -1
- package/lib/abstract-document-xml/index.js.map +1 -1
- package/lib/abstract-document-xml/mustache-xml/index.d.ts +3 -0
- package/lib/abstract-document-xml/mustache-xml/index.d.ts.map +1 -0
- package/lib/abstract-document-xml/mustache-xml/index.js +19 -0
- package/lib/abstract-document-xml/mustache-xml/index.js.map +1 -0
- package/lib/abstract-document-xml/mustache-xml/parse-mustache-xml.d.ts +14 -0
- package/lib/abstract-document-xml/mustache-xml/parse-mustache-xml.d.ts.map +1 -0
- package/lib/abstract-document-xml/mustache-xml/parse-mustache-xml.js +133 -0
- package/lib/abstract-document-xml/mustache-xml/parse-mustache-xml.js.map +1 -0
- package/lib/abstract-document-xml/mustache-xml/validate-mustache-xml.d.ts +21 -0
- package/lib/abstract-document-xml/mustache-xml/validate-mustache-xml.d.ts.map +1 -0
- package/lib/abstract-document-xml/mustache-xml/validate-mustache-xml.js +226 -0
- package/lib/abstract-document-xml/mustache-xml/validate-mustache-xml.js.map +1 -0
- package/lib/abstract-document-xml/xsd-template/xsd-template.d.ts +2 -2
- package/lib/abstract-document-xml/xsd-template/xsd-template.d.ts.map +1 -1
- package/lib/abstract-document-xml/xsd-template/xsd-template.js +1 -1
- package/lib/abstract-document-xml/xsd-template/xsd-template.js.map +1 -1
- package/package.json +2 -3
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Group.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Header and footer.docx and b/package/src/abstract-document-exporters/__tests__/docx2/tmp/Header → footer.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Mixed hyperlink and textrun.docx and b/package/src/abstract-document-exporters/__tests__/docx2/tmp/Mixed hyperlink → textrun.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Mixed textrun and images.docx and b/package/src/abstract-document-exporters/__tests__/docx2/tmp/Mixed textrun → images.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple images.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple tables.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple textrun with Center alignment.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple textrun with End alignment.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple textrun with Start alignment that linebreaks.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple textrun with Start alignment.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Page numbering.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Simple table colSpan and rowSpan.docx and b/package/src/abstract-document-exporters/__tests__/docx2/tmp/Simple table colSpan → rowSpan.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Simple table without rows.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Simple table.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single hyperlink.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single image.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with Center alignment that linebreaks.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with Center alignment.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with End alignment that linebreaks.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with End alignment.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with Start alignment that linebreaks.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with Start alignment.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/hello with Arial font.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/hello.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/letter-dimensions.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/page-orientation-landscape.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/page-orientation-portrait.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/tocSeparator.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/world.docx +0 -0
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position group.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position header and footer.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position paragraph.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position section in group.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position section in table.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position table.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Group Paragraphs.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Group Tables.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Group no keeptogether.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Group too big for one page.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Header and footer.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Hyperlink internal linktarget.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Hyperlink internal.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Manual line break.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Manual line breaks empty lines.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Margins header body footer.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed hyperlink and textrun no underline.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed hyperlink and textrun with underline.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed hyperlink and textrun.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed textrun and images.pdf and b/package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed textrun → images.pdf +0 -0
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple images overflow.pdf +0 -0
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple images.pdf +0 -0
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple textrun with Center alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple textrun with End alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple textrun with Start alignment that linebreaks.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple textrun with Start alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Page numbering.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table row that doesnt fit page.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table single row.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with group.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with header 2.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with header.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with margin bottom.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with margin top single table.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with margin top.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with rowSpan multipages.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with rowSpan.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table all auto.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table all fix.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table background.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table cell padding of image.pdf +0 -0
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table cell padding of text.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table center alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table colSpan and rowSpan.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table minimal row height.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table mix auto fix.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table padding.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table right alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table row alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table text alignment in cell with wrapping.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table text alignment in cell.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table with default colored borders.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table with header.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table with multi colored borders.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table with single colored borders.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single date.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single figure.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single hyperlink centered.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single hyperlink no underline.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single hyperlink right aligned.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single hyperlink.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image from URL.pdf +0 -0
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image svg color hex.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image svg color name.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image svg color url.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image svg dasharray.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image.pdf +0 -0
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun baseline alphabetic.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun baseline bottom.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun baseline hanging.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun baseline middle.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun baseline top.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Center alignment that linebreaks.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Center alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with End alignment that linebreaks.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with End alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Justify alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Start alignment that linebreaks.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Start alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with super and subscripts.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Table of content separator.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/hello with roman font.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/hello.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/pagebreak.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/world.pdf +2 -2
- package/src/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.ts +1 -1
- package/src/abstract-document-xml/index.ts +1 -1
- package/src/abstract-document-xml/mustache-xml/index.ts +2 -0
- package/src/abstract-document-xml/mustache-xml/parse-mustache-xml.ts +125 -0
- package/src/abstract-document-xml/mustache-xml/validate-mustache-xml.ts +279 -0
- package/src/abstract-document-xml/xsd-template/xsd-template.ts +1 -1
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import * as FXmlP from "fast-xml-parser";
|
|
2
|
+
import { XmlElement, parseXml, findElement } from "./parse-mustache-xml";
|
|
3
|
+
|
|
4
|
+
enum ErrorType {
|
|
5
|
+
warning = 0,
|
|
6
|
+
error = 1,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type Range = {
|
|
10
|
+
readonly startLineNumber: number;
|
|
11
|
+
readonly startColumn: number;
|
|
12
|
+
readonly endLineNumber: number;
|
|
13
|
+
readonly endColumn: number;
|
|
14
|
+
};
|
|
15
|
+
type Position = {
|
|
16
|
+
readonly lineNumber: number;
|
|
17
|
+
readonly column: number;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type ErrorObject = {
|
|
21
|
+
readonly range: Range;
|
|
22
|
+
readonly options: ErrorOptions;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type ErrorOptions = {
|
|
26
|
+
readonly className: string;
|
|
27
|
+
// eslint-disable-next-line functional/prefer-readonly-type
|
|
28
|
+
readonly hoverMessage: Array<{
|
|
29
|
+
readonly value: string;
|
|
30
|
+
}>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type XmlError = {
|
|
34
|
+
readonly message: string;
|
|
35
|
+
readonly type: ErrorType;
|
|
36
|
+
readonly range: Range;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// eslint-disable-next-line functional/prefer-readonly-type
|
|
40
|
+
export function validateMustacheXml(fullXml: string, xsdSchema: ReadonlyArray<XmlElement>): Array<ErrorObject> {
|
|
41
|
+
const errors: Array<XmlError> = [];
|
|
42
|
+
|
|
43
|
+
// ignore all mustache brackets
|
|
44
|
+
const matchMustacheBrackets = /{{.*}}(?!([\S]))/g;
|
|
45
|
+
// Ignore xml comments
|
|
46
|
+
const xmlComments = /<!--[^>]*-->/g;
|
|
47
|
+
|
|
48
|
+
// Replace matches with spaces of same length
|
|
49
|
+
let cleanedXml = fullXml.replace(matchMustacheBrackets, (m) => " ".repeat(m.length));
|
|
50
|
+
cleanedXml = cleanedXml.replace(xmlComments, (m) => {
|
|
51
|
+
const x = (m.match(/^.*$/gm) || []).map((m2) => " ".repeat(m2.length));
|
|
52
|
+
return x.join("\n");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const xml = `<xml>\n${cleanedXml}\n</xml>`;
|
|
56
|
+
|
|
57
|
+
if (xml) {
|
|
58
|
+
try {
|
|
59
|
+
const result = FXmlP.XMLValidator.validate(xml, {
|
|
60
|
+
allowBooleanAttributes: true,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
if (result !== true) {
|
|
64
|
+
errors.push(getErrorFromException(result, xml));
|
|
65
|
+
}
|
|
66
|
+
const entryPointXml = parseXml(xml, {
|
|
67
|
+
preserveOrder: true,
|
|
68
|
+
ignoreAttributes: false,
|
|
69
|
+
attributeNamePrefix: "",
|
|
70
|
+
allowBooleanAttributes: true,
|
|
71
|
+
trimValues: false,
|
|
72
|
+
ignoreDeclaration: true,
|
|
73
|
+
})[0]!;
|
|
74
|
+
|
|
75
|
+
const entryPointSchema = xsdSchema[0]!;
|
|
76
|
+
let pos = 0;
|
|
77
|
+
const lines = cleanedXml.split("\n");
|
|
78
|
+
const getRangeOfElement = (text: string, incrementPosition: boolean = true): Range => {
|
|
79
|
+
if (text === undefined) {
|
|
80
|
+
const monacoPosition = getPositionFromIndex(lines, pos);
|
|
81
|
+
return toRange(
|
|
82
|
+
monacoPosition.lineNumber,
|
|
83
|
+
monacoPosition.column,
|
|
84
|
+
monacoPosition.lineNumber,
|
|
85
|
+
monacoPosition.column + 5
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
const position = cleanedXml.indexOf(text, pos);
|
|
89
|
+
if (incrementPosition) {
|
|
90
|
+
pos = position >= pos ? position + text.length : pos;
|
|
91
|
+
}
|
|
92
|
+
const monacoPosition = getPositionFromIndex(lines, position);
|
|
93
|
+
return toRange(
|
|
94
|
+
monacoPosition.lineNumber,
|
|
95
|
+
monacoPosition.column,
|
|
96
|
+
monacoPosition.lineNumber,
|
|
97
|
+
monacoPosition.column + text.length
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const validationErrors = entryPointXml.children.flatMap((child) =>
|
|
102
|
+
validateElements(child, undefined, entryPointSchema, getRangeOfElement)
|
|
103
|
+
);
|
|
104
|
+
errors.push(...validationErrors);
|
|
105
|
+
} catch (e) {
|
|
106
|
+
errors.push(createError(e.message, ErrorType.error, toRange(1, 1, 1, 100)));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return errors.map((e) => getDecorationsFromError(e));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function validateElements(
|
|
114
|
+
element: XmlElement,
|
|
115
|
+
schemaElement: XmlElement | undefined,
|
|
116
|
+
completeSchema: XmlElement,
|
|
117
|
+
getRangeOfElement: (elementName: string, incrementPosition?: boolean) => Range
|
|
118
|
+
): ReadonlyArray<XmlError> {
|
|
119
|
+
const errors: Array<XmlError> = [];
|
|
120
|
+
|
|
121
|
+
// Validate element name
|
|
122
|
+
const tagName = element.tagName;
|
|
123
|
+
const range = getRangeOfElement(tagName);
|
|
124
|
+
|
|
125
|
+
const slashPosition = getRangeOfElement("/", false);
|
|
126
|
+
const closingTagPosition = getRangeOfElement(">", false);
|
|
127
|
+
const isClosed = rangeLessThan(slashPosition, closingTagPosition);
|
|
128
|
+
|
|
129
|
+
const validElements = Object.values(completeSchema.children);
|
|
130
|
+
const schemaName = schemaElement?.attributes.type || tagName;
|
|
131
|
+
const foundSchemaElement = findElement(validElements, schemaName);
|
|
132
|
+
|
|
133
|
+
if (!foundSchemaElement) {
|
|
134
|
+
return [createError(`"${tagName}" is not a valid element`, ErrorType.error, range)];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const possibleAttributes = Array.from(foundSchemaElement.children).flatMap((c) =>
|
|
138
|
+
c.tagName === "attribute" ? c : []
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
// Validate required attributes
|
|
142
|
+
for (const possibleAttribute of possibleAttributes) {
|
|
143
|
+
const attributeName = possibleAttribute.attributes.name;
|
|
144
|
+
const isRequired = possibleAttribute.attributes.use;
|
|
145
|
+
if (attributeName && isRequired && isRequired === "required") {
|
|
146
|
+
if (element.attributes[attributeName] === undefined) {
|
|
147
|
+
errors.push(createError(`"${attributeName}" is a required attribute on "${tagName}"`, ErrorType.error, range));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Validate existing attributes
|
|
153
|
+
for (const [attrKey, attrVal] of Object.entries(element.attributes)) {
|
|
154
|
+
const possibleAttrNames = possibleAttributes.flatMap((p) => p.attributes.name || []);
|
|
155
|
+
const attrText = typeof attrVal === "string" ? `${attrKey}="${attrVal}"` : attrKey;
|
|
156
|
+
const attrRange = getRangeOfElement(attrText, false);
|
|
157
|
+
if (!possibleAttrNames.includes(attrKey)) {
|
|
158
|
+
errors.push(createError(`"${attrKey}" is a not a valid attribute on "${tagName}"`, ErrorType.error, attrRange));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Validate that the children are allowed as a child of current element
|
|
163
|
+
// and then validate the children themselves
|
|
164
|
+
const schemaChildren = Object.values(foundSchemaElement.children);
|
|
165
|
+
|
|
166
|
+
for (const child of element.children) {
|
|
167
|
+
const childName = child.tagName;
|
|
168
|
+
if (!childName) {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
const foundChild = findElement(schemaChildren, childName);
|
|
172
|
+
if (!foundChild) {
|
|
173
|
+
const childRange = getRangeOfElement(childName, false);
|
|
174
|
+
if (childRange) {
|
|
175
|
+
errors.push(createError(`"${childName}" is not a valid child of "${tagName}"`, ErrorType.error, childRange));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const elementErrors = validateElements(child, foundChild, completeSchema, getRangeOfElement);
|
|
180
|
+
errors.push(...elementErrors);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (!isClosed) {
|
|
184
|
+
// Increment position to after closing tag
|
|
185
|
+
getRangeOfElement(`</${tagName}`, true);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return errors;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function getDecorationsFromError(error: XmlError): ErrorObject {
|
|
192
|
+
return {
|
|
193
|
+
range: error.range,
|
|
194
|
+
options: {
|
|
195
|
+
className: getErrorClassNames(error),
|
|
196
|
+
hoverMessage: [{ value: getErrorType(error) }, { value: getErrorMessage(error) }],
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function getErrorFromException(result: FXmlP.ValidationError, xml: string): XmlError {
|
|
202
|
+
const { col, line, msg } = result.err;
|
|
203
|
+
const startLine = line - 1;
|
|
204
|
+
const lines = xml.split("\n");
|
|
205
|
+
const rowText = lines[startLine] || "";
|
|
206
|
+
const length = rowText.indexOf(">") - rowText.indexOf("<") || 4;
|
|
207
|
+
const range = toRange(startLine, col, startLine, col + length);
|
|
208
|
+
|
|
209
|
+
return createError(msg!, ErrorType.error, range);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function getErrorClassNames(error: XmlError): string {
|
|
213
|
+
switch (error.type) {
|
|
214
|
+
case ErrorType.warning:
|
|
215
|
+
return "xml-lint xml-lint--warning";
|
|
216
|
+
case ErrorType.error:
|
|
217
|
+
return "xml-lint xml-lint--error";
|
|
218
|
+
default:
|
|
219
|
+
return "";
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function getErrorType(error: XmlError): string {
|
|
224
|
+
switch (error.type) {
|
|
225
|
+
case ErrorType.warning:
|
|
226
|
+
return "**Warning**";
|
|
227
|
+
case ErrorType.error:
|
|
228
|
+
return "**Error**";
|
|
229
|
+
default:
|
|
230
|
+
return "";
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const getErrorMessage = (error: XmlError): string => error.message.split(/[\t\n]/g)[1] ?? error.message;
|
|
235
|
+
|
|
236
|
+
const createError = (message: string, type: ErrorType, range: Range): XmlError => ({ message, type, range });
|
|
237
|
+
|
|
238
|
+
function getPositionFromIndex(lines: ReadonlyArray<string>, index: number): Position {
|
|
239
|
+
let totalLength = 0;
|
|
240
|
+
for (const [lineNumber, line] of lines.entries()) {
|
|
241
|
+
totalLength += line.length;
|
|
242
|
+
if (totalLength >= index - lineNumber) {
|
|
243
|
+
return {
|
|
244
|
+
lineNumber: lineNumber + 1,
|
|
245
|
+
column: 1 + index - (totalLength - line.length) - lineNumber || 1, // "- lineNumber" because of \n characters
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return { lineNumber: lines.length, column: 1 };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const toRange = (startLineNumber: number, startColumn: number, endLineNumber: number, endColumn: number): Range => ({
|
|
253
|
+
startLineNumber,
|
|
254
|
+
startColumn,
|
|
255
|
+
endLineNumber,
|
|
256
|
+
endColumn,
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
export function errorToReadableText(errors: ReadonlyArray<ErrorObject>, templateName: string = ""): string {
|
|
260
|
+
const errorLines: Array<string> = [];
|
|
261
|
+
if (templateName) {
|
|
262
|
+
errorLines.push(`Error in template ${templateName} \n`);
|
|
263
|
+
}
|
|
264
|
+
for (const error of errors) {
|
|
265
|
+
const hoverErrors = error.options.hoverMessage.map((e) => e.value.replace(/\*/g, ""));
|
|
266
|
+
errorLines.push(`${hoverErrors.join("\n")}`);
|
|
267
|
+
errorLines.push(`On line ${error.range.startLineNumber}, column ${error.range.startColumn}\n`);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return errorLines.join("\n");
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function rangeLessThan(range1: Range, range2: Range): boolean {
|
|
274
|
+
return range1.startLineNumber < range2.startLineNumber
|
|
275
|
+
? true
|
|
276
|
+
: range1.startLineNumber > range2.startLineNumber
|
|
277
|
+
? false
|
|
278
|
+
: range1.startColumn < range2.startColumn;
|
|
279
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Elements from "./elements";
|
|
2
2
|
import * as Styles from "./styles";
|
|
3
3
|
import * as CustomElements from "./custom-elements";
|
|
4
|
-
import { parseXml } from "
|
|
4
|
+
import { parseXml } from "../mustache-xml";
|
|
5
5
|
|
|
6
6
|
const commonParts = `${Styles.layoutFoundation}
|
|
7
7
|
${Elements.section}
|