Skip to content

Commit

Permalink
Merge pull request #337 from marp-team/twemoji-api
Browse files Browse the repository at this point in the history
Use `@twemoji/api` package instead of `twemoji`
  • Loading branch information
yhatt authored Mar 26, 2023
2 parents 7ad2abd + e4c11f7 commit 38fb336
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Changed

- Upgrade Node.js and dependent packages ([#336](https://github.com/marp-team/marp-core/pull/336))
- Use `@twemoji/api` package instead of `twemoji` ([#337](https://github.com/marp-team/marp-core/pull/337))

## v3.5.0 - 2023-02-18

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"@rollup/plugin-terser": "^0.4.0",
"@rollup/plugin-typescript": "^11.0.0",
"@tsconfig/node12": "^1.0.11",
"@twemoji/api": "^14.1.2",
"@types/jest": "^29.5.0",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "^5.56.0",
Expand Down Expand Up @@ -112,7 +113,6 @@
"stylelint-config-standard-scss": "^7.0.1",
"ts-jest": "29.0.5",
"tslib": "^2.5.0",
"twemoji": "^14.0.2",
"typescript": "^5.0.2"
},
"dependencies": {
Expand Down
13 changes: 3 additions & 10 deletions src/emoji/emoji.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import marpitPlugin from '@marp-team/marpit/plugin'
import twemoji from '@twemoji/api'
import emojiRegex from 'emoji-regex'
import markdownItEmoji from 'markdown-it-emoji'
import twemoji from 'twemoji'
import { version as twemojiVersion } from 'twemoji/package.json'
import twemojiCSS from './twemoji.scss'

export interface EmojiOptions {
Expand All @@ -29,15 +28,9 @@ export const markdown = marpitPlugin((md) => {
const twemojiExt = twemojiOpts.ext || 'svg'

const twemojiParse = (content: string): string =>
twemoji.parse(content, {
// Casting to any is a workaround until merging the PR https://github.com/jdecked/twemoji/pull/1
(twemoji as any).parse(content, {
attributes: () => ({ 'data-marp-twemoji': '' }),
// Twemoji's default CDN (MaxCDN) shuts down at December 31, 2022.
// Unfortunately, continuous updates of Twemoji (including the update of
// base path) can not be expected due to Elon's acquisition for now. So
// Marp uses the CDN of jsDelivr unless the user specifies the base path.
base: Object.hasOwnProperty.call(twemojiOpts, 'base')
? twemojiOpts.base
: `https://cdn.jsdelivr.net/gh/twitter/twemoji@${twemojiVersion}/assets/`,
ext: `.${twemojiExt}`,
size: twemojiExt === 'svg' ? 'svg' : undefined,
})
Expand Down
10 changes: 6 additions & 4 deletions test/marp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,23 @@ describe('Marp', () => {

it('uses SVG via jsDelivr CDN by default', () => {
expect(emojiSrc(':ok_hand:')).toMatchInlineSnapshot(
`"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/svg/1f44c.svg"`
`"https://cdn.jsdelivr.net/gh/jdecked/twemoji@14.1.2/assets/svg/1f44c.svg"`
)
})

describe('base option', () => {
it('uses specified base', () =>
expect(
emojiSrc(':+1:', instance({ base: '/assets/twemoji/' }))
).toMatchInlineSnapshot(`"/assets/twemoji/svg/1f44d.svg"`))
).toMatchInlineSnapshot(
`"https://cdn.jsdelivr.net/gh/jdecked/twemoji@14.1.2/assets/svg/1f44d.svg"`
))

it("uses Twemoji's default CDN if the base option was undefined", () =>
expect(
emojiSrc(':+1:', instance({ base: undefined }))
).toMatchInlineSnapshot(
`"https://twemoji.maxcdn.com/v/14.0.2/svg/1f44d.svg"`
`"https://cdn.jsdelivr.net/gh/jdecked/twemoji@14.1.2/assets/svg/1f44d.svg"`
))
})

Expand All @@ -192,7 +194,7 @@ describe('Marp', () => {
expect(
emojiSrc(':+1:', instance({ ext: 'png' }))
).toMatchInlineSnapshot(
`"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f44d.png"`
`"https://cdn.jsdelivr.net/gh/jdecked/twemoji@14.1.2/assets/72x72/1f44d.png"`
))
})
})
Expand Down
20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,16 @@
resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.11.tgz#ee3def1f27d9ed66dac6e46a295cffb0152e058d"
integrity sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==

"@twemoji/api@^14.1.2":
version "14.1.2"
resolved "https://registry.yarnpkg.com/@twemoji/api/-/api-14.1.2.tgz#9e75a59cc2ff64c6c9106902823c9b6bc5bb4a9f"
integrity sha512-JLuszRq7t+NWJTaNwBD+Hbhf67gzn6jAqhNIDTPndEGT55kHiZTJAYRGCHZB/eA58OGVSp7mIvsJs+F/ZDJanA==
dependencies:
fs-extra "^8.0.1"
jsonfile "^5.0.0"
twemoji-parser "14.0.0"
universalify "^0.1.2"

"@types/babel__core@^7.1.14":
version "7.20.0"
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.20.0.tgz#61bc5a4cae505ce98e1e36c5445e4bee060d8891"
Expand Down Expand Up @@ -5817,16 +5827,6 @@ twemoji-parser@14.0.0:
resolved "https://registry.yarnpkg.com/twemoji-parser/-/twemoji-parser-14.0.0.tgz#13dabcb6d3a261d9efbf58a1666b182033bf2b62"
integrity sha512-9DUOTGLOWs0pFWnh1p6NF+C3CkQ96PWmEFwhOVmT3WbecRC+68AIqpsnJXygfkFcp4aXbOp8Dwbhh/HQgvoRxA==

twemoji@^14.0.2:
version "14.0.2"
resolved "https://registry.yarnpkg.com/twemoji/-/twemoji-14.0.2.tgz#c53adb01dab22bf4870f648ca8cc347ce99ee37e"
integrity sha512-BzOoXIe1QVdmsUmZ54xbEH+8AgtOKUiG53zO5vVP2iUu6h5u9lN15NcuS6te4OY96qx0H7JK9vjjl9WQbkTRuA==
dependencies:
fs-extra "^8.0.1"
jsonfile "^5.0.0"
twemoji-parser "14.0.0"
universalify "^0.1.2"

type-check@^0.4.0, type-check@~0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1"
Expand Down

0 comments on commit 38fb336

Please sign in to comment.