mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #3863 from overleaf/hb-clear-content-outside-heading-def
Remove content outside of the title commands for outline GitOrigin-RevId: 4361521b5e1ae8adc853ed4fb250cbeeaebb1d71
This commit is contained in:
parent
afc15335c7
commit
7a36373a0f
2 changed files with 25 additions and 2 deletions
|
@ -50,6 +50,7 @@ function matchOutline(content) {
|
|||
}
|
||||
|
||||
const DISPLAY_TITLE_REGEX = new RegExp('([^\\\\]*)\\\\([^{]+){([^}]+)}(.*)')
|
||||
const END_OF_TITLE_REGEX = new RegExp('^([^{}]*?({[^{}]*?}[^{}]*?)*)}')
|
||||
/*
|
||||
* Attempt to improve the display of the outline title for titles with commands.
|
||||
* Either skip the command (for labels) or display the command's content instead
|
||||
|
@ -61,11 +62,19 @@ const DISPLAY_TITLE_REGEX = new RegExp('([^\\\\]*)\\\\([^{]+){([^}]+)}(.*)')
|
|||
*/
|
||||
function matchDisplayTitle(title) {
|
||||
const closingBracketPosition = title.indexOf('}')
|
||||
|
||||
if (closingBracketPosition < 0) {
|
||||
// simple title (no commands)
|
||||
return title
|
||||
}
|
||||
|
||||
// if there is anything outside the title def on the line, remove it
|
||||
// before proceeding
|
||||
const titleOnlyMatch = title.match(END_OF_TITLE_REGEX)
|
||||
if (titleOnlyMatch) {
|
||||
title = titleOnlyMatch[1]
|
||||
}
|
||||
|
||||
const titleMatch = title.match(DISPLAY_TITLE_REGEX)
|
||||
if (!titleMatch) {
|
||||
// no contained commands; strip everything after the first closing bracket
|
||||
|
|
|
@ -47,13 +47,27 @@ describe('OutlineParser', function() {
|
|||
\\section{Label after \\label{foo}}
|
||||
\\section{Label \\label{foo} between}
|
||||
\\section{TT \\texttt{Bar}}
|
||||
`
|
||||
\\section{plain title}
|
||||
`
|
||||
const outline = matchOutline(content)
|
||||
expect(outline).to.deep.equal([
|
||||
{ line: 2, title: ' Label before', level: 40 },
|
||||
{ line: 3, title: 'Label after ', level: 40 },
|
||||
{ line: 4, title: 'Label between', level: 40 },
|
||||
{ line: 5, title: 'TT Bar', level: 40 }
|
||||
{ line: 5, title: 'TT Bar', level: 40 },
|
||||
{ line: 6, title: 'plain title', level: 40 }
|
||||
])
|
||||
})
|
||||
|
||||
it('removes spurious commands after title definition', function() {
|
||||
const content = `
|
||||
\\section{Plain title} more text \\href{link}{link}
|
||||
\\section{\\label{foo} Label before} more text \\href{link}{link}
|
||||
`
|
||||
const outline = matchOutline(content)
|
||||
expect(outline).to.deep.equal([
|
||||
{ line: 2, title: 'Plain title', level: 40 },
|
||||
{ line: 3, title: ' Label before', level: 40 }
|
||||
])
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue