Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cshaa/nml-parser
Parser of the Namespace Markup Language
https://github.com/cshaa/nml-parser
Last synced: about 5 hours ago
JSON representation
Parser of the Namespace Markup Language
- Host: GitHub
- URL: https://github.com/cshaa/nml-parser
- Owner: cshaa
- License: apache-2.0
- Created: 2013-09-18T10:48:05.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-09-16T18:51:58.000Z (over 10 years ago)
- Last Synced: 2025-01-17T21:12:55.842Z (8 days ago)
- Language: JavaScript
- Size: 202 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
nml
==Namespace Markup Language parser
##How to set up
To parse a document, you have to create new `nml` object.
```js
var doc = new nml();
```
Then, you can change to `failonerr` mode, that stops the parser if an error occures.
```js
doc.failonerr = true;
```
And finally you should set up _sandbox_ elements - that ones, which may contain only __one text child__ (such as _html:script_ element in html6) **TODO**
```js
doc.sandbox = [
{name:"script",space:"html"},
{name:"textarea",space:"form"},
{name:"customelementsrock"}
];
```
Now you are ready to parse.##How to parse
Before the parsing, you have to load your document (via http or from a local file) into a local variable (as a string), then you can call the `parse` function.
```js
var str = "";
doc.parse(str);
console.log(doc.childs[0]);
```
You can also call the parser asynchronously. **TODO**
```js
doc.parse.on("error",function(e){
console.log(e.line);
console.log(e.collumn);
console.log(e.message);
});
doc.parse.on("success",function(e){
console.log(doc.[0]);
});
doc.parse(str,true);
```
After parsing you will maybe need to export a DOM document. That can be easily done using the `toDOM` function. **TODO**
```js
doc.parse(str);
node = doc.toDOM().body;
document.importNode(node,true);
```