overleaf/services/web/app/coffee/Features/Documents/DocumentHelper.coffee
Paulo Jorge Reis af2d959504 Merge pull request #1072 from sharelatex/spd-open-with-overleaf
Implement v1 open-with-overleaf API in v2 (part 1)

GitOrigin-RevId: 488f4eeefc29086a72295ccbc7c63d2f927add12
2018-11-15 10:04:33 +00:00

13 lines
559 B
CoffeeScript

module.exports = DocumentHelper =
getTitleFromTexContent: (content, maxContentToScan = 30000) ->
TITLE_WITH_CURLY_BRACES = /\\[tT]itle\*?\s*{([^}]+)}/
TITLE_WITH_SQUARE_BRACES = /\\[tT]itle\s*\[([^\]]+)\]/
ESCAPED_BRACES = /\\([{}\[\]])/g
content = content.substring(0, maxContentToScan).split("\n") if typeof content is 'string'
title = null
for line in content
match = line.match(TITLE_WITH_SQUARE_BRACES) || line.match(TITLE_WITH_CURLY_BRACES)
if match?
title = match[1].replace(ESCAPED_BRACES, (br)->br[1])
break
return title