Skip to content

Commit

Permalink
Prefer lang global directive than constructor option
Browse files Browse the repository at this point in the history
  • Loading branch information
yhatt committed Oct 14, 2023
1 parent 1a7c7ee commit e38d676
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/markdown/directives/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ function _apply(md, opts = {}) {
}

// Apply attribute to token
if (lang || marpitDirectives.lang)
token.attrSet('lang', lang || marpitDirectives.lang)
if (marpitDirectives.lang || lang)
token.attrSet('lang', marpitDirectives.lang || lang)

if (marpitDirectives.class)
token.attrJoin('class', marpitDirectives.class)
Expand Down
2 changes: 2 additions & 0 deletions src/marpit.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class Marpit {
* slide page at before of headings. it would apply to headings whose
* larger than or equal to the specified level if a number is given, or
* ONLY specified levels if a number array.
* @param {string} [opts.lang] Set the default `lang` attribute of each slide.
* It can override by `lang` global directive in the Markdown.
* @param {boolean} [opts.looseYAML=false] Allow loose YAML parsing in
* built-in directives, and custom directives defined in current instance.
* @param {MarkdownIt|string|Object|Array} [opts.markdown] An instance of
Expand Down
5 changes: 5 additions & 0 deletions test/markdown/directives/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ describe('Marpit directives apply plugin', () => {
expect(sections.eq(1).attr('lang')).toBe('en-US')
})

it('can override the language that is setting by `lang` constructor option', () => {
const $lang = load(md({ options: { lang: 'fr' } }).render(langDir))
expect($lang('section').first().attr('lang')).toBe('en-US')
})

context('when lang directive is not defined', () => {
it('follows the lang option of Marpit instance', () => {
const $ = load(md({}).render(''))
Expand Down

0 comments on commit e38d676

Please sign in to comment.