Skip to content

Commit

Permalink
zmarkdown escape latex titles
Browse files Browse the repository at this point in the history
  • Loading branch information
artragis authored and vhf committed Jun 25, 2018
1 parent 54d9279 commit 201c249
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
20 changes: 20 additions & 0 deletions packages/zmarkdown/__tests__/__snapshots__/server.tests.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,23 @@ exports[`Texfile endpoint accepts POSTed markdown 1`] = `
\\\\end{document}"
`;
exports[`Texfile endpoint escapes title and author 1`] = `
"\\\\documentclass[contentType]{zmdocument}
\\\\usepackage{blindtext}
\\\\title{recap \\\\#1}
\\\\author{titi\\\\_alone}
\\\\licence[/tmp/l/by-nc-sa.svg]{CC-BY-NC-SA}{https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode}
\\\\smileysPath{/tmp/s}
\\\\makeglossaries
\\\\begin{document}
\\\\maketitle
\\\\tableofcontents
\\\\levelOneTitle{foo}
\\\\end{document}"
`;
12 changes: 11 additions & 1 deletion packages/zmarkdown/__tests__/server.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const clone = require('clone')
const dedent = require('dedent')
const a = require('axios')
const fs = require('fs')

const xtend = require('xtend')
const u = (path) => `http://localhost:27272${path}`
const epub = u('/epub')
const html = u('/html')
Expand Down Expand Up @@ -203,6 +203,16 @@ describe('Texfile endpoint', () => {
expect(metadata).toEqual({})
})

it('escapes title and author', async () => {
const titleOpts = {authors: ['titi_alone'], title: 'recap #1'}
const response = await a.post(texfile,
{md: '# foo', opts: xtend(texfileOpts, titleOpts)})
expect(response.status).toBe(200)

const result = response.data
expect(result[0]).toMatchSnapshot()
})

it('does not return metadata', async () => {
const response = await a.post(texfile, {md: '# foo', opts: texfileOpts})

Expand Down
5 changes: 3 additions & 2 deletions packages/zmarkdown/templates/latex-document.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const assert = require('assert')
const escape = require('rebber/dist/escaper')

const template = (opts, callback) => {
const {
Expand Down Expand Up @@ -30,8 +31,8 @@ const template = (opts, callback) => {
return callback(null, `\\documentclass[${contentType}]{zmdocument}
\\usepackage{blindtext}
\\title{${title}}
\\author{${authors.join(', ')}}
\\title{${escape(title)}}
\\author{${escape(authors.join(', '))}}
${licenseLine}
\\smileysPath{${smileysDirectory}}
Expand Down

0 comments on commit 201c249

Please sign in to comment.