Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix html entities decoding

ammarahm-ed06ced4499ee6
diff --git a/apps/mobile/patches/html-to-text+8.1.0.patch b/apps/mobile/patches/html-to-text+8.1.0.patch
index 418da0645..7ec93f3ea 100644
--- a/apps/mobile/patches/html-to-text+8.1.0.patch
+++ b/apps/mobile/patches/html-to-text+8.1.0.patch
@@ -27,18 +27,28 @@ index d6cb1e6..68d0337 100644
const href = getHref();
if (!href) {
diff --git a/node_modules/html-to-text/lib/html-to-text.js b/node_modules/html-to-text/lib/html-to-text.js
-index 9ebda73..330a28c 100644
+index 9ebda73..8c5345f 100644
--- a/node_modules/html-to-text/lib/html-to-text.js
+++ b/node_modules/html-to-text/lib/html-to-text.js
@@ -1,6 +1,6 @@
const { hp2Builder } = require('@selderee/plugin-htmlparser2');
const merge = require('deepmerge');
-const he = require('he');
-+const {decode} = require("entities");
++const {decode, EntityLevel} = require("entities");
const htmlparser = require('htmlparser2');
const selderee = require('selderee');
-@@ -377,7 +377,7 @@ function recursiveWalk (walk, dom, builder) {
+@@ -27,8 +27,7 @@ const DEFAULT_OPTIONS = {
+ returnDomByDefault: true
+ },
+ decodeOptions: {
+- isAttributeValue: false,
+- strict: false
++ level:EntityLevel.HTML
+ },
+ formatters: {},
+ limits: {
+@@ -377,7 +376,7 @@ function recursiveWalk (walk, dom, builder) {
for (const elem of dom) {
switch (elem.type) {
case 'text': {
diff --git a/apps/mobile/src/components/NoteItem/index.js b/apps/mobile/src/components/NoteItem/index.js
index 34b9bf558..02309c091 100644
--- a/apps/mobile/src/components/NoteItem/index.js
+++ b/apps/mobile/src/components/NoteItem/index.js
@@ -1,3 +1,4 @@
+import {decode, EntityLevel} from 'entities';
import React, {useEffect} from 'react';
import {Platform, View} from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
@@ -14,7 +15,7 @@ import {ActionIcon} from '../ActionIcon';
import {Button} from '../Button';
import {ActionSheetEvent} from '../DialogManager/recievers';
import {TimeSince} from '../Menu/TimeSince';
-import { Properties } from '../Properties';
+import {Properties} from '../Properties';
import Heading from '../Typography/Heading';
import Paragraph from '../Typography/Paragraph';
@@ -47,7 +48,7 @@ function navigateToTag(item) {
});
}
-const showActionSheet = (item) => {
+const showActionSheet = item => {
Properties.present(item);
};
@@ -56,7 +57,7 @@ const NoteItem = ({item, isTrash, tags, dateBy = 'dateCreated'}) => {
const {colors} = state;
const settings = useSettingStore(state => state.settings);
const compactMode = settings.notesListMode === 'compact';
- const attachmentCount = db.attachments?.ofNote(item.id,'all')?.length || 0;
+ const attachmentCount = db.attachments?.ofNote(item.id, 'all')?.length || 0;
function getNotebook() {
if (isTrash || !item.notebooks || item.notebooks.length < 1) return [];
@@ -136,7 +137,9 @@ const NoteItem = ({item, isTrash, tags, dateBy = 'dateCreated'}) => {
flexWrap: 'wrap'
}}
numberOfLines={2}>
- {item.headline}
+ {decode(item.headline, {
+ level: EntityLevel.HTML
+ })}
</Paragraph>
) : null}
diff --git a/apps/mobile/src/services/Exporter.js b/apps/mobile/src/services/Exporter.js
index d1d04b528..8ff76afb1 100644
--- a/apps/mobile/src/services/Exporter.js
+++ b/apps/mobile/src/services/Exporter.js
@@ -1,4 +1,4 @@
-import { decode } from 'entities';
+import { decode, EntityLevel } from 'entities';
import {Platform} from 'react-native';
import RNHTMLtoPDF from 'react-native-html-to-pdf-lite';
import * as ScopedStorage from 'react-native-scoped-storage';
@@ -324,7 +324,9 @@ async function saveToPDF(note) {
Platform.OS === 'ios' && (await Storage.checkAndCreateDir('/exported/PDF/'));
let html = await db.notes.note(note).export('html');
- html = decode(html);
+ html = decode(html,{
+ level:EntityLevel.HTML
+ });
let fileName = sanitizeFilename(note.title + Date.now(), {replacement: '_'});
let html3 = html;
if (html.indexOf('<head>') > -1) {
diff --git a/apps/mobile/src/utils/linkpreview.ts b/apps/mobile/src/utils/linkpreview.ts
index b48ae7e0a..785aaa044 100644
--- a/apps/mobile/src/utils/linkpreview.ts
+++ b/apps/mobile/src/utils/linkpreview.ts
@@ -1,5 +1,5 @@
import {Image} from 'react-native';
-import {decode} from 'entities';
+import {decode, EntityLevel} from 'entities';
export interface PreviewData {
description?: string;
image?: PreviewDataImage;
@@ -39,7 +39,9 @@ export const getActualImageUrl = (baseUrl: string, imageUrl?: string) => {
export const getHtmlEntitiesDecodedText = (text?: string) => {
const actualText = text?.trim();
if (!actualText) return;
- return decode(actualText);
+ return decode(actualText,{
+ level:EntityLevel.HTML
+ });
};
export const getContent = (left: string, right: string, type: string) => {
diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.js
index 8b01de29a..cd88be705 100644
--- a/apps/mobile/src/views/Editor/Functions.js
+++ b/apps/mobile/src/views/Editor/Functions.js
@@ -666,7 +666,11 @@ function onNoteChange(wait = 300) {
_sid = sessionId;
let params = [title, id, content.data, content.type, sessionId];
timer = setTimeout(() => {
- console.log('saving note', params[1], _sid, sessionId);
+ //console.log('saving note', params[1], _sid, sessionId);
+ if (!params[1]) {
+ console.log('update id to',id);
+ params[1] = id;
+ }
saveNote(...params, _sid !== sessionId);
}, wait);
}
@@ -771,27 +775,27 @@ async function addToCollection(id) {
export async function saveNote(
title,
- id,
+ _id,
data,
type,
sessionId,
preventUpdate
) {
- console.log(disableSaving, isSaving, id);
+ console.log("saving note:", disableSaving, isSaving, _id,id);
if (disableSaving || (isSaving && !id)) return;
if (preventUpdate) {
noteEdited = false;
}
isSaving = true;
try {
- if (id && !db.notes.note(id)) {
+ if (_id && !db.notes.note(_id)) {
clearNote();
useEditorStore.getState().setCurrentlyEditingNote(null);
return;
}
let locked = false;
- if (id) {
- let _note = db.notes.note(id).data;
+ if (_id) {
+ let _note = db.notes.note(_id).data;
if (_note.conflicted) {
presentResolveConflictDialog(_note);
return;
@@ -820,7 +824,7 @@ export async function saveNote(
data: data,
type: type
},
- id: id,
+ id: _id,
sessionId: isContentInvalid(data) ? null : sessionId
};
@@ -834,7 +838,8 @@ export async function saveNote(
if (!locked) {
let noteId = await db.notes.add(noteData);
- if (!id || saveCounter < 3) {
+ id = noteId;
+ if (!_id || saveCounter < 3) {
Navigation.setRoutesToUpdate([
Navigation.routeNames.Notes,
Navigation.routeNames.Favorites,
@@ -842,20 +847,18 @@ export async function saveNote(
Navigation.routeNames.Notebook
]);
}
-
- if (!id) {
+ if (!_id) {
await addToCollection(noteId);
}
- if (!id && !preventUpdate) {
+ if (!_id && !preventUpdate) {
if (!title || title === '') {
console.log('posting title now');
post('titleplaceholder', db.notes.note(noteId)?.data?.title || '');
}
- await setNoteInEditorAfterSaving(id, noteId);
+ await setNoteInEditorAfterSaving(_id, noteId);
saveCounter++;
- id = noteId;
setTimeout(() => {
useEditorStore.getState().setCurrentlyEditingNote(noteId);
});
@@ -872,7 +875,7 @@ export async function saveNote(
]);
lastEditTime = n + 10;
- let n = db.notes.note(id)?.data?.dateEdited;
+ let n = db.notes.note(_id)?.data?.dateEdited;
tiny.call(
EditorWebView,
tiny.updateDateEdited(n ? timeConverter(n) : '')