Skip to content

Commit dc0d90d

Browse files
authored
Merge pull request #123 from aaronpk/master
Moves language parsing behind feature flag, and prep for v0.3.2 release
2 parents 84bd6ef + 9138ea4 commit dc0d90d

File tree

5 files changed

+150
-108
lines changed

5 files changed

+150
-108
lines changed

Mf2/Parser.php

+13-6
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ class Parser {
277277

278278
public $jsonMode;
279279

280+
/** @var boolean Whether to include experimental language parsing in the result */
281+
public $lang = false;
282+
280283
/**
281284
* Elements upgraded to mf2 during backcompat
282285
* @var SplObjectStorage
@@ -811,9 +814,11 @@ public function parseE(\DOMElement $e) {
811814
'value' => unicodeTrim($this->innerText($e)),
812815
);
813816

814-
// Language
815-
if ( $html_lang = $this->language($e) ) {
816-
$return['html-lang'] = $html_lang;
817+
if($this->lang) {
818+
// Language
819+
if ( $html_lang = $this->language($e) ) {
820+
$return['html-lang'] = $html_lang;
821+
}
817822
}
818823

819824
return $return;
@@ -1073,9 +1078,11 @@ public function parseH(\DOMElement $e, $is_backcompat = false) {
10731078
}
10741079
}
10751080

1076-
// Language
1077-
if ( $html_lang = $this->language($e) ) {
1078-
$return['html-lang'] = $html_lang;
1081+
if($this->lang) {
1082+
// Language
1083+
if ( $html_lang = $this->language($e) ) {
1084+
$return['html-lang'] = $html_lang;
1085+
}
10791086
}
10801087

10811088
// Make sure things are in alphabetical order

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,24 @@ $parser->parse(true, $elementIWant); // returns a document with only the Microfo
229229
230230
```
231231
232+
### Experimental Language Parsing
233+
234+
There is still [ongoing brainstorming](http://microformats.org/wiki/microformats2-parsing-brainstorming#Parse_language_information) around how HTML language attributes should be added to the parsed result. In order to use this feature, you will need to set a flag to opt in.
235+
236+
```php
237+
$doc = '<div class="h-entry" lang="sv" id="postfrag123">
238+
<h1 class="p-name">En svensk titel</h1>
239+
<div class="e-content" lang="en">With an <em>english</em> summary</div>
240+
<div class="e-content">Och <em>svensk</em> huvudtext</div>
241+
</div>';
242+
$parser = new Mf2\Parser($doc);
243+
$parser->lang = true;
244+
$result = $parser->parse();
245+
```
246+
247+
Note that this option is still considered experimental and in development, and the parsed output may change between minor releases.
248+
249+
232250
### Generating output for JSON serialization with JSON-mode
233251
234252
Due to a quirk with the way PHP arrays work, there is an edge case ([reported](https://github.com/indieweb/php-mf2/issues/29) by Tom Morris) in which a document with no rel values, when serialised as JSON, results in an empty object as the rels value rather than an empty array. Replacing this in code with a stdClass breaks PHP iteration over the values.
@@ -289,6 +307,14 @@ Currently php-mf2 passes the majority of it’s own test case, and a good percen
289307

290308
### Changelog
291309

310+
#### v0.3.2
311+
312+
2017-05-27
313+
314+
* Fixed how the Microformats tests repo is loaded via composer
315+
* Moved experimental language parsing feature behind an opt-in flag
316+
* [#121](https://github.com/indieweb/php-mf2/pull/121) Fixed language detection to support parsing of HTML fragments
317+
292318
#### v0.3.1
293319

294320
2017-05-24

composer.json

+3-9
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,14 @@
99
"homepage": "http://waterpigs.co.uk"
1010
}
1111
],
12-
"repositories": [
13-
{
14-
"type": "vcs",
15-
"url": "https://github.com/microformats/tests"
16-
}
17-
],
1812
"bin": ["bin/fetch-mf2", "bin/parse-mf2"],
1913
"require": {
20-
"php": ">=5.4.0",
21-
"microformats/test": "@dev"
14+
"php": ">=5.4.0"
2215
},
2316
"require-dev": {
2417
"phpunit/phpunit": "4.8.*",
25-
"phpdocumentor/phpdocumentor": "v2.8.4"
18+
"phpdocumentor/phpdocumentor": "v2.8.4",
19+
"mf2/tests": "@dev"
2620
},
2721
"autoload": {
2822
"files": ["Mf2/Parser.php"]

0 commit comments

Comments
 (0)