diff --git a/package.json b/package.json index 75b8001d..c5cc29e7 100644 --- a/package.json +++ b/package.json @@ -3,18 +3,24 @@ "@joplin/turndown-plugin-gfm": "^1.0.43", "@popclip/helpers": "file:lib/@popclip/helpers", "@popclip/test": "file:lib/@popclip/test", + "@popclip/types": "^1.4586.0", "@tryfabric/martian": "^1.2.4", "@types/crypto-js": "^4.1.1", "@types/voca": "^1.4.1", + "axios": "1.6.8", "browserify": "^17.0.0", "case-anything": "^2.1.10", "core-js": "^3.22.7", "crypto-js": "^4.1.1", "evernote": "^2.0.5", "html-entities": "^2.3.3", + "linkedom": "0.18.0", "mathjs": "^10.0.0", + "rot13-cipher": "1.0.0", + "sanitize-html": "2.13.0", "slackify-markdown": "^4.3.1", "superagent": "^6.1.0", + "turndown": "7.1.3", "turndown-plugin-gfm": "^1.0.2", "typescript": "5.4.5", "voca": "^1.4.0", diff --git a/source/Evernote.popclipext/Config.json b/source/Evernote.popclipext/Config.json index 70496a9e..88f54705 100644 --- a/source/Evernote.popclipext/Config.json +++ b/source/Evernote.popclipext/Config.json @@ -1,17 +1,14 @@ { - "popclip version": 3895, + "popclip version": 4586, "identifier": "com.pilotmoon.popclip.extension.evernote", "name": "Evernote", "icon": "evernote-logo.svg", "capture html": true, "module": "main.bundle.js.lzfse", - "entitlements": [ - "network" - ], + "entitlements": ["network"], "app": { "name": "Evernote", "link": "https://evernote.com/" }, - "description": "Send the selected text to Evernote.", - "note": "Updated 15 Sep 2022 with fix." -} \ No newline at end of file + "description": "Send the selected text to Evernote." +} diff --git a/source/Evernote.popclipext/Readme.md b/source/Evernote.popclipext/Readme.md index d665a1da..625ff316 100644 --- a/source/Evernote.popclipext/Readme.md +++ b/source/Evernote.popclipext/Readme.md @@ -20,23 +20,13 @@ Icon from [svgrepo](https://www.svgrepo.com/svg/24585/evernote) (CC0). ### Requirements -* PopClip 2022.5 -* An Evernote account +- PopClip 2024.5 or later +- An Evernote account ## Changelog -### 15 Sep 2022 - -* Fix bug with build, extension not working. - -### 5 May 2022 - -* Rewritten to send the to the Evernote servers directly using the Evernote API. - -### 30 Jun 2014 - -* Updated to support HTML content. - -### 8 Nov 2012 - -* Initial release using AppleScript. +- 14 May 2024: Fix for PopClip 2024.5. +- 15 Sep 2022: Fix bug with build, extension not working. +- 5 May 2022: Rewritten to send the to the Evernote servers directly using the Evernote API. +- 30 Jun 2014: Updated to support HTML content. +- 8 Nov 2012: Initial release using AppleScript. diff --git a/source/Evernote.popclipext/build b/source/Evernote.popclipext/build index 2e37a846..88b7d8cc 100755 --- a/source/Evernote.popclipext/build +++ b/source/Evernote.popclipext/build @@ -2,5 +2,5 @@ npx tsc module=main npx browserify --external sanitize-html --external htmlparser2 --external dom-serializer --standalone foo $module.js > $module.bundle.js -lzfse -encode -i $module.bundle.js > $module.bundle.js.lzfse -rm $module.bundle.js \ No newline at end of file +lzfse -encode -i $module.bundle.js > $module.bundle.js.lzfse +rm *.js diff --git a/source/Evernote.popclipext/enml.js b/source/Evernote.popclipext/enml.js deleted file mode 100644 index 57d2fe46..00000000 --- a/source/Evernote.popclipext/enml.js +++ /dev/null @@ -1,36 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.renderEnml = exports.renderXhtml = exports.cleanHtml = void 0; -// Utility for rendering HTML as ENML (Evernote Markup Language), -// Evernote's rather fussy markup language for notes. It's XHTML (not HTML) -// with a couple of extra tags and a restriction on which tags can attributes can be used. -// The allowed list of tags and attributes is given in enml.json. -// https://dev.evernote.com/doc/articles/enml.php -const sanitizeHtml = require("sanitize-html"); -const htmlparser2_1 = require("htmlparser2"); -const dom_serializer_1 = require("dom-serializer"); -const enml_json_1 = require("./enml.json"); -// clean HTML by removing disallowed tags and attributes -const cleanHtml = (dirty) => { - return sanitizeHtml(dirty, { - allowedTags: enml_json_1.allowedTags, - allowedAttributes: enml_json_1.allowedAttributes, - exclusiveFilter: function (frame) { - return frame.tag === 'a' && frame.text.trim().length === 0; // also remove empty links (usually anchors) - } - }); -}; -exports.cleanHtml = cleanHtml; -// render given HTML string as XHTML -const renderXhtml = (html) => { - const document = (0, htmlparser2_1.parseDocument)(html); - return (0, dom_serializer_1.default)(document, { xmlMode: true }); -}; -exports.renderXhtml = renderXhtml; -// render given HTML string as ENML -const renderEnml = (html) => { - const prefix = '\n\n'; - const suffix = ''; - return prefix + (0, exports.renderXhtml)((0, exports.cleanHtml)(html)) + suffix; -}; -exports.renderEnml = renderEnml; diff --git a/source/Evernote.popclipext/enml.ts b/source/Evernote.popclipext/enml.ts index 5d0d3825..3d3cf2ba 100644 --- a/source/Evernote.popclipext/enml.ts +++ b/source/Evernote.popclipext/enml.ts @@ -3,29 +3,30 @@ // with a couple of extra tags and a restriction on which tags can attributes can be used. // The allowed list of tags and attributes is given in enml.json. // https://dev.evernote.com/doc/articles/enml.php -import * as sanitizeHtml from 'sanitize-html' -import { parseDocument } from 'htmlparser2' -import render from 'dom-serializer' -import { allowedTags, allowedAttributes } from './enml.json' +import sanitizeHtml from "sanitize-html"; +import { parseDocument } from "htmlparser2"; +import render from "dom-serializer"; +import { allowedTags, allowedAttributes } from "./enml.json"; // clean HTML by removing disallowed tags and attributes export const cleanHtml = (dirty: string): string => { - return sanitizeHtml(dirty, { - allowedTags: allowedTags, - allowedAttributes: allowedAttributes, - exclusiveFilter: function (frame) { - return frame.tag === 'a' && frame.text.trim().length === 0 // also remove empty links (usually anchors) - } - }) -} + return sanitizeHtml(dirty, { + allowedTags: allowedTags, + allowedAttributes: allowedAttributes, + exclusiveFilter: function (frame) { + return frame.tag === "a" && frame.text.trim().length === 0; // also remove empty links (usually anchors) + }, + }); +}; // render given HTML string as XHTML export const renderXhtml = (html: string): string => { - const document = parseDocument(html) - return render(document, { xmlMode: true }) -} + const document = parseDocument(html); + return render(document, { xmlMode: true }); +}; // render given HTML string as ENML export const renderEnml = (html: string): string => { - const prefix = '\n\n' - const suffix = '' - return prefix + renderXhtml(cleanHtml(html)) + suffix -} + const prefix = + '\n\n'; + const suffix = ""; + return prefix + renderXhtml(cleanHtml(html)) + suffix; +}; diff --git a/source/Evernote.popclipext/main.bundle.js.lzfse b/source/Evernote.popclipext/main.bundle.js.lzfse index 33f086a9..5547361e 100644 Binary files a/source/Evernote.popclipext/main.bundle.js.lzfse and b/source/Evernote.popclipext/main.bundle.js.lzfse differ diff --git a/source/Evernote.popclipext/main.js b/source/Evernote.popclipext/main.js deleted file mode 100644 index 3de19656..00000000 --- a/source/Evernote.popclipext/main.js +++ /dev/null @@ -1,65 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -/* -Where does the the `evernote.js` come from? -It is the npm module `evernote`, that has been packed using browserify. -I installed the npm module using `npm install evernote` then wrapped it up -using `./bin/getmodules evernote` (tool in this repo). --Nick -*/ -/* eslint-disable @typescript-eslint/naming-convention */ -/* eslint-disable @typescript-eslint/no-var-requires */ -const enml_1 = require("./enml"); -const consumer_json_1 = require("./consumer.json"); -const evernote_1 = require("evernote"); -const { consumerKey, consumerSecret } = util.clarify(consumer_json_1.consumer); -// this keeps oauth module happy -const g = globalThis; -g.location = { protocol: 'https:' }; -// sign in to evernote using its delightfully byzantine oauth system -const auth = async (info, flow) => await new Promise(function (resolve, reject) { - const client = new evernote_1.Client({ - consumerKey, - consumerSecret, - sandbox: false - }); - client.getRequestToken(info.redirect, async function (_, requestToken, requestTokenSecret) { - if (typeof requestToken === 'string' && requestToken.length > 0 && typeof requestTokenSecret === 'string' && requestTokenSecret.length > 0) { - const { oauth_verifier } = await flow(client.getAuthorizeUrl(requestToken)); - client.getAccessToken(requestToken, requestTokenSecret, oauth_verifier, function (_, accessToken) { - if (typeof accessToken === 'string' && accessToken.length > 0) { - resolve(accessToken); - } - else { - reject(new Error('bad accessToken')); - } - }); - } - else { - reject(new Error('bad requestToken or requestTokenSecret')); - } - }); -}); -const action = async (input, options, context) => { - const content = (0, enml_1.renderEnml)(input.html); - const title = context.browserTitle.length > 0 ? context.browserTitle : 'New Note'; - const attributes = { sourceApplication: 'PopClip' }; - if (context.browserUrl.length > 0) { - attributes.sourceURL = context.browserUrl; - } - const note = { title, content, attributes }; - try { - const authenticatedClient = new evernote_1.Client({ - token: options.authsecret, - sandbox: false - }); - const noteStore = authenticatedClient.getNoteStore(); - const status = await noteStore.createNote(note); - print('status', status); - } - catch (e) { - throw new Error('Evernote API error: ' + JSON.stringify(e)); - } - popclip.showSuccess(); -}; -exports.default = { action, auth }; diff --git a/tsconfig.json b/tsconfig.json index eb89631b..f231a44f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,33 +1,23 @@ { - "compilerOptions": { - "strict": true, - "noImplicitAny": false, - // note es2018 requires macOS 10.14 - // once we drop support for high sierra this can be bumped for cleaner js code - // (note es2018 is required for async generators) - "target": "es2017", - "lib": [ - "es2021" - ], - // we can specify esnext lib due to polyfills in popclip - "module": "commonjs", - "esModuleInterop": false, - "moduleResolution": "node", - "resolveJsonModule": true, - "baseUrl": "./lib", - }, - "include": [ - "./popclip.d.ts", - "./lib", - "./extras", - "./source", - "./source-contrib", - "./scratch" - ], - "exclude": ["/Applications/PopClip.app/Contents/Resources/popclip.d.ts"], - "ts-standard": { - "ignore": [ - "**/*.js" - ] - } -} \ No newline at end of file + "compilerOptions": { + "strict": true, + "noImplicitAny": false, + "target": "es2018", + "lib": ["es2023"], + "skipLibCheck": true, + "module": "commonjs", + "esModuleInterop": true, + "moduleResolution": "node", + "resolveJsonModule": true, + "baseUrl": "./lib" + }, + "include": [ + "./node_modules/@popclip/types/popclip.d.ts", + "./node_modules/@popclip/types/extra/shims.d.ts", + "./lib", + "./extras", + "./source", + "./source-contrib" + ], + "exclude": ["/Applications/PopClip.app/Contents/Resources/popclip.d.ts"] +}