<commit_before>fs = require "fs"
logger = require "logger-sharelatex"

module.exports = DraftModeManager =
	injectDraftMode: (filename, callback = (error) ->) ->
		fs.readFile filename, "utf8", (error, content) ->
			return callback(error) if error?
			modified_content = DraftModeManager._injectDraftOption content
			logger.log {
				content: content.slice(0,1024), # \documentclass is normally v near the top
				modified_content: modified_content.slice(0,1024),
				filename
			}, "injected draft class"
			fs.writeFile filename, modified_content, callback
	
	_injectDraftOption: (content) ->
		content
			# With existing options (must be first, otherwise both are applied)
			.replace(/\\documentclass\[/, "\\documentclass[draft,")
			# Without existing options
			.replace(/\\documentclass\{/, "\\documentclass[draft]{")<commit_msg>Make draft mode regex global<commit_after>fs = require "fs"
logger = require "logger-sharelatex"

module.exports = DraftModeManager =
	injectDraftMode: (filename, callback = (error) ->) ->
		fs.readFile filename, "utf8", (error, content) ->
			return callback(error) if error?
			modified_content = DraftModeManager._injectDraftOption content
			logger.log {
				content: content.slice(0,1024), # \documentclass is normally v near the top
				modified_content: modified_content.slice(0,1024),
				filename
			}, "injected draft class"
			fs.writeFile filename, modified_content, callback
	
	_injectDraftOption: (content) ->
		content
			# With existing options (must be first, otherwise both are applied)
			.replace(/\\documentclass\[/g, "\\documentclass[draft,")
			# Without existing options
			.replace(/\\documentclass\{/g, "\\documentclass[draft]{")
{'fraction_non_alphanumeric': 0.12404016538688718, 'fraction_numerical': 0.01299468399291199, 'mean_word_length': 4.377777777777778, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3609200', 'n_tokens_mistral': 563, 'n_tokens_neox': 470, 'n_words': 131}