Skip to content

Commit

Permalink
Merge pull request #558 from marp-team/lang-directive
Browse files Browse the repository at this point in the history
Reflect `lang` global directive to HTML templates
  • Loading branch information
yhatt committed Oct 28, 2023
2 parents d0520cc + 19df529 commit 34a57fb
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
### Changed

- Upgrade Marpit to [v2.6.1](https://github.com/marp-team/marpit/releases/tag/v2.6.1) ([#557](https://github.com/marp-team/marp-cli/pull/557))
- Added `lang` global directive
- Upgrade Marp Core to [v3.9.0](https://github.com/marp-team/marp-core/releases/v3.9.0) ([#557](https://github.com/marp-team/marp-cli/pull/557))
- Enabled [CSS container query](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_container_queries) support for child elements of `section` element by default
- Upgrade dependent packages to the latest versions ([#557](https://github.com/marp-team/marp-cli/pull/557))
- Reflect the language defined in `lang` global directive to `<html>` element ([#542](https://github.com/marp-team/marp-cli/issues/542), [#558](https://github.com/marp-team/marp-cli/pull/558))

### Fixed

Expand Down
7 changes: 3 additions & 4 deletions src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class Converter {
fallbackToPrintableTemplate = false,
}: { fallbackToPrintableTemplate?: boolean } = {}
): Promise<TemplateResult> {
const { lang, globalDirectives, type } = this.options
const { globalDirectives, type } = this.options

const isFile = (f: File | undefined): f is File =>
!!f && f.type === FileType.File
Expand All @@ -159,7 +159,6 @@ export class Converter {

return await template({
...(this.options.templateOption || {}),
lang,
base: await resolveBase(file),
notifyWS:
isFile(file) && this.options.watch && type === ConvertType.html
Expand Down Expand Up @@ -489,8 +488,8 @@ export class Converter {
private async generateEngine(
mergeOptions: MarpitOptions
): Promise<Marpit & { [engineInfo]?: EngineInfo }> {
const { html, options } = this.options
const opts = { ...options, ...mergeOptions, html }
const { html, lang, options } = this.options
const opts = { lang, ...options, ...mergeOptions, html }

let engine = this.options.engine

Expand Down
2 changes: 2 additions & 0 deletions src/engine/info-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export interface EngineInfo {
description: string | undefined
image: string | undefined
keywords: string[] | undefined
lang: string | undefined
length: number
size: { height: number; width: number }
theme: string | undefined
Expand All @@ -28,6 +29,7 @@ export default function infoPlugin(md: any) {
description: globalDirectives.marpCLIDescription,
image: globalDirectives.marpCLIImage,
keywords: globalDirectives.marpCLIKeywords,
lang: globalDirectives.lang || marpit.options.lang,
title: globalDirectives.marpCLITitle,
url: globalDirectives.marpCLIURL,
size: {
Expand Down
2 changes: 1 addition & 1 deletion src/templates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ interface TemplateRendererOptions extends Options {

interface TemplateCoreOption {
base?: string
lang: string
notifyWS?: string
renderer: (
tplOpts: TemplateRendererOptions
Expand All @@ -36,6 +35,7 @@ export interface TemplateMeta {
keywords: string[] | undefined
title: string | undefined
url: string | undefined
lang: string | undefined
}

interface RenderedSize {
Expand Down
5 changes: 5 additions & 0 deletions test/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ describe('Converter', () => {
expect(result).toContain('<html lang="zh">')
})

it('prefers lang specified in Markdown than lang option', async () => {
const { result } = await instance().convert('<!-- lang: fr -->')
expect(result).toContain('<html lang="fr">')
})

it("overrides html option by converter's html option", async () => {
const defaultHtml = (await instance().convert('<i><br></i>')).rendered
expect(defaultHtml.html).toContain('&lt;i&gt;<br />&lt;/i&gt;')
Expand Down

0 comments on commit 34a57fb

Please sign in to comment.