You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-29 22:48:10 +02:00
Desktop, Cli: Some imported ENEX files incorrectly had invisible sections
This commit is contained in:
1
packages/app-cli/tests/enex_to_md/invisible_text3.html
Normal file
1
packages/app-cli/tests/enex_to_md/invisible_text3.html
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<span style="color: rgb(5, 5, 5); font-family: "Segoe UI Historic", "Segoe UI", Helvetica, Arial, sans-serif; font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(240, 242, 245); text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;">This should not actually be visible</span>
|
||||||
1
packages/app-cli/tests/enex_to_md/invisible_text3.md
Normal file
1
packages/app-cli/tests/enex_to_md/invisible_text3.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
This should not actually be visible
|
||||||
@@ -3,6 +3,7 @@ import { ResourceEntity } from './services/database/types';
|
|||||||
const stringPadding = require('string-padding');
|
const stringPadding = require('string-padding');
|
||||||
const stringToStream = require('string-to-stream');
|
const stringToStream = require('string-to-stream');
|
||||||
const resourceUtils = require('./resourceUtils.js');
|
const resourceUtils = require('./resourceUtils.js');
|
||||||
|
const cssParser = require('css');
|
||||||
|
|
||||||
const BLOCK_OPEN = '[[BLOCK_OPEN]]';
|
const BLOCK_OPEN = '[[BLOCK_OPEN]]';
|
||||||
const BLOCK_CLOSE = '[[BLOCK_CLOSE]]';
|
const BLOCK_CLOSE = '[[BLOCK_CLOSE]]';
|
||||||
@@ -423,10 +424,23 @@ function attributeToLowerCase(node: any) {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isInvisibleBlock(attributes: any) {
|
function cssValue(context: any, style: string, propName: string): string {
|
||||||
const style = attributes.style;
|
if (!style) return null;
|
||||||
if (!style) return false;
|
|
||||||
return !!style.match(/display:[\s\S]*none/);
|
try {
|
||||||
|
const o = cssParser.parse(`pre {${style}}`);
|
||||||
|
if (!o.stylesheet.rules.length) return null;
|
||||||
|
const prop = o.stylesheet.rules[0].declarations.find((d: any) => d.property.toLowerCase() === propName);
|
||||||
|
return prop && prop.value ? prop.value.trim().toLowerCase() : null;
|
||||||
|
} catch (error) {
|
||||||
|
displaySaxWarning(context, error.message);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function isInvisibleBlock(context: any, attributes: any) {
|
||||||
|
const display = cssValue(context, attributes.style, 'display');
|
||||||
|
return display && display.indexOf('none') === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isSpanWithStyle(attributes: any) {
|
function isSpanWithStyle(attributes: any) {
|
||||||
@@ -560,7 +574,7 @@ function enexXmlToMdArray(stream: any, resources: ResourceEntity[]): Promise<Ene
|
|||||||
saxStream.on('opentag', function(node: any) {
|
saxStream.on('opentag', function(node: any) {
|
||||||
const nodeAttributes = attributeToLowerCase(node);
|
const nodeAttributes = attributeToLowerCase(node);
|
||||||
const n = node.name.toLowerCase();
|
const n = node.name.toLowerCase();
|
||||||
const isVisible = !isInvisibleBlock(nodeAttributes);
|
const isVisible = !isInvisibleBlock(this, nodeAttributes);
|
||||||
|
|
||||||
state.tags.push({
|
state.tags.push({
|
||||||
name: n,
|
name: n,
|
||||||
@@ -653,7 +667,7 @@ function enexXmlToMdArray(stream: any, resources: ResourceEntity[]): Promise<Ene
|
|||||||
|
|
||||||
section.lines.push(newSection);
|
section.lines.push(newSection);
|
||||||
section = newSection;
|
section = newSection;
|
||||||
} else if (isInvisibleBlock(nodeAttributes)) {
|
} else if (!isVisible) {
|
||||||
const newSection: Section = {
|
const newSection: Section = {
|
||||||
type: SectionType.Hidden,
|
type: SectionType.Hidden,
|
||||||
lines: [],
|
lines: [],
|
||||||
|
|||||||
27
packages/lib/package-lock.json
generated
27
packages/lib/package-lock.json
generated
@@ -1057,8 +1057,7 @@
|
|||||||
"atob": {
|
"atob": {
|
||||||
"version": "2.1.2",
|
"version": "2.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz",
|
||||||
"integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==",
|
"integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"aws-sdk": {
|
"aws-sdk": {
|
||||||
"version": "2.783.0",
|
"version": "2.783.0",
|
||||||
@@ -1712,6 +1711,27 @@
|
|||||||
"resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz",
|
||||||
"integrity": "sha1-iNf/fsDfuG9xPch7u0LQRNPmxBs="
|
"integrity": "sha1-iNf/fsDfuG9xPch7u0LQRNPmxBs="
|
||||||
},
|
},
|
||||||
|
"css": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/css/-/css-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-DG9pFfwOrzc+hawpmqX/dHYHJG+Bsdb0klhyi1sDneOgGOXy9wQIC8hzyVp1e4NRYDBdxcylvywPkkXCHAzTyQ==",
|
||||||
|
"requires": {
|
||||||
|
"inherits": "^2.0.4",
|
||||||
|
"source-map": "^0.6.1",
|
||||||
|
"source-map-resolve": "^0.6.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"source-map-resolve": {
|
||||||
|
"version": "0.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/source-map-resolve/-/source-map-resolve-0.6.0.tgz",
|
||||||
|
"integrity": "sha512-KXBr9d/fO/bWo97NXsPIAW1bFSBOuCnjbNTBMO7N59hsv5i9yzRDfcYwwt0l04+VqnKC+EwzvJZIP/qkuMgR/w==",
|
||||||
|
"requires": {
|
||||||
|
"atob": "^2.1.2",
|
||||||
|
"decode-uri-component": "^0.2.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"cssom": {
|
"cssom": {
|
||||||
"version": "0.4.4",
|
"version": "0.4.4",
|
||||||
"resolved": "https://registry.npmjs.org/cssom/-/cssom-0.4.4.tgz",
|
"resolved": "https://registry.npmjs.org/cssom/-/cssom-0.4.4.tgz",
|
||||||
@@ -1766,8 +1786,7 @@
|
|||||||
"decode-uri-component": {
|
"decode-uri-component": {
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz",
|
||||||
"integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=",
|
"integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"deep-extend": {
|
"deep-extend": {
|
||||||
"version": "0.6.0",
|
"version": "0.6.0",
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
"chokidar": "^3.4.3",
|
"chokidar": "^3.4.3",
|
||||||
"color": "3.1.2",
|
"color": "3.1.2",
|
||||||
"compare-versions": "^3.6.0",
|
"compare-versions": "^3.6.0",
|
||||||
|
"css": "^3.0.0",
|
||||||
"diff-match-patch": "^1.0.4",
|
"diff-match-patch": "^1.0.4",
|
||||||
"es6-promise-pool": "^2.5.0",
|
"es6-promise-pool": "^2.5.0",
|
||||||
"file-uri-to-path": "^1.0.0",
|
"file-uri-to-path": "^1.0.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user