Skip to content

Commit 8a925a2

Browse files
authored
fix: nested within dt (#279)
1 parent c0451a7 commit 8a925a2

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

src/microformats/parse.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
BackcompatRoot,
1919
} from "../backcompat";
2020
import { applyIncludesToRoot } from "../helpers/includes";
21-
import { parseE } from "./property";
21+
import { parseE, parseDt } from "./property";
2222
import { isEnabled } from "../helpers/experimental";
2323

2424
interface ParseMicroformatOptions extends ParsingOptions {
@@ -85,6 +85,15 @@ export const parseMicroformat = (
8585
textContent(node, options);
8686
}
8787

88+
/**
89+
* The `value` is set as per default parsing as nothing else has been added
90+
* to the spec. A proposal has been made:
91+
* https://github.com/microformats/microformats2-parsing/issues/71
92+
*/
93+
if (options.valueType === "dt") {
94+
item.value = parseDt(node, options);
95+
}
96+
8897
/**
8998
* There is some ambigutity on how this should be handled.
9099
* At the moment, we're following other parsers and keeping `value` a string

src/microformats/property.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const parseU = (
6161
return typeof url === "string" ? url.trim() : url;
6262
};
6363

64-
const parseDt = (node: Element, options: ParsingOptions): string =>
64+
export const parseDt = (node: Element, options: ParsingOptions): string =>
6565
valueClassPattern(node, { ...options, datetime: true }) ??
6666
getAttributeIfTag(node, ["time", "ins", "del"], "datetime") ??
6767
getAttributeIfTag(node, ["abbr"], "title") ??
@@ -122,7 +122,7 @@ export const parseProperty = (
122122
const type = getType(className);
123123
const key = className.replace(propertyRegexp, "");
124124
const value =
125-
["u", "p", "e"].includes(type) && isMicroformatRoot(child)
125+
["u", "p", "e", "dt"].includes(type) && isMicroformatRoot(child)
126126
? parseMicroformat(child, {
127127
...options,
128128
valueType: type,

test/suites/local/microformats-v2/nested.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@
1515
<div class="h-entry">
1616
<div class="u-photo h-card"></div>
1717
</div>
18+
19+
<div class="h-card">
20+
<div class="dt-bday h-event">
21+
<time class="dt-start dt-end" datetime="2010-05-02">2nd May</time>
22+
</div>
23+
</div>

test/suites/local/microformats-v2/nested.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@
6060
}
6161
]
6262
}
63+
},
64+
{
65+
"type": ["h-card"],
66+
"properties": {
67+
"bday": [
68+
{
69+
"type": ["h-event"],
70+
"properties": {
71+
"name": ["2nd May"],
72+
"start": ["2010-05-02"],
73+
"end": ["2010-05-02"]
74+
},
75+
"value": "2nd May"
76+
}
77+
]
78+
}
6379
}
6480
],
6581
"rels": {},

0 commit comments

Comments
 (0)