Skip to content

Commit

Permalink
Merge pull request #432 from marp-team/notes-follow-up
Browse files Browse the repository at this point in the history
Follow up for `--notes` option
  • Loading branch information
yhatt authored Feb 23, 2022
2 parents eb34446 + 8574573 commit 0b95928
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 48 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Added

- `--notes` option to export presenter notes as text file ([#278](https://github.com/marp-team/marp-cli/issues/278), [#429](https://github.com/marp-team/marp-cli/pull/429) by [@chrisns](https://github.com/chrisns))
- `--notes` option to export presenter notes as text file ([#278](https://github.com/marp-team/marp-cli/issues/278), [#429](https://github.com/marp-team/marp-cli/pull/429) by [@chrisns](https://github.com/chrisns), [#432](https://github.com/marp-team/marp-cli/pull/432))
- Make notes font size changeable in bespoke template ([#428](https://github.com/marp-team/marp-cli/pull/428) by [@chrisns](https://github.com/chrisns), [#431](https://github.com/marp-team/marp-cli/pull/431))
- Timer for the presenter view of bespoke template ([#314](https://github.com/marp-team/marp-cli/issues/314), [#430](https://github.com/marp-team/marp-cli/pull/430) by [@chrisns](https://github.com/chrisns))

Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,16 @@ marp slide-deck.md -o [email protected] --image-scale 2
>
> It is also available for PPTX conversion. By default, Marp CLI will use `2` as the default scale factor in PPTX to suppress deterioration of slide rendering in full-screen presentation.
### Export presenter notes (`--notes`)

You can export [presenter notes][marpit presenter notes] in Marp / Marpit Markdown as a text file by using `--notes` option or specifying the output path with TXT extension.

```bash
# Export presenter notes as a text
marp --notes slide-deck.md
marp slide-deck.md -o output.txt
```

### Security about local files

Because of [the security reason](https://github.com/marp-team/marp-cli/pull/10#user-content-security), **PDF, PPTX and image(s) conversion cannot use local files by default.**
Expand Down Expand Up @@ -491,7 +501,7 @@ If you want to prevent looking up a configuration file, you can pass `--no-confi
| `jpegQuality` | number | `--jpeg-quality` | Setting JPEG image quality (`85` by default) |
| `keywords` | string \| string[] | `--keywords` | Define keywords for the slide deck (Accepts comma-separated string and array of string) |
| `lang` | string | | Define the language of converted HTML |
| `notes` | boolean | `--notes` | Convert slide deck into just the text notes |
| `notes` | boolean | `--notes` | Convert slide deck notes into a text file |
| `ogImage` | string | `--og-image` | Define [Open Graph] image URL |
| `options` | object | | The base options for the constructor of engine |
| `output` | string | `--output` `-o` | Output file path (or directory when input-dir is passed) |
Expand Down
1 change: 1 addition & 0 deletions src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const mimeTypes = {
[ConvertType.pptx]:
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
[ConvertType.jpeg]: 'image/jpeg',
[ConvertType.notes]: 'text/plain',
}

export interface ConverterOption {
Expand Down
12 changes: 6 additions & 6 deletions src/marp-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,18 @@ export const marpCli = async (
group: OptionGroup.Converter,
type: 'boolean',
},
notes: {
conflicts: ['image', 'images', 'pptx', 'pdf'],
describe: 'Convert slide deck notes into TXT',
group: OptionGroup.Converter,
type: 'boolean',
},
pptx: {
conflicts: ['pdf', 'image', 'images', 'notes'],
describe: 'Convert slide deck into PowerPoint document',
group: OptionGroup.Converter,
type: 'boolean',
},
notes: {
conflicts: ['image', 'images', 'pptx', 'pdf'],
describe: 'Convert slide deck notes into a text file',
group: OptionGroup.Converter,
type: 'boolean',
},
image: {
conflicts: ['pdf', 'images', 'pptx', 'notes'],
describe: 'Convert the first slide page into an image file',
Expand Down
2 changes: 2 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export class Server extends (EventEmitter as new () => TypedEmitter<Server.Event
if (queryKeys.includes('png')) return ConvertType.png
if (queryKeys.includes('jpg') || queryKeys.includes('jpeg'))
return ConvertType.jpeg
if (queryKeys.includes('txt') || queryKeys.includes('notes'))
return ConvertType.notes

return ConvertType.html
})()
Expand Down
82 changes: 42 additions & 40 deletions test/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,46 +526,6 @@ transition:
expect(ret.newFile.type).toBe(FileType.StandardIO)
})

it('converts markdown file to text and save to specified path when output is defined', async () => {
const notesInstance = (opts: Partial<ConverterOption> = {}) =>
instance({ ...opts, type: ConvertType.notes })
const write = (<any>fs).__mockWriteFile()
const output = './specified.txt'
const ret = await (<any>notesInstance({ output })).convertFile(
new File(threePath),
{ type: 'notes' }
)
const notes: Buffer = write.mock.calls[0][1]

expect(write).toHaveBeenCalled()
expect(write.mock.calls[0][0]).toBe('./specified.txt')
expect(notes.toString()).toBe('presenter note')
expect(ret.newFile?.path).toBe('./specified.txt')
expect(ret.newFile?.buffer).toBe(notes)
})

it('converts markdown file to text and save to specified path when output is defined but no notes exist', async () => {
const warn = jest.spyOn(console, 'warn').mockImplementation()
const notesInstance = (opts: Partial<ConverterOption> = {}) =>
instance({ ...opts, type: ConvertType.notes })
const write = (<any>fs).__mockWriteFile()
const output = './specified.txt'
const ret = await (<any>notesInstance({ output })).convertFile(
new File(onePath),
{ type: 'notes' }
)
const notes: Buffer = write.mock.calls[0][1]

expect(warn).toHaveBeenCalledWith(
expect.stringContaining('contains no notes')
)
expect(write).toHaveBeenCalled()
expect(write.mock.calls[0][0]).toBe('./specified.txt')
expect(notes.toString()).toBe('')
expect(ret.newFile?.path).toBe('./specified.txt')
expect(ret.newFile?.buffer).toBe(notes)
})

describe('when convert type is PDF', () => {
const pdfInstance = (opts: Partial<ConverterOption> = {}) =>
instance({ ...opts, type: ConvertType.pdf })
Expand Down Expand Up @@ -984,6 +944,48 @@ transition:
puppeteerTimeoutMs
)
})

describe('when convert type is notes', () => {
it('converts markdown file to notes text and save to specified path when output is defined', async () => {
const notesInstance = (opts: Partial<ConverterOption> = {}) =>
instance({ ...opts, type: ConvertType.notes })

const write = (<any>fs).__mockWriteFile()
const output = './specified.txt'
const ret = await (<any>notesInstance({ output })).convertFile(
new File(threePath)
)
const notes: Buffer = write.mock.calls[0][1]

expect(write).toHaveBeenCalled()
expect(write.mock.calls[0][0]).toBe('./specified.txt')
expect(notes.toString()).toBe('presenter note')
expect(ret.newFile?.path).toBe('./specified.txt')
expect(ret.newFile?.buffer).toBe(notes)
})

it('converts markdown file to empty text and save to specified path when output is defined but no notes exist', async () => {
const warn = jest.spyOn(console, 'warn').mockImplementation()
const notesInstance = (opts: Partial<ConverterOption> = {}) =>
instance({ ...opts, type: ConvertType.notes })

const write = (<any>fs).__mockWriteFile()
const output = './specified.txt'
const ret = await (<any>notesInstance({ output })).convertFile(
new File(onePath)
)
const notes: Buffer = write.mock.calls[0][1]

expect(warn).toHaveBeenCalledWith(
expect.stringContaining('contains no notes')
)
expect(write).toHaveBeenCalled()
expect(write.mock.calls[0][0]).toBe('./specified.txt')
expect(notes.toString()).toBe('')
expect(ret.newFile?.path).toBe('./specified.txt')
expect(ret.newFile?.buffer).toBe(notes)
})
})
})

describe('#convertFiles', () => {
Expand Down
8 changes: 8 additions & 0 deletions test/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ describe('Server', () => {
const jpegRes = await request(server.server).get('/1.md?jpeg')
expect(server.converter.options.type).toBe(ConvertType.jpeg)
expect(jpegRes.type).toBe('image/jpeg')

const txtRes = await request(server.server).get('/1.md?txt')
expect(server.converter.options.type).toBe(ConvertType.notes)
expect(txtRes.type).toBe('text/plain')

const notesRes = await request(server.server).get('/1.md?notes')
expect(server.converter.options.type).toBe(ConvertType.notes)
expect(notesRes.type).toBe('text/plain')
})
})

Expand Down

0 comments on commit 0b95928

Please sign in to comment.