Skip to content

Commit

Permalink
fix: nested within dt (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zegnat authored Nov 13, 2023
1 parent c0451a7 commit 8a925a2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/microformats/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
BackcompatRoot,
} from "../backcompat";
import { applyIncludesToRoot } from "../helpers/includes";
import { parseE } from "./property";
import { parseE, parseDt } from "./property";
import { isEnabled } from "../helpers/experimental";

interface ParseMicroformatOptions extends ParsingOptions {
Expand Down Expand Up @@ -85,6 +85,15 @@ export const parseMicroformat = (
textContent(node, options);
}

/**
* The `value` is set as per default parsing as nothing else has been added
* to the spec. A proposal has been made:
* https://github.com/microformats/microformats2-parsing/issues/71
*/
if (options.valueType === "dt") {
item.value = parseDt(node, options);
}

/**
* There is some ambigutity on how this should be handled.
* At the moment, we're following other parsers and keeping `value` a string
Expand Down
4 changes: 2 additions & 2 deletions src/microformats/property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const parseU = (
return typeof url === "string" ? url.trim() : url;
};

const parseDt = (node: Element, options: ParsingOptions): string =>
export const parseDt = (node: Element, options: ParsingOptions): string =>
valueClassPattern(node, { ...options, datetime: true }) ??
getAttributeIfTag(node, ["time", "ins", "del"], "datetime") ??
getAttributeIfTag(node, ["abbr"], "title") ??
Expand Down Expand Up @@ -122,7 +122,7 @@ export const parseProperty = (
const type = getType(className);
const key = className.replace(propertyRegexp, "");
const value =
["u", "p", "e"].includes(type) && isMicroformatRoot(child)
["u", "p", "e", "dt"].includes(type) && isMicroformatRoot(child)
? parseMicroformat(child, {
...options,
valueType: type,
Expand Down
6 changes: 6 additions & 0 deletions test/suites/local/microformats-v2/nested.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@
<div class="h-entry">
<div class="u-photo h-card"></div>
</div>

<div class="h-card">
<div class="dt-bday h-event">
<time class="dt-start dt-end" datetime="2010-05-02">2nd May</time>
</div>
</div>
16 changes: 16 additions & 0 deletions test/suites/local/microformats-v2/nested.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@
}
]
}
},
{
"type": ["h-card"],
"properties": {
"bday": [
{
"type": ["h-event"],
"properties": {
"name": ["2nd May"],
"start": ["2010-05-02"],
"end": ["2010-05-02"]
},
"value": "2nd May"
}
]
}
}
],
"rels": {},
Expand Down

0 comments on commit 8a925a2

Please sign in to comment.