Spaces:
Running
Running
parseYaml: strip inline comments
Browse files- index.html +6 -1
index.html
CHANGED
|
@@ -113,7 +113,12 @@ function parseYaml(txt) {
|
|
| 113 |
const o = {};
|
| 114 |
for (const line of txt.split("\n")) {
|
| 115 |
const m = line.match(/^([a-zA-Z_]+):\s*(.*)$/);
|
| 116 |
-
if (m)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
}
|
| 118 |
return o;
|
| 119 |
}
|
|
|
|
| 113 |
const o = {};
|
| 114 |
for (const line of txt.split("\n")) {
|
| 115 |
const m = line.match(/^([a-zA-Z_]+):\s*(.*)$/);
|
| 116 |
+
if (!m) continue;
|
| 117 |
+
let v = m[2].trim();
|
| 118 |
+
// strip an inline comment that isn't inside quotes
|
| 119 |
+
if (!/^["']/.test(v)) v = v.replace(/\s+#.*$/, "").trim();
|
| 120 |
+
v = v.replace(/^["']|["']$/g, "");
|
| 121 |
+
if (v) o[m[1]] = v;
|
| 122 |
}
|
| 123 |
return o;
|
| 124 |
}
|