Skip to content

Commit

Permalink
Merge pull request #77 from marp-team/warn-twemojibase-deprecation
Browse files Browse the repository at this point in the history
Output warning when used deprecated twemojiBase option
  • Loading branch information
yhatt authored Mar 13, 2019
2 parents 8687ef4 + 61ed593 commit fb46656
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Changed

- Upgrade Node and dependent packages to the latest ([#76](https://github.com/marp-team/marp-core/pull/76))
- Output warning when used deprecated `twemojiBase` option ([#77](https://github.com/marp-team/marp-core/pull/77))

## v0.6.2 - 2019-03-09

Expand Down
11 changes: 10 additions & 1 deletion src/emoji/emoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@ export function markdown(md, opts: EmojiOptions): void {
twemoji.parse(content, {
attributes: () => ({ 'data-marp-twemoji': '' }),
base:
twemojiOpts.base || opts.twemojiBase || 'https://twemoji.maxcdn.com/2/',
twemojiOpts.base ||
(() => {
if (opts.twemojiBase) {
console.warn(
'Deprecation warning: twemojiBase option has been deprecated and would remove in next version. Please use twemoji.base option instead.'
)
}
return opts.twemojiBase
})() ||
'https://twemoji.maxcdn.com/2/',
ext: `.${twemojiExt}`,
size: twemojiExt === 'svg' ? 'svg' : 72,
})
Expand Down
8 changes: 7 additions & 1 deletion test/marp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const marpitDisablePlugin = md =>
jest.mock('../src/browser')
jest.mock('../src/math/katex.scss')

afterEach(() => jest.restoreAllMocks())

describe('Marp', () => {
const marp = (opts?: MarpOptions): Marp => new Marp(opts)

Expand Down Expand Up @@ -158,15 +160,19 @@ describe('Marp', () => {
})
})

describe('twemojiBase option [soft-deprecated]', () => {
describe('twemojiBase option [deprecated]', () => {
const instance = (emoji: EmojiOptions = {}) => new Marp({ emoji })

it('uses specified base when twemojiBase option is defined', () => {
const warn = jest.spyOn(console, 'warn')
const marp = instance({ twemojiBase: '/assets/twemoji/' })
const $ = cheerio.load(marp.render('# :ok_hand:').html)
const src = $('h1 > img[data-marp-twemoji]').attr('src')

expect(src).toBe('/assets/twemoji/svg/1f44c.svg')
expect(warn).toBeCalledWith(
expect.stringContaining('Deprecation warning')
)
})
})

Expand Down

0 comments on commit fb46656

Please sign in to comment.