{"_id":"56b7a33f6c2a240d0094ae96","user":"56b534d0168b5c1700c159a7","version":{"_id":"56b79f817ced7f17003ab196","__v":1,"project":"56b79ef9a6c10c0d00a2d67d","createdAt":"2016-02-07T19:48:17.460Z","releaseDate":"2016-02-07T19:48:17.460Z","categories":["56b79f827ced7f17003ab197"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"2.0.0","version":"2.0"},"project":"56b79ef9a6c10c0d00a2d67d","githubsync":"","__v":3,"category":{"_id":"56b79f827ced7f17003ab197","pages":["56b79f827ced7f17003ab198","56b7a33f6c2a240d0094ae96","56b7a50cd22adc0d0053f4bf","56b7a55deb783a0d0078950f"],"project":"56b79ef9a6c10c0d00a2d67d","version":"56b79f817ced7f17003ab196","__v":4,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-02-07T19:46:02.504Z","from_sync":false,"order":0,"slug":"documentation","title":"Documentation"},"updates":["5815c480dea8d10f0082d996"],"next":{"pages":[],"description":""},"createdAt":"2016-02-07T20:04:15.570Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":999,"body":"Parsing documents using Kurenai couldn't be simpler. First, let's create a document parser.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\nuse Kurenai\\\\Parser;\\nuse Kurenai\\\\Parsers\\\\Metadata\\\\JsonParser;\\nuse Kurenai\\\\Parsers\\\\Content\\\\MarkdownParser;\\n\\n$parser = new Parser(new JsonParser, new MarkdownParser);\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nHere we've created a parser for documents which have JSON metadata, and Markdown content.\n\nFor alternative parsers, simply check the xxxx.\n\nLet's use our newly created parser to parse a document.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n$document = $parser->parse('path/to/document.txt');\\n\\n// or...\\n\\n$document = $parser->parse($documentAsString);\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nYou can specify either a path to a document (with any extension) or provide the document content directly to the `parse()` method.\n\nNow that we have a document, let's see what we can do with it.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n$document->getRaw();                 // Get the raw document content.\\n\\n$document->getMetdata();             // Get document metadata as array.\\n\\n$document->getContent();             // Get the rendered document content.\\n\\n$document->get('foo.bar');           // Use dot-notation to access metadata.\\n\\n$document->get('foo', 'default');    // Provide a default value.\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nUnless you provide a default value, the `get()` method will return null should an array key fail to exist.","excerpt":"","slug":"parsing-documents","type":"basic","title":"Parsing Documents"}
Parsing documents using Kurenai couldn't be simpler. First, let's create a document parser. [block:code] { "codes": [ { "code": "<?php\n\nuse Kurenai\\Parser;\nuse Kurenai\\Parsers\\Metadata\\JsonParser;\nuse Kurenai\\Parsers\\Content\\MarkdownParser;\n\n$parser = new Parser(new JsonParser, new MarkdownParser);", "language": "php" } ] } [/block] Here we've created a parser for documents which have JSON metadata, and Markdown content. For alternative parsers, simply check the xxxx. Let's use our newly created parser to parse a document. [block:code] { "codes": [ { "code": "<?php\n\n$document = $parser->parse('path/to/document.txt');\n\n// or...\n\n$document = $parser->parse($documentAsString);", "language": "php" } ] } [/block] You can specify either a path to a document (with any extension) or provide the document content directly to the `parse()` method. Now that we have a document, let's see what we can do with it. [block:code] { "codes": [ { "code": "<?php\n\n$document->getRaw(); // Get the raw document content.\n\n$document->getMetdata(); // Get document metadata as array.\n\n$document->getContent(); // Get the rendered document content.\n\n$document->get('foo.bar'); // Use dot-notation to access metadata.\n\n$document->get('foo', 'default'); // Provide a default value.", "language": "php" } ] } [/block] Unless you provide a default value, the `get()` method will return null should an array key fail to exist.