mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #14245 from overleaf/mj-linebreak-arguments
[lezer+visual] Allow optional arguments for line breaks GitOrigin-RevId: e59a7c9a2efacc8a0fde887736899bbcbb52a4bc
This commit is contained in:
parent
0b91a2052a
commit
56438c32cc
4 changed files with 18 additions and 12 deletions
|
@ -66,8 +66,9 @@ function parseColumnSpecifications(specification: string): ColumnDefinition[] {
|
|||
return columns
|
||||
}
|
||||
|
||||
const isRowSeparator = (node: SyntaxNode, state: EditorState) =>
|
||||
node.type.is('Command') && state.sliceDoc(node.from, node.to) === '\\\\'
|
||||
const isRowSeparator = (node: SyntaxNode) =>
|
||||
node.type.is('Command') &&
|
||||
Boolean(node.getChild('KnownCtrlSym')?.getChild('LineBreak'))
|
||||
|
||||
const isHLine = (node: SyntaxNode) =>
|
||||
node.type.is('Command') &&
|
||||
|
@ -133,7 +134,7 @@ function parseTabularBody(
|
|||
currentChild;
|
||||
currentChild = currentChild.nextSibling
|
||||
) {
|
||||
if (isRowSeparator(currentChild, state)) {
|
||||
if (isRowSeparator(currentChild)) {
|
||||
const lastRow = getLastRow()
|
||||
body.rows.push({
|
||||
cells: [],
|
||||
|
|
|
@ -794,13 +794,17 @@ export const atomicDecorations = (options: Options) => {
|
|||
}).range(nodeRef.from, nodeRef.to)
|
||||
)
|
||||
}
|
||||
} else if (nodeRef.type.is('LineBreakCtrlSym')) {
|
||||
} else if (nodeRef.type.is('LineBreak')) {
|
||||
// line break
|
||||
decorations.push(
|
||||
Decoration.replace({
|
||||
widget: new IndicatorWidget('\u21A9'),
|
||||
}).range(nodeRef.from, nodeRef.to)
|
||||
)
|
||||
const optionalArgument = nodeRef.node.getChild('OptionalArgument')
|
||||
if (!optionalArgument || shouldDecorate(state, optionalArgument)) {
|
||||
decorations.push(
|
||||
Decoration.replace({
|
||||
widget: new IndicatorWidget('\u21A9'),
|
||||
}).range(nodeRef.from, nodeRef.to)
|
||||
)
|
||||
}
|
||||
return false
|
||||
} else if (nodeRef.type.is('Caption')) {
|
||||
if (shouldDecorate(state, nodeRef)) {
|
||||
// a caption
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { EditorState } from '@codemirror/state'
|
||||
import { SyntaxNode } from '@lezer/common'
|
||||
import { LineBreakCtrlSym } from '../../../lezer-latex/latex.terms.mjs'
|
||||
|
||||
const isUnknownCommandWithName = (
|
||||
node: SyntaxNode,
|
||||
|
@ -92,7 +91,7 @@ export function typesetNodeIntoElement(
|
|||
// ignoring these commands
|
||||
from = childNode.to
|
||||
return false
|
||||
} else if (childNode.type.is(LineBreakCtrlSym)) {
|
||||
} else if (childNode.type.is('LineBreak')) {
|
||||
ancestor().appendChild(document.createElement('br'))
|
||||
from = childNode.to
|
||||
}
|
||||
|
|
|
@ -360,7 +360,9 @@ Command {
|
|||
}
|
||||
|
||||
KnownCtrlSym {
|
||||
LineBreakCtrlSym
|
||||
LineBreak {
|
||||
LineBreakCtrlSym OptionalArgument?
|
||||
}
|
||||
}
|
||||
|
||||
textBase {
|
||||
|
|
Loading…
Reference in a new issue