Commit 433434d6 authored by Volker Krause's avatar Volker Krause
Browse files

Parse multi-entry itemprop attributes in Microdata correctly

parent 466b6f01
Pipeline #57766 passed with stages
in 12 minutes and 55 seconds
<article class="post" itemscope itemtype="">
<header class="post-header">
<h1 class="post-title" itemprop="name headline">February/March in KDE Itinerary</h1>
<p class="post-meta">
<time datetime="2021-04-02T11:15:00+02:00" itemprop="datePublished">2021-04-02</time>
<span itemprop="author" itemscope itemtype=""><span itemprop="name">Volker Krause</span></span>
<div class="post-content" itemprop="articleBody">bla</div>
"@context": "",
"@type": "BlogPosting",
"articleBody": "bla",
"author": {
"@type": "Person",
"name": "Volker Krause"
"datePublished": "2021-04-02T11:15:00+02:00",
"headline": "February/March in KDE Itinerary",
"name": "February/March in KDE Itinerary"
......@@ -147,6 +147,15 @@ static QString valueForItemProperty(const HtmlElement &elem)
return v;
static void insertProperties(QJsonObject &obj, const QString &prop, const QJsonValue &val)
// multiple properties can be specified at once, as a space-separated list
const auto props = prop.split(QLatin1Char(' '), Qt::SkipEmptyParts);
for (const auto &p : props) {
obj.insert(p, val);
static void parseMicroData(const HtmlElement &elem, QJsonObject &obj, QJsonArray &result)
auto child = elem.firstChild();
......@@ -161,10 +170,10 @@ static void parseMicroData(const HtmlElement &elem, QJsonObject &obj, QJsonArray
if (prop.isEmpty()) {
result.push_back(subObj); // stand-alone object that just happens to be nested
} else {
obj.insert(prop, subObj);
insertProperties(obj, prop, subObj);
} else if (!prop.isEmpty()) {
obj.insert(prop, valueForItemProperty(child));
insertProperties(obj, prop, valueForItemProperty(child));
// Maybe there is more JSON-LD inside this microdata tree
} else if (isJsonLdTag(child)) {
parseJson(child.content().toUtf8(), result);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment