mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-20 01:53:47 +00:00
Parse labels from environment options (#24189)
GitOrigin-RevId: e51eed7521f6e32e614f8b38092a0b0219f7f186
This commit is contained in:
parent
f11ad91249
commit
fe4f41501f
3 changed files with 12 additions and 4 deletions
|
@ -23,14 +23,19 @@ async function extractMetaFromDoc(lines) {
|
|||
}
|
||||
|
||||
const labelRe = /\\label{(.{0,80}?)}/g
|
||||
const labelOptionRe = /\blabel={?(.{0,80}?)[\s},\]]/g
|
||||
const packageRe = /^\\usepackage(?:\[.{0,80}?])?{(.{0,80}?)}/g
|
||||
const reqPackageRe = /^\\RequirePackage(?:\[.{0,80}?])?{(.{0,80}?)}/g
|
||||
|
||||
for (const rawLine of lines) {
|
||||
const line = getNonCommentedContent(rawLine)
|
||||
|
||||
for (const pkg of lineMatches(labelRe, line)) {
|
||||
docMeta.labels.push(pkg)
|
||||
for (const label of lineMatches(labelRe, line)) {
|
||||
docMeta.labels.push(label)
|
||||
}
|
||||
|
||||
for (const label of lineMatches(labelOptionRe, line)) {
|
||||
docMeta.labels.push(label)
|
||||
}
|
||||
|
||||
for (const pkg of lineMatches(packageRe, line, ',')) {
|
||||
|
|
|
@ -2,6 +2,7 @@ import { EditorView } from '@codemirror/view'
|
|||
import { Transaction, Text } from '@codemirror/state'
|
||||
|
||||
const metadataChangeRe = /\\(documentclass|usepackage|RequirePackage|label)\b/
|
||||
const optionChangeRe = /\b(label)=/
|
||||
|
||||
export const metadata = () => [
|
||||
// trigger metadata reload if edited line contains metadata-related commands
|
||||
|
@ -26,7 +27,7 @@ export const metadata = () => [
|
|||
const toLine = doc.lineAt(to).number
|
||||
|
||||
for (const line of doc.iterLines(fromLine, toLine + 1)) {
|
||||
if (metadataChangeRe.test(line)) {
|
||||
if (metadataChangeRe.test(line) || optionChangeRe.test(line)) {
|
||||
needsMetadataUpdate = true
|
||||
return
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ describe('MetaHandler', function () {
|
|||
'\\label{ccc}%bar', // ccc should be in the returned labels
|
||||
'\\label{ddd} % bar', // ddd should be in the returned labels
|
||||
'\\label{ e,f,g }', // e,f,g should be in the returned labels
|
||||
'\\begin{lstlisting}[label=foo, caption={Test}]', // foo should be in the returned labels
|
||||
'\\begin{lstlisting}[label={lst:foo},caption={Test}]', // lst:foo should be in the returned labels
|
||||
]
|
||||
|
||||
this.docs = {
|
||||
|
@ -85,7 +87,7 @@ describe('MetaHandler', function () {
|
|||
)
|
||||
|
||||
expect(result).to.deep.equal({
|
||||
labels: ['aaa', 'ccc', 'ddd', 'e,f,g'],
|
||||
labels: ['aaa', 'ccc', 'ddd', 'e,f,g', 'foo', 'lst:foo'],
|
||||
packages: {
|
||||
foo: this.packageMapping.foo,
|
||||
baz: this.packageMapping.baz,
|
||||
|
|
Loading…
Add table
Reference in a new issue