mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Refactor to texOrPdfString function
GitOrigin-RevId: b084966a4fc13de4708973685844b2d9d2405e9b
This commit is contained in:
parent
2a2bb3f064
commit
77ad90d59a
2 changed files with 23 additions and 12 deletions
|
@ -191,3 +191,21 @@ export const enterNode = (
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const texOrPdfArgument = { tex: 0, pdf: 1 }
|
||||||
|
|
||||||
|
export const texOrPdfString = (
|
||||||
|
state: EditorState,
|
||||||
|
node: SyntaxNode,
|
||||||
|
version: keyof typeof texOrPdfArgument
|
||||||
|
) => {
|
||||||
|
const commandName = getCommandName(node.node, state, ['CtrlSeq'])
|
||||||
|
if (commandName === '\\texorpdfstring') {
|
||||||
|
const argumentNode = node
|
||||||
|
.getChildren('TextArgument')
|
||||||
|
[texOrPdfArgument[version]]?.getChild('LongArg')
|
||||||
|
if (argumentNode) {
|
||||||
|
return state.doc.sliceString(argumentNode.from, argumentNode.to)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { NodeIntersectsChangeFn, ProjectionItem } from './projection'
|
||||||
import * as tokens from '../../lezer-latex/latex.terms.mjs'
|
import * as tokens from '../../lezer-latex/latex.terms.mjs'
|
||||||
import { getEnvironmentArguments, getEnvironmentName } from './environments'
|
import { getEnvironmentArguments, getEnvironmentName } from './environments'
|
||||||
import { PartialFlatOutline } from '@/features/ide-react/context/outline-context'
|
import { PartialFlatOutline } from '@/features/ide-react/context/outline-context'
|
||||||
|
import { texOrPdfString } from './commands'
|
||||||
|
|
||||||
export type Outline = {
|
export type Outline = {
|
||||||
line: number
|
line: number
|
||||||
|
@ -89,18 +90,10 @@ const getEntryText = (state: EditorState, node: SyntaxNodeRef): string => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle the texorpdfstring command
|
// Handle the texorpdfstring command
|
||||||
if (
|
if (token.type.is('UnknownCommand')) {
|
||||||
token.type.name === 'Command' &&
|
const pdfString = texOrPdfString(state, token.node, 'pdf')
|
||||||
token.node.firstChild?.firstChild != null
|
if (pdfString) {
|
||||||
) {
|
titleParts.push(pdfString)
|
||||||
let command = token.node.firstChild.firstChild
|
|
||||||
let commandName = state.doc.sliceString(command.from + 1, command.to)
|
|
||||||
let textArguments = token.node.firstChild.getChildren('TextArgument')
|
|
||||||
if (commandName == 'texorpdfstring' && textArguments.length >= 2) {
|
|
||||||
let pdfstring = textArguments[1]
|
|
||||||
titleParts.push(
|
|
||||||
state.doc.sliceString(pdfstring.from + 1, pdfstring.to - 1)
|
|
||||||
)
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue