diff --git a/ghost/core/core/server/api/endpoints/utils/serializers/output/utils/post-gating.js b/ghost/core/core/server/api/endpoints/utils/serializers/output/utils/post-gating.js index 571af1a4e1..07655f311a 100644 --- a/ghost/core/core/server/api/endpoints/utils/serializers/output/utils/post-gating.js +++ b/ghost/core/core/server/api/endpoints/utils/serializers/output/utils/post-gating.js @@ -1,5 +1,5 @@ const membersService = require('../../../../../../services/members'); -const htmlToPlaintext = require('../../../../../../../shared/html-to-plaintext'); +const htmlToPlaintext = require('@tryghost/html-to-plaintext'); // @TODO: reconsider the location of this - it's part of members and adds a property to the API const forPost = (attrs, frame) => { diff --git a/ghost/core/core/server/data/migrations/versions/4.0/23-regenerate-posts-html.js b/ghost/core/core/server/data/migrations/versions/4.0/23-regenerate-posts-html.js index 1854c21683..a3d4761146 100644 --- a/ghost/core/core/server/data/migrations/versions/4.0/23-regenerate-posts-html.js +++ b/ghost/core/core/server/data/migrations/versions/4.0/23-regenerate-posts-html.js @@ -1,7 +1,7 @@ const logging = require('@tryghost/logging'); const {createIrreversibleMigration} = require('../../utils'); const mobiledocLib = require('../../../../lib/mobiledoc'); -const htmlToPlaintext = require('../../../../../shared/html-to-plaintext'); +const htmlToPlaintext = require('@tryghost/html-to-plaintext'); module.exports = createIrreversibleMigration(async (knex) => { logging.info('Starting re-generation of posts html.'); diff --git a/ghost/core/core/server/data/migrations/versions/4.9/05-fix-missed-mobiledoc-url-transforms.js b/ghost/core/core/server/data/migrations/versions/4.9/05-fix-missed-mobiledoc-url-transforms.js index 10e0bfda9a..3b606a35b8 100644 --- a/ghost/core/core/server/data/migrations/versions/4.9/05-fix-missed-mobiledoc-url-transforms.js +++ b/ghost/core/core/server/data/migrations/versions/4.9/05-fix-missed-mobiledoc-url-transforms.js @@ -1,6 +1,6 @@ const logging = require('@tryghost/logging'); const urlUtils = require('../../../../../shared/url-utils'); -const htmlToPlaintext = require('../../../../../shared/html-to-plaintext'); +const htmlToPlaintext = require('@tryghost/html-to-plaintext'); const mobiledocLib = require('../../../../lib/mobiledoc'); const {createTransactionalMigration} = require('../../utils'); diff --git a/ghost/core/core/server/data/migrations/versions/5.0/2022-05-21-00-00-regenerate-posts-html.js b/ghost/core/core/server/data/migrations/versions/5.0/2022-05-21-00-00-regenerate-posts-html.js index e6d0255c5a..bd713a8c73 100644 --- a/ghost/core/core/server/data/migrations/versions/5.0/2022-05-21-00-00-regenerate-posts-html.js +++ b/ghost/core/core/server/data/migrations/versions/5.0/2022-05-21-00-00-regenerate-posts-html.js @@ -1,7 +1,7 @@ const logging = require('@tryghost/logging'); const {createIrreversibleMigration} = require('../../utils'); const mobiledocLib = require('../../../../lib/mobiledoc'); -const htmlToPlaintext = require('../../../../../shared/html-to-plaintext'); +const htmlToPlaintext = require('@tryghost/html-to-plaintext'); module.exports = createIrreversibleMigration(async (knex) => { logging.info(`Starting regeneration of posts HTML`); diff --git a/ghost/core/core/server/models/post.js b/ghost/core/core/server/models/post.js index 2dfbcabe2d..d737878111 100644 --- a/ghost/core/core/server/models/post.js +++ b/ghost/core/core/server/models/post.js @@ -7,7 +7,7 @@ const {sequence} = require('@tryghost/promise'); const tpl = require('@tryghost/tpl'); const errors = require('@tryghost/errors'); const nql = require('@tryghost/nql'); -const htmlToPlaintext = require('../../shared/html-to-plaintext'); +const htmlToPlaintext = require('@tryghost/html-to-plaintext'); const ghostBookshelf = require('./base'); const config = require('../../shared/config'); const settingsCache = require('../../shared/settings-cache'); diff --git a/ghost/core/core/server/services/comments/emails.js b/ghost/core/core/server/services/comments/emails.js index 5520de78b8..98decd507e 100644 --- a/ghost/core/core/server/services/comments/emails.js +++ b/ghost/core/core/server/services/comments/emails.js @@ -1,7 +1,7 @@ const {promises: fs} = require('fs'); const path = require('path'); const moment = require('moment'); -const htmlToPlaintext = require('../../../shared/html-to-plaintext'); +const htmlToPlaintext = require('@tryghost/html-to-plaintext'); class CommentsServiceEmails { constructor({config, logging, models, mailer, settingsCache, urlService, urlUtils}) { diff --git a/ghost/core/core/server/services/mega/post-email-serializer.js b/ghost/core/core/server/services/mega/post-email-serializer.js index 7b3f096ba8..3d8d8f33d4 100644 --- a/ghost/core/core/server/services/mega/post-email-serializer.js +++ b/ghost/core/core/server/services/mega/post-email-serializer.js @@ -8,7 +8,7 @@ const api = require('../../api').endpoints; const apiShared = require('../../api').shared; const {URL} = require('url'); const mobiledocLib = require('../../lib/mobiledoc'); -const htmlToPlaintext = require('../../../shared/html-to-plaintext'); +const htmlToPlaintext = require('@tryghost/html-to-plaintext'); const membersService = require('../members'); const {isUnsplashImage, isLocalContentImage} = require('@tryghost/kg-default-cards/lib/utils'); const {textColorForBackgroundColor, darkenToContrastThreshold} = require('@tryghost/color-utils'); diff --git a/ghost/core/package.json b/ghost/core/package.json index 35678ac089..61b5e53f77 100644 --- a/ghost/core/package.json +++ b/ghost/core/package.json @@ -73,6 +73,7 @@ "@tryghost/errors": "1.2.14", "@tryghost/express-dynamic-redirects": "0.0.0", "@tryghost/helpers": "1.1.71", + "@tryghost/html-to-plaintext": "0.0.0", "@tryghost/image-transform": "1.2.1", "@tryghost/job-manager": "0.0.0", "@tryghost/kg-card-factory": "3.1.3", @@ -145,7 +146,6 @@ "glob": "8.0.3", "got": "9.6.0", "gscan": "4.34.0", - "html-to-text": "8.2.0", "human-number": "2.0.0", "image-size": "1.0.2", "intl": "1.2.5", diff --git a/ghost/html-to-plaintext/.eslintrc.js b/ghost/html-to-plaintext/.eslintrc.js new file mode 100644 index 0000000000..c9c1bcb522 --- /dev/null +++ b/ghost/html-to-plaintext/.eslintrc.js @@ -0,0 +1,6 @@ +module.exports = { + plugins: ['ghost'], + extends: [ + 'plugin:ghost/node' + ] +}; diff --git a/ghost/html-to-plaintext/README.md b/ghost/html-to-plaintext/README.md new file mode 100644 index 0000000000..c86d9cc932 --- /dev/null +++ b/ghost/html-to-plaintext/README.md @@ -0,0 +1,21 @@ +# Html To Plaintext + + +## Usage + + +## Develop + +This is a monorepo package. + +Follow the instructions for the top-level repo. +1. `git clone` this repo & `cd` into it as usual +2. Run `yarn` to install top-level dependencies. + + + +## Test + +- `yarn lint` run just eslint +- `yarn test` run lint and tests + diff --git a/ghost/html-to-plaintext/index.js b/ghost/html-to-plaintext/index.js new file mode 100644 index 0000000000..bb4a0723fc --- /dev/null +++ b/ghost/html-to-plaintext/index.js @@ -0,0 +1 @@ +module.exports = require('./lib/html-to-plaintext'); diff --git a/ghost/core/core/shared/html-to-plaintext.js b/ghost/html-to-plaintext/lib/html-to-plaintext.js similarity index 100% rename from ghost/core/core/shared/html-to-plaintext.js rename to ghost/html-to-plaintext/lib/html-to-plaintext.js diff --git a/ghost/html-to-plaintext/package.json b/ghost/html-to-plaintext/package.json new file mode 100644 index 0000000000..f4aee57617 --- /dev/null +++ b/ghost/html-to-plaintext/package.json @@ -0,0 +1,23 @@ +{ + "name": "@tryghost/html-to-plaintext", + "version": "0.0.0", + "repository": "https://github.com/TryGhost/Ghost/tree/main/packages/html-to-plaintext", + "author": "Ghost Foundation", + "private": true, + "main": "index.js", + "scripts": { + "dev": "echo \"Implement me!\"", + "test": "NODE_ENV=testing c8 --all --check-coverage --reporter text --reporter cobertura mocha './test/**/*.test.js'", + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" + }, + "devDependencies": { + "c8": "7.12.0", + "mocha": "10.0.0" + }, + "dependencies": { + "html-to-text": "8.2.1", + "lodash": "4.17.21" + } +} diff --git a/ghost/html-to-plaintext/test/.eslintrc.js b/ghost/html-to-plaintext/test/.eslintrc.js new file mode 100644 index 0000000000..829b601eb0 --- /dev/null +++ b/ghost/html-to-plaintext/test/.eslintrc.js @@ -0,0 +1,6 @@ +module.exports = { + plugins: ['ghost'], + extends: [ + 'plugin:ghost/test' + ] +}; diff --git a/ghost/core/test/unit/shared/html-to-plaintext.test.js b/ghost/html-to-plaintext/test/html-to-plaintext.test.js similarity index 88% rename from ghost/core/test/unit/shared/html-to-plaintext.test.js rename to ghost/html-to-plaintext/test/html-to-plaintext.test.js index 60b4c33c54..59ae4b4156 100644 --- a/ghost/core/test/unit/shared/html-to-plaintext.test.js +++ b/ghost/html-to-plaintext/test/html-to-plaintext.test.js @@ -1,5 +1,5 @@ const assert = require('assert'); -const htmlToPlaintext = require('../../../core/shared/html-to-plaintext'); +const htmlToPlaintext = require('../'); describe('Html to Plaintext', function () { function getEmailandExcert(input) { @@ -74,7 +74,7 @@ describe('Html to Plaintext', function () { describe('Special cases', function () { it('Instagram (blockquotes)', function () { // This is an instagram embed, but with all the style attributes & svg content removed for brevity - const html = '
Some text in a paragraph.
'; + const html = 'View this post on InstagramSome text in a paragraph.