mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
af2d959504
Implement v1 open-with-overleaf API in v2 (part 1) GitOrigin-RevId: 488f4eeefc29086a72295ccbc7c63d2f927add12
13 lines
559 B
CoffeeScript
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
|