+ NodeJS library that transforms OpenRosa/ODK XForms into a format the Enketo understands. It works both as a library module, as well as a standalone app.Enketo Transformer
(inner) Source:
(inner)
(inne
(inner) _
(inner) _md5
(inner) _pa
(inne
(inner) Source:
(inner)
(inner)
(inner) Source:
(inner) _t
transformer.js
}
: {};
- const mediaMap = Object.fromEntries(
- Object.entries(survey.media || {}).map((entry) =>
- entry.map(escapeURLPath)
- )
- );
+ let mediaMap = null;
+
+ if (survey.media) {
+ mediaMap = Object.fromEntries(
+ Object.entries(survey.media).map((entry) =>
+ entry.map(escapeURLPath)
+ )
+ );
+ }
return _parseXml(survey.xform)
.then((doc) => {
@@ -547,12 +551,15 @@ transformer.js
if (original !== rendered) {
if (mediaMap != null) {
- const fragment = libxmljs.parseHtmlFragment(rendered);
-
- rendered = _replaceMediaSources(
- fragment,
- mediaMap
- ).toString(false);
+ const fragment = libxmljs.parseHtmlFragment(
+ `<div class="temporary-root">${rendered}</div>`
+ );
+
+ rendered = _replaceMediaSources(fragment, mediaMap)
+ .root()
+ .childNodes()
+ .map((node) => node.toString(false))
+ .join('');
}
key = `$$$${index}`;
diff --git a/package-lock.json b/package-lock.json
index ade8f61..f1ad4a1 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "enketo-transformer",
- "version": "2.1.3",
+ "version": "2.1.4",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -2326,9 +2326,9 @@
}
},
"eslint-plugin-react-hooks": {
- "version": "4.4.0",
- "resolved": "https://registry.npmjs.org/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.4.0.tgz",
- "integrity": "sha512-U3RVIfdzJaeKDQKEJbz5p3NW8/L80PCATJAfuojwbaEL+gBjfGdhUcGde+WGUW46Q5sr/NgxevsIiDtNXrvZaQ==",
+ "version": "4.5.0",
+ "resolved": "https://registry.npmjs.org/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.5.0.tgz",
+ "integrity": "sha512-8k1gRt7D7h03kd+SAAlzXkQwWK22BnK6GKZG+FJA6BAGy22CFvl8kCIXKpVux0cCxMWDQUPqSok0LKaZ0aOcCw==",
"dev": true
},
"eslint-plugin-unicorn": {
@@ -4093,12 +4093,6 @@
"requires": {
"has-flag": "^1.0.0"
}
- },
- "wordwrap": {
- "version": "1.0.0",
- "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz",
- "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=",
- "dev": true
}
}
},
@@ -4697,9 +4691,9 @@
},
"dependencies": {
"ansi-regex": {
- "version": "4.1.0",
- "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz",
- "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==",
+ "version": "4.1.1",
+ "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz",
+ "integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==",
"dev": true
},
"astral-regex": {
@@ -4730,9 +4724,9 @@
}
},
"debug": {
- "version": "4.3.3",
- "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz",
- "integrity": "sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==",
+ "version": "4.3.4",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
+ "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
"dev": true,
"requires": {
"ms": "2.1.2"
@@ -5376,9 +5370,9 @@
}
},
"nodemon": {
- "version": "2.0.15",
- "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.15.tgz",
- "integrity": "sha512-gdHMNx47Gw7b3kWxJV64NI+Q5nfl0y5DgDbiVtShiwa7Z0IZ07Ll4RLFo6AjrhzMtoEZn5PDE3/c2AbVsiCkpA==",
+ "version": "2.0.16",
+ "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.16.tgz",
+ "integrity": "sha512-zsrcaOfTWRuUzBn3P44RDliLlp263Z/76FPoHFr3cFFkOz0lTPAcIw8dCzfdVIx/t3AtDYCZRCDkoCojJqaG3w==",
"dev": true,
"requires": {
"chokidar": "^3.5.2",
@@ -7460,9 +7454,9 @@
"dev": true
},
"semver": {
- "version": "7.3.5",
- "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz",
- "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==",
+ "version": "7.3.7",
+ "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz",
+ "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==",
"dev": true,
"requires": {
"lru-cache": "^6.0.0"
diff --git a/package.json b/package.json
index 7a967cf..8b5c0a6 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "enketo-transformer",
- "version": "2.1.3",
+ "version": "2.1.4",
"description": "Library/app that transforms ODK-compliant XForms into a format that Enketo can consume",
"license": "Apache-2.0",
"main": "src/transformer.js",
@@ -62,7 +62,7 @@
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.29.4",
- "eslint-plugin-react-hooks": "^4.4.0",
+ "eslint-plugin-react-hooks": "^4.5.0",
"eslint-plugin-unicorn": "^36.0.0",
"grunt": "^1.5.2",
"http-server": "^13.1.0",
@@ -71,7 +71,7 @@
"jsdoc-plugin-typescript": "^2.0.7",
"markdown-eslint-parser": "^1.2.1",
"mocha": "^9.2.2",
- "nodemon": "^2.0.15",
+ "nodemon": "^2.0.16",
"nyc": "^15.1.0",
"prettier": "^2.6.2",
"rimraf": "^3.0.2"