A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix theme not applied in extension
ammarahm-edf47da530450f
diff --git a/apps/mobile/android/app/src/main/assets/plaineditor.html b/apps/mobile/android/app/src/main/assets/plaineditor.htmlindex 68a061c6a..7adf6afc5 100644--- a/apps/mobile/android/app/src/main/assets/plaineditor.html+++ b/apps/mobile/android/app/src/main/assets/plaineditor.html@@ -153,23 +153,6 @@mask-size: 15px 15px;mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='24' width='24'%3E%3Cpath d='M7.5,18A5.5,5.5 0 0,1 2,12.5A5.5,5.5 0 0,1 7.5,7H18A4,4 0 0,1 22,11A4,4 0 0,1 18,15H9.5A2.5,2.5 0 0,1 7,12.5A2.5,2.5 0 0,1 9.5,10H17V11.5H9.5A1,1 0 0,0 8.5,12.5A1,1 0 0,0 9.5,13.5H18A2.5,2.5 0 0,0 20.5,11A2.5,2.5 0 0,0 18,8.5H7.5A4,4 0 0,0 3.5,12.5A4,4 0 0,0 7.5,16.5H17V18H7.5Z'%3E%3C/path%3E%3C/svg%3E");}-- .mce-content-body code[data-mce-selected="inline-boundary"] {- background-color: #f0f0f0 !important;- }-- .mce-content-body code {- background-color: #f0f0f0 !important;- border: 1px solid var(--border);- border-radius: 5px;- padding: 3px 5px 0px 5px;- }-- code {- font-family: ui-monospace, SFMono-Regular, SF Mono, Consolas, Liberation Mono,- Menlo, monospace !important;- font-size: 10pt !important- }</style></head>@@ -179,7 +162,7 @@</div><script src="./constants.js"></script><script src="./listeners.js"></script>-+<script>function reactNativeEventHandler(type, value) {if (window.ReactNativeWebView) {diff --git a/apps/mobile/html/Web.bundle/site/constants.js b/apps/mobile/html/Web.bundle/site/constants.jsindex a3ce3e1b4..e8d0f10d8 100755--- a/apps/mobile/html/Web.bundle/site/constants.js+++ b/apps/mobile/html/Web.bundle/site/constants.js@@ -23,53 +23,53 @@ let pageTheme = {};const markdownPatterns = [- {start: '*', end: '*', format: 'italic'},- {start: '**', end: '**', format: 'bold'},- {start: '`', end: '`', format: 'code'},- {start: '#', format: 'h1'},- {start: '##', format: 'h2'},- {start: '###', format: 'h3'},- {start: '####', format: 'h4'},- {start: '#####', format: 'h5'},- {start: '######', format: 'h6'},- {start: '* ', cmd: 'InsertUnorderedList'},- {start: '- [ ] ', cmd: 'insertCheckList'},- {start: '- [x] ', cmd: 'insertCheckList', value: 'checked'},- {start: '- ', cmd: 'InsertUnorderedList'},- {start: '> ', format: 'blockquote'},+ { start: '*', end: '*', format: 'italic' },+ { start: '**', end: '**', format: 'bold' },+ { start: '`', end: '`', format: 'code' },+ { start: '#', format: 'h1' },+ { start: '##', format: 'h2' },+ { start: '###', format: 'h3' },+ { start: '####', format: 'h4' },+ { start: '#####', format: 'h5' },+ { start: '######', format: 'h6' },+ { start: '* ', cmd: 'InsertUnorderedList' },+ { start: '- [ ] ', cmd: 'insertCheckList' },+ { start: '- [x] ', cmd: 'insertCheckList', value: 'checked' },+ { start: '- ', cmd: 'InsertUnorderedList' },+ { start: '> ', format: 'blockquote' },{start: '1. ',cmd: 'InsertOrderedList',- value: {'list-style-type': 'decimal'}+ value: { 'list-style-type': 'decimal' }},{start: '1) ',cmd: 'InsertOrderedList',- value: {'list-style-type': 'decimal'}+ value: { 'list-style-type': 'decimal' }},{start: 'a. ',cmd: 'InsertOrderedList',- value: {'list-style-type': 'lower-alpha'}+ value: { 'list-style-type': 'lower-alpha' }},{start: 'a) ',cmd: 'InsertOrderedList',- value: {'list-style-type': 'lower-alpha'}+ value: { 'list-style-type': 'lower-alpha' }},{start: 'i. ',cmd: 'InsertOrderedList',- value: {'list-style-type': 'lower-roman'}+ value: { 'list-style-type': 'lower-roman' }},{start: 'i) ',cmd: 'InsertOrderedList',- value: {'list-style-type': 'lower-roman'}+ value: { 'list-style-type': 'lower-roman' }},- {start: '---', replacement: '<hr/>'},- {start: '--', replacement: '—'},- {start: '(c)', replacement: '©'}+ { start: '---', replacement: '<hr/>' },+ { start: '--', replacement: '—' },+ { start: '(c)', replacement: '©' }];function dark() {@@ -79,18 +79,10 @@ function dark() {}if (!globalThis.tinymce) return;if (!tinymce.activeEditor) return;- tinymce.activeEditor.dom.styleSheetLoader.unload(- 'dist/skins/notesnook/content.min.css'- );- tinymce.activeEditor.dom.styleSheetLoader.load(- 'dist/skins/notesnook-dark/content.min.css'- );- tinymce.activeEditor.ui.styleSheetLoader.unload(- 'dist/skins/notesnook/skin.min.css'- );- tinymce.activeEditor.ui.styleSheetLoader.load(- 'dist/skins/notesnook-dark/skin.min.css'- );+ tinymce.activeEditor.dom.styleSheetLoader.unload('dist/skins/notesnook/content.min.css');+ tinymce.activeEditor.dom.styleSheetLoader.load('dist/skins/notesnook-dark/content.min.css');+ tinymce.activeEditor.ui.styleSheetLoader.unload('dist/skins/notesnook/skin.min.css');+ tinymce.activeEditor.ui.styleSheetLoader.load('dist/skins/notesnook-dark/skin.min.css');}function light() {@@ -100,18 +92,10 @@ function light() {}if (!globalThis.tinymce) return;if (!tinymce.activeEditor) return;- tinymce.activeEditor.dom.styleSheetLoader.unload(- 'dist/skins/notesnook-dark/content.min.css'- );- tinymce.activeEditor.dom.styleSheetLoader.load(- 'dist/skins/notesnook/content.min.css'- );- tinymce.activeEditor.ui.styleSheetLoader.unload(- 'dist/skins/notesnook-dark/skin.min.css'- );- tinymce.activeEditor.ui.styleSheetLoader.load(- 'dist/skins/notesnook/skin.min.css'- );+ tinymce.activeEditor.dom.styleSheetLoader.unload('dist/skins/notesnook-dark/content.min.css');+ tinymce.activeEditor.dom.styleSheetLoader.load('dist/skins/notesnook/content.min.css');+ tinymce.activeEditor.ui.styleSheetLoader.unload('dist/skins/notesnook-dark/skin.min.css');+ tinymce.activeEditor.ui.styleSheetLoader.load('dist/skins/notesnook/skin.min.css');}const codeblock_theme_light = `@@ -1000,19 +984,23 @@ table[data-mce-selected]border-right: 1px solid ${pageTheme.colors.accent + 'B3'} !important;}--table[data-mce-selected] td[data-mce-active],table[data-mce-selected] th[data-mce-active] {border: 2px solid ${pageTheme.colors.accent + 'B3'} !important;background-color: ${pageTheme.colors.shade};}+ code[data-mce-selected="inline-boundary"]:not(pre code),+.hljs[data-mce-selected="inline-boundary"] {+ background-color: ${pageTheme.colors.nav} !important;+}++code:not(pre code),.hljs {background-color: ${pageTheme.colors.nav} !important;border: 1px solid ${pageTheme.colors.border} !important;- border-radius: 5px;- padding: 3px 5px 0px 5px;+ border-radius: 5px !important;+ padding: 3px 5px 0px 5px !important;font-family: ui-monospace, SFMono-Regular, SF Mono, Consolas, Liberation Mono,Menlo, monospace !important;font-size: 10pt !important;diff --git a/apps/mobile/html/Web.bundle/site/plaineditor.html b/apps/mobile/html/Web.bundle/site/plaineditor.htmlindex 68a061c6a..7adf6afc5 100644--- a/apps/mobile/html/Web.bundle/site/plaineditor.html+++ b/apps/mobile/html/Web.bundle/site/plaineditor.html@@ -153,23 +153,6 @@mask-size: 15px 15px;mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='24' width='24'%3E%3Cpath d='M7.5,18A5.5,5.5 0 0,1 2,12.5A5.5,5.5 0 0,1 7.5,7H18A4,4 0 0,1 22,11A4,4 0 0,1 18,15H9.5A2.5,2.5 0 0,1 7,12.5A2.5,2.5 0 0,1 9.5,10H17V11.5H9.5A1,1 0 0,0 8.5,12.5A1,1 0 0,0 9.5,13.5H18A2.5,2.5 0 0,0 20.5,11A2.5,2.5 0 0,0 18,8.5H7.5A4,4 0 0,0 3.5,12.5A4,4 0 0,0 7.5,16.5H17V18H7.5Z'%3E%3C/path%3E%3C/svg%3E");}-- .mce-content-body code[data-mce-selected="inline-boundary"] {- background-color: #f0f0f0 !important;- }-- .mce-content-body code {- background-color: #f0f0f0 !important;- border: 1px solid var(--border);- border-radius: 5px;- padding: 3px 5px 0px 5px;- }-- code {- font-family: ui-monospace, SFMono-Regular, SF Mono, Consolas, Liberation Mono,- Menlo, monospace !important;- font-size: 10pt !important- }</style></head>@@ -179,7 +162,7 @@</div><script src="./constants.js"></script><script src="./listeners.js"></script>-+<script>function reactNativeEventHandler(type, value) {if (window.ReactNativeWebView) {diff --git a/apps/mobile/share/index.js b/apps/mobile/share/index.jsindex 0feebcd6e..b85522897 100644--- a/apps/mobile/share/index.js+++ b/apps/mobile/share/index.js@@ -1,7 +1,7 @@import Clipboard from '@react-native-clipboard/clipboard';-import absolutify from 'absolutify';+import { getLinkPreview } from 'link-preview-js';+import { HTMLRootElement } from 'node-html-parser/dist/nodes/html';import React, { useEffect, useRef, useState } from 'react';-import { ScrollView } from 'react-native';import {ActivityIndicator,Alert,@@ -9,6 +9,7 @@ import {KeyboardAvoidingView,Platform,SafeAreaView,+ ScrollView,StatusBar,Text,TouchableOpacity,@@ -20,6 +21,7 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';import Icon from 'react-native-vector-icons/MaterialCommunityIcons';import WebView from 'react-native-webview';import ShareExtension from 'rn-extensions-share';+import isURL from 'validator/lib/isURL';import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../src/services/EventManager';import { getElevation } from '../src/utils';import { db } from '../src/utils/database';@@ -27,8 +29,6 @@ import Storage from '../src/utils/storage';import { sleep } from '../src/utils/TimeUtils';import { Search } from './search';import { useShareStore } from './store';-import isURL from 'validator/lib/isURL';-import { getLinkPreview } from 'link-preview-js';const AnimatedKAV = Animated.createAnimatedComponent(KeyboardAvoidingView);const AnimatedSAV = Animated.createAnimatedComponent(SafeAreaView);@@ -36,11 +36,7 @@ async function sanitizeHtml(site) {try {let html = await fetch(site);html = await html.text();- let siteHtml = html.replace(- /(?:<(script|button|input|textarea|style|link|head)(?:\s[^>]*)?>)\s*((?:(?!<\1)[\s\S])*)\s*(?:<\/\1>)/g,- ''- );- return absolutify(siteHtml, site);+ return sanitize(html, site);} catch (e) {return '';}@@ -63,14 +59,65 @@ function getBaseUrl(site) {var url = site.split('/').slice(0, 3).join('/');return url;}-function absolutifyImgs(html, site) {- let { parse } = require('node-html-parser');- let parser = parse(html);- let images = parser.querySelectorAll('img');+/**+ *+ * @param {HTMLRootElement} document+ */+function wrapTablesWithDiv(document) {+ const tables = document.getElementsByTagName('table');+ for (let table of tables) {+ table.setAttribute('contenteditable', 'true');+ const div = document.createElement('div');+ div.setAttribute('contenteditable', 'false');+ div.innerHTML = table.outerHTML;+ div.classList.add('table-container');+ table.replaceWith(div);+ }+ return document;+}++let elementBlacklist = [+ 'script',+ 'button',+ 'input',+ 'textarea',+ 'style',+ 'form',+ 'link',+ 'head',+ 'nav',+ 'iframe',+ 'canvas',+ 'select',+ 'dialog',+ 'footer'+];++/**+ *+ * @param {HTMLRootElement} document+ */+function removeInvalidElements(document) {+ let elements = document.querySelectorAll(elementBlacklist.join(','));+ for (let element of elements) {+ element.remove();+ }+ return document;+}++/**+ *+ * @param {HTMLRootElement} document+ */+function replaceSrcWithAbsoluteUrls(document, baseUrl) {+ console.log('parsing:', document);++ let images = document.querySelectorAll('img');+ console.log(images.length);for (var i = 0; i < images.length; i++) {let img = images[i];- let url = getBaseUrl(site);+ let url = getBaseUrl(baseUrl);let src = img.getAttribute('src');if (src.startsWith('/')) {if (src.startsWith('//')) {@@ -80,10 +127,36 @@ function absolutifyImgs(html, site) {}}if (src.startsWith('data:')) {- src = '';+ img.remove();+ } else {+ img.setAttribute('src', src);}- img.setAttribute('src', src);}+ console.log('end');+ return document;+}++/**+ *+ * @param {HTMLRootElement} document+ */+function fixCodeBlocks(document) {+ let elements = document.querySelectorAll('code,pre');+ console.log(elements.length);+ for (let element of elements) {+ element.classList.add('.hljs');+ }+ return document;+}++function sanitize(html, baseUrl) {+ let { parse } = require('node-html-parser');+ let parser = parse(html);+ parser = wrapTablesWithDiv(parser);+ parser = removeInvalidElements(parser);+ parser = replaceSrcWithAbsoluteUrls(parser, baseUrl);+ parser = fixCodeBlocks(parser);+return parser.outerHTML;}@@ -246,19 +319,25 @@ const NotesnookShare = ({ quicknote = false }) => {const onLoad = () => {postMessage(webviewRef, 'htmldiff', note.content?.data || '');+ console.log('on load');setTimeout(() => {- webviewRef.current?.injectJavaScript(`document- .querySelector('.htmldiff_div')- .setAttribute('contenteditable', 'true');`);+ let theme = { ...colors };+ theme.factor = 1;+webviewRef.current?.injectJavaScript(`- pageTheme.colors = ${theme};- setTheme();- `);- }, 300);- let theme = { ...colors };- theme.factor = 1;+ document.querySelector('.htmldiff_div').setAttribute('contenteditable', 'true');`);- postMessage(webviewRef, 'theme', JSON.stringify(theme));+ webviewRef.current?.injectJavaScript(`(function() {+ try {+ pageTheme.colors = ${JSON.stringify(theme)};+ setTheme();+ } catch(e) {+ console.log(e);+ }+ })();++ `);+ }, 300);};function postMessage(webview, type, value = null) {@@ -353,7 +432,6 @@ const NotesnookShare = ({ quicknote = false }) => {try {if (m === 2) {let html = await sanitizeHtml(rawData.value);- html = await absolutifyImgs(html, rawData.value);setNote(note => {note.content.data = html;return { ...note };