Skip to content

TagSpaces is an offline, open source, document manager with tagging support

fix: add new implementation for removing markdown

Ilian Sapundshieve30ca64afce2
diff --git a/app/perspectives/grid-perspective/components/CellContent.tsx b/app/perspectives/grid-perspective/components/CellContent.tsx
index e197eb290..d22a35b27 100644
--- a/app/perspectives/grid-perspective/components/CellContent.tsx
+++ b/app/perspectives/grid-perspective/components/CellContent.tsx
@@ -17,7 +17,6 @@
*/
import React from 'react';
-import removeMd from 'remove-markdown';
import classNames from 'classnames';
import Grid from '@material-ui/core/Grid';
import Typography from '@material-ui/core/Typography';
@@ -33,7 +32,8 @@ import { formatFileSize, formatDateTime } from '-/utils/misc';
import { extractTagsAsObjects, extractTitle } from '-/utils/paths';
import {
findBackgroundColorForFolder,
- findColorForEntry
+ findColorForEntry,
+ removeMarkDown
} from '-/services/utils-io';
import TagContainerDnd from '-/components/TagContainerDnd';
import TagContainer from '-/components/TagContainer';
@@ -102,12 +102,13 @@ const CellContent = (props: Props) => {
PlatformIO.getDirSeparator()
);
- let description = removeMd(fsEntry.description);
-
- if (description.length > maxDescriptionPreviewLength) {
+ let { description } = fsEntry;
+ if (description && description.length > maxDescriptionPreviewLength) {
description = description.substr(0, maxDescriptionPreviewLength) + '...';
}
+ description = removeMarkDown(description);
+
if (description && layoutType === 'row' && fsEntry.isFile) {
description = ' | ' + description;
}
@@ -181,7 +182,7 @@ const CellContent = (props: Props) => {
<div id="gridCellTags" className={classes.gridCellTags}>
{showTags && entryTags ? renderTags(entryTags) : tagPlaceholder}
</div>
- {description.length > 0 && (
+ {description && (
<Typography
id="gridCellDescription"
className={classes.gridCellDescription}
diff --git a/app/services/utils-io.ts b/app/services/utils-io.ts
index fb69942de..3a5a32db8 100644
--- a/app/services/utils-io.ts
+++ b/app/services/utils-io.ts
@@ -17,6 +17,8 @@
*/
import { v1 as uuidv1 } from 'uuid';
+import marked from 'marked';
+import DOMPurify from 'dompurify';
import {
loadIndex,
enhanceDirectoryIndex,
@@ -1108,3 +1110,12 @@ export function loadFileContentPromise(
xhr.send();
});
}
+
+export function removeMarkDown(mdContent) {
+ if (!mdContent) return '';
+ let result = marked(DOMPurify.sanitize(mdContent));
+ const span = document.createElement('span');
+ span.innerHTML = result;
+ result = span.textContent || span.innerText;
+ return result;
+}
diff --git a/package.json b/package.json
index 871f80431..142d34263 100644
--- a/package.json
+++ b/package.json
@@ -152,7 +152,7 @@
"@material-ui/icons": "^4.11.2",
"@material-ui/lab": "^4.0.0-alpha.57",
"@material-ui/pickers": "^3.2.10",
- "@tagspaces/tagspaces-platforms": "^1.0.53",
+ "@tagspaces/tagspaces-platforms": "^1.0.54",
"aws-amplify": "^3.3.27",
"aws-sdk": "^2.984.0",
"babel-polyfill": "^6.26.0",
@@ -165,7 +165,7 @@
"crypto-js": "^4.0.0",
"csv-stringify": "^5.6.2",
"date-fns": "^2.0.0-beta.4",
- "dompurify": "^2.2.7",
+ "dompurify": "^2.3.3",
"electron-debug": "^3.2.0",
"electron-window-state": "^5.0.3",
"exif-js": "^2.3.0",
@@ -179,7 +179,7 @@
"i18next-http-backend": "^1.2.8",
"jszip": "^3.1.5",
"leaflet": "^1.7.1",
- "marked": "^2.0.1",
+ "marked": "^3.0.8",
"material-design-icons": "^3.0.1",
"mgrs": "^1.0.0",
"open-location-code": "^1.0.3",
@@ -205,7 +205,6 @@
"redux": "^3.7.2",
"redux-persist": "^5.10.0",
"redux-thunk": "^2.3.0",
- "remove-markdown": "^0.3.0",
"semver": "^5.5.0",
"source-map-support": "^0.5.11",
"sync-fetch": "^0.3.0",
diff --git a/yarn.lock b/yarn.lock
index 8f91761cd..47715e1a2 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3362,10 +3362,10 @@
dependencies:
defer-to-connect "^1.0.1"
-"@tagspaces/tagspaces-platforms@^1.0.53":
- version "1.0.53"
- resolved "https://registry.yarnpkg.com/@tagspaces/tagspaces-platforms/-/tagspaces-platforms-1.0.53.tgz#ac4aedf48d042c6e7e760d327b1efa6b2218e43c"
- integrity sha512-6N5K5msBYiQsav2Qsy6meqMGezfPvWj2ezH7NgVzkgMQbLeuP40RSPN0vbmOFCSufb39L01KTx8y0dCwqq6HQg==
+"@tagspaces/tagspaces-platforms@^1.0.54":
+ version "1.0.54"
+ resolved "https://registry.yarnpkg.com/@tagspaces/tagspaces-platforms/-/tagspaces-platforms-1.0.54.tgz#cfb67def5e341ead659086618452f9599b724a6f"
+ integrity sha512-6/AhsTTg0SCfz+HjpMos1WbWQ/3nXXf/z1q2eq6h4UR/vGqdH6Y8FtcnzpaD8a0n0oQ6vi1DZqDxq36ukmv5ww==
"@testim/chrome-version@^1.0.7":
version "1.0.7"
@@ -7828,10 +7828,10 @@ [email protected]:
resolved "https://registry.yarnpkg.com/dompurify/-/dompurify-2.3.1.tgz#a47059ca21fd1212d3c8f71fdea6943b8bfbdf6a"
integrity sha512-xGWt+NHAQS+4tpgbOAI08yxW0Pr256Gu/FNE2frZVTbgrBUn8M7tz7/ktS/LZ2MHeGqz6topj0/xY+y8R5FBFw==
-dompurify@^2.2.7:
- version "2.2.7"
- resolved "https://registry.npmjs.org/dompurify/-/dompurify-2.2.7.tgz"
- integrity sha512-jdtDffdGNY+C76jvodNTu9jt5yYj59vuTUyx+wXdzcSwAGTYZDAQkQ7Iwx9zcGrA4ixC1syU4H3RZROqRxokxg==
+dompurify@^2.3.3:
+ version "2.3.3"
+ resolved "https://registry.yarnpkg.com/dompurify/-/dompurify-2.3.3.tgz#c1af3eb88be47324432964d8abc75cf4b98d634c"
+ integrity sha512-dqnqRkPMAjOZE0FogZ+ceJNM2dZ3V/yNOuFB7+39qpO93hHhfRpHw3heYQC7DPK9FqbQTfBKUJhiSfz4MvXYwg==
[email protected], domutils@^1.5.1:
version "1.5.1"
@@ -13003,10 +13003,10 @@ markdown-table@^2.0.0:
dependencies:
repeat-string "^1.0.0"
-marked@^2.0.1:
- version "2.0.1"
- resolved "https://registry.npmjs.org/marked/-/marked-2.0.1.tgz"
- integrity sha512-5+/fKgMv2hARmMW7DOpykr2iLhl0NgjyELk5yn92iE7z8Se1IS9n3UsFm86hFXIkvMBmVxki8+ckcpjBeyo/hw==
+marked@^3.0.8:
+ version "3.0.8"
+ resolved "https://registry.yarnpkg.com/marked/-/marked-3.0.8.tgz#2785f0dc79cbdc6034be4bb4f0f0a396bd3f8aeb"
+ integrity sha512-0gVrAjo5m0VZSJb4rpL59K1unJAMb/hm8HRXqasD8VeC8m91ytDPMritgFSlKonfdt+rRYYpP/JfLxgIX8yoSw==
matcher@^1.0.0:
version "1.1.1"
@@ -16692,11 +16692,6 @@ remark@^13.0.0:
remark-stringify "^9.0.0"
unified "^9.1.0"
-remove-markdown@^0.3.0:
- version "0.3.0"
- resolved "https://registry.npmjs.org/remove-markdown/-/remove-markdown-0.3.0.tgz"
- integrity sha1-XktmdJOpNXlyjz1S7MHbnKUF3Jg=
-
remove-trailing-separator@^1.0.1:
version "1.1.0"
resolved "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz"