Skip to content

Commit 1e4a025

Browse files
authored
fix: Handle empty alt for images in implied p-name (#413)
* fix: ignore empty attributes * test: tests for implied name with empty alt in img * fix: use impliedTextContent when parsing p-*
1 parent b1057a4 commit 1e4a025

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

src/helpers/attributes.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ export const getAttribute = (
88
export const getAttributeValue = (
99
node: Element,
1010
name: string,
11-
): string | undefined => getAttribute(node, name)?.value;
11+
): string | undefined => {
12+
const attr = getAttribute(node, name)?.value;
13+
return attr?.length ? attr : undefined;
14+
};
1215

1316
export const getClassNames = (
1417
node: Element,

src/microformats/property.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import { isMicroformatRoot } from "../helpers/nodeMatchers";
1717
import { parseMicroformat } from "./parse";
1818
import { valueClassPattern } from "../helpers/valueClassPattern";
19-
import { textContent } from "../helpers/textContent";
19+
import { textContent, impliedTextContent } from "../helpers/textContent";
2020
import { parseImage } from "../helpers/images";
2121
import { isLocalLink, applyBaseUrl } from "../helpers/url";
2222
import { convertV1PropertyClassNames } from "../backcompat";
@@ -36,7 +36,7 @@ export const parseP = (node: Element, options: ParsingOptions): string =>
3636
getAttributeIfTag(node, ["data"], "value") ??
3737
getAttributeIfTag(node, ["img", "area"], "alt") ??
3838
getAttributeIfTag(node, ["meta"], "content") ??
39-
textContent(node, options);
39+
impliedTextContent(node, options);
4040

4141
export const parseU = (
4242
node: Element,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<a class="p-author h-card u-url" href="/">
2+
Author
3+
<img class="u-photo" src="/photo.jpg" alt="" />
4+
</a>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"rels": {},
3+
"rel-urls": {},
4+
"items": [
5+
{
6+
"type": ["h-card"],
7+
"properties": {
8+
"photo": ["http://example.com/photo.jpg"],
9+
"name": ["Author"]
10+
}
11+
}
12+
]
13+
}

0 commit comments

Comments
 (0)