Add XML support for textlint.
But, This is a example. Proof of concept of XML support.
What is textlint plugin? Please see https://github.com/textlint/textlint/blob/master/docs/plugin.md
XML is a data. It means that XML has various format and nodes.
SO, One XML plugin impossible to support all XML format.
This example aim to parse following XML:
<?xml version="1.0" encoding="UTF-8"?>
<note>
<heading>Reminder</heading>
<body>TODO: This is TODO</body>
</note>
notenodeheadernodebodynode
A typical TxtNode has following type:
- Document
- Paragraph
- Header
- Str
We do that map each node to typical node type.
notenode =>Paragraphtypeheadernode =>Headertypebodynode =>Paragraphtype<body>string</body>=> string isStrtype
Parse XML to TxtNode:
<?xml version="1.0" encoding="UTF-8"?>
<note><body>string</body></note>to
{
"type": "Document",
"children": [
{
"type": "Unknown",
"name": "?xml",
"value": "?xml version=\"1.0\" encoding=\"UTF-8\"?",
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 38
}
},
"range": [
0,
38
],
"raw": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
},
{
"type": "Str",
"value": "\n",
"loc": {
"start": {
"line": 1,
"column": 38
},
"end": {
"line": 2,
"column": 0
}
},
"range": [
38,
39
],
"raw": "\n"
},
{
"type": "Paragraph",
"tagName": "note",
"properties": {},
"children": [
{
"type": "Paragraph",
"tagName": "body",
"properties": {},
"children": [
{
"type": "Str",
"value": "string",
"loc": {
"start": {
"line": 2,
"column": 12
},
"end": {
"line": 2,
"column": 18
}
},
"range": [
51,
57
],
"raw": "string"
}
],
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 2,
"column": 25
}
},
"range": [
45,
64
],
"raw": "<body>string</body>"
}
],
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 32
}
},
"range": [
39,
71
],
"raw": "<note><body>string</body></note>"
}
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 32
}
},
"range": [
0,
71
],
"raw": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<note><body>string</body></note>"
}- https://github.com/textlint/textlint/blob/master/docs/plugin.md
- https://github.com/textlint/textlint-plugin-html
- Install(but, this example is not published to npm)
- Manually add xml plugin to do following:
{
"plugins": [
"xml-example"
]
}
Run
$ textlint example.xmlnpm test
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request :D
MIT