avoid adding draft mode more than once

This commit is contained in:
Brian Gough
2017-08-17 15:03:37 +01:00
parent 2b610030d5
commit 5b5f7b0690
2 changed files with 4 additions and 3 deletions

View File

@@ -5,6 +5,9 @@ module.exports = DraftModeManager =
injectDraftMode: (filename, callback = (error) ->) ->
fs.readFile filename, "utf8", (error, content) ->
return callback(error) if error?
# avoid adding draft mode more than once
if content?.indexOf("\\documentclass\[draft") >= 0
return callback()
modified_content = DraftModeManager._injectDraftOption content
logger.log {
content: content.slice(0,1024), # \documentclass is normally v near the top
@@ -18,4 +21,4 @@ module.exports = DraftModeManager =
# With existing options (must be first, otherwise both are applied)
.replace(/\\documentclass\[/g, "\\documentclass[draft,")
# Without existing options
.replace(/\\documentclass\{/g, "\\documentclass[draft]{")
.replace(/\\documentclass\{/g, "\\documentclass[draft]{")