mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-27 10:32:58 +02:00
Desktop, Cli: Some imported ENEX files incorrectly had invisible sections
This commit is contained in:
parent
63a5bfa756
commit
f7a457fb6c
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 stringToStream = require('string-to-stream');
|
||||
const resourceUtils = require('./resourceUtils.js');
|
||||
const cssParser = require('css');
|
||||
|
||||
const BLOCK_OPEN = '[[BLOCK_OPEN]]';
|
||||
const BLOCK_CLOSE = '[[BLOCK_CLOSE]]';
|
||||
@ -423,10 +424,23 @@ function attributeToLowerCase(node: any) {
|
||||
return output;
|
||||
}
|
||||
|
||||
function isInvisibleBlock(attributes: any) {
|
||||
const style = attributes.style;
|
||||
if (!style) return false;
|
||||
return !!style.match(/display:[\s\S]*none/);
|
||||
function cssValue(context: any, style: string, propName: string): string {
|
||||
if (!style) return null;
|
||||
|
||||
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) {
|
||||
@ -560,7 +574,7 @@ function enexXmlToMdArray(stream: any, resources: ResourceEntity[]): Promise<Ene
|
||||
saxStream.on('opentag', function(node: any) {
|
||||
const nodeAttributes = attributeToLowerCase(node);
|
||||
const n = node.name.toLowerCase();
|
||||
const isVisible = !isInvisibleBlock(nodeAttributes);
|
||||
const isVisible = !isInvisibleBlock(this, nodeAttributes);
|
||||
|
||||
state.tags.push({
|
||||
name: n,
|
||||
@ -653,7 +667,7 @@ function enexXmlToMdArray(stream: any, resources: ResourceEntity[]): Promise<Ene
|
||||
|
||||
section.lines.push(newSection);
|
||||
section = newSection;
|
||||
} else if (isInvisibleBlock(nodeAttributes)) {
|
||||
} else if (!isVisible) {
|
||||
const newSection: Section = {
|
||||
type: SectionType.Hidden,
|
||||
lines: [],
|
||||
|
27
packages/lib/package-lock.json
generated
27
packages/lib/package-lock.json
generated
@ -1057,8 +1057,7 @@
|
||||
"atob": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz",
|
||||
"integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==",
|
||||
"dev": true
|
||||
"integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg=="
|
||||
},
|
||||
"aws-sdk": {
|
||||
"version": "2.783.0",
|
||||
@ -1712,6 +1711,27 @@
|
||||
"resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz",
|
||||
"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": {
|
||||
"version": "0.4.4",
|
||||
"resolved": "https://registry.npmjs.org/cssom/-/cssom-0.4.4.tgz",
|
||||
@ -1766,8 +1786,7 @@
|
||||
"decode-uri-component": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz",
|
||||
"integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=",
|
||||
"dev": true
|
||||
"integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU="
|
||||
},
|
||||
"deep-extend": {
|
||||
"version": "0.6.0",
|
||||
|
@ -35,6 +35,7 @@
|
||||
"chokidar": "^3.4.3",
|
||||
"color": "3.1.2",
|
||||
"compare-versions": "^3.6.0",
|
||||
"css": "^3.0.0",
|
||||
"diff-match-patch": "^1.0.4",
|
||||
"es6-promise-pool": "^2.5.0",
|
||||
"file-uri-to-path": "^1.0.0",
|
||||
|
Loading…
Reference in New Issue
Block a user