Hello!
How use xmlLinter? We have @codemirror/lang-xml, but have not ParseLinter.
Example: @codemirror/lang-json - jsonParseLinter and I use in extension - linter(jsonParseLinter()).
Can someone provide a example?
Thank you
Hello!
How use xmlLinter? We have @codemirror/lang-xml, but have not ParseLinter.
Example: @codemirror/lang-json - jsonParseLinter and I use in extension - linter(jsonParseLinter()).
Can someone provide a example?
Thank you
@codemirror/lang-xml does not come with a linter (everything it exports is listed in the readme, so if you don’t find it there, its not in the package).
Thank you @marijn !
Guys, who can share the experience who did the xml lint for CodeMirror v6?
I didn’t understand - https://develop.prosemirror.net/examples/lint/
That’s about a completely different library, so indeed, it won’t help you here. But I am curious where you got that link, since I don’t use the develop.prosemirror.net domain (though the way my server is set up apparently serves up the plain prosemirror.net content on it).
@marijn , I don’t know how I found this link), when I searched the Internet, I looked at a lot of things
Hi! @marijn, I did tags check in xml. Please tell me, how to check for an open quote or equal sign?
Thank you!
const tagLinter = linter(view => {
let diagnostics: Diagnostic[] = []
syntaxTree(view.state).cursor().iterate(node => {
// No open tag
if (node.name == "MismatchedCloseTag") {
let tagName = this.getTagAsString(view.state, node.from, node.to);
diagnostics.push({
from: node.from,
to: node.to,
severity: "error",
message: `No open tag for ${tagName}`
})
}
// No closed the tag
if (node.name == "MissingCloseTag") {
// looking for the tag that led to the problem
let tag = node.node.parent?.firstChild;
let from = tag?.from;
let to = tag?.to;
let tagName = this.getTagAsString(view.state, from, to);
diagnostics.push({
from: from ? from : node.from,
to: to ? to : node.to,
severity: "error",
message: "No closed the tag for " + tagName
})
}
})
return diagnostics;
})
getTagAsString(state: EditorState, from: number | undefined, to: number | undefined): string | undefined {
if (!from || !to) return undefined;
return state.doc.toString().substring(from, to);
}
I don’t really understand the question. Open quotes on attributes aren’t separate tree nodes, they are just part of an attribute value node.
Please don’t do this. You’re serializing a (potentially huge) document in its entirety to then take a tiny substring of it. Use state.doc.sliceDoc(from, to)
.
Hi! @marijn, thank you
but i found this
return state.doc.sliceString(from, to)
for check quotes and “=” did so:
if (node.name == 'Attribute') {
const attributeName = this.getElementAsString(doc, node.from, node.to);
const countOfCharacterEquals = attributeName.replace(/[^=]/g, ''); // Count of '=' characters in attribute with value
const countOfCharacterQuotes = attributeName.replace(/[^"]/g, ''); // Count of quotes in attribute with value
if (countOfCharacterEquals.length === 0) {
this.xmlSyntaxErrors.push({
from: node.from,
to: node.to,
severity: 'error',
message: `Attribute ${attributeName} miss symbol '='`
});
return;
}
if (countOfCharacterEquals.length > 1 || countOfCharacterQuotes.length < 2) {
this.xmlSyntaxErrors.push({
from: node.from,
to: node.to,
severity: 'error',
message: `Have open quote ${attributeName}`
});
}
}