mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-29 22:54:21 -05:00
Fix size of highlighting if frontmatter is invalid (#2264)
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
7d53493f56
commit
c50037fc9f
2 changed files with 13 additions and 12 deletions
|
@ -45,8 +45,8 @@ describe('FrontmatterLinter', () => {
|
|||
testFrontmatterLinter(
|
||||
'---\ntags: a\n---',
|
||||
{
|
||||
from: 4,
|
||||
to: 11,
|
||||
from: 5,
|
||||
to: 12,
|
||||
severity: 'warning'
|
||||
},
|
||||
'tags:\n- a'
|
||||
|
@ -56,8 +56,8 @@ describe('FrontmatterLinter', () => {
|
|||
testFrontmatterLinter(
|
||||
'---\ntags: 1\n---',
|
||||
{
|
||||
from: 4,
|
||||
to: 11,
|
||||
from: 5,
|
||||
to: 12,
|
||||
severity: 'warning'
|
||||
},
|
||||
'tags:\n- 1'
|
||||
|
@ -67,8 +67,8 @@ describe('FrontmatterLinter', () => {
|
|||
testFrontmatterLinter(
|
||||
'---\ntags: 123, a\n---',
|
||||
{
|
||||
from: 4,
|
||||
to: 16,
|
||||
from: 5,
|
||||
to: 17,
|
||||
severity: 'warning'
|
||||
},
|
||||
'tags:\n- 123\n- a'
|
||||
|
@ -77,8 +77,8 @@ describe('FrontmatterLinter', () => {
|
|||
})
|
||||
it('with invalid yaml', () => {
|
||||
testFrontmatterLinter('---\n1\n 2: 3\n---', {
|
||||
from: 0,
|
||||
to: 16,
|
||||
from: 4,
|
||||
to: 12,
|
||||
severity: 'error'
|
||||
})
|
||||
})
|
||||
|
|
|
@ -23,13 +23,14 @@ export class FrontmatterLinter implements Linter {
|
|||
if (!frontmatterExtraction.isPresent) {
|
||||
return []
|
||||
}
|
||||
const frontmatterLines = lines.slice(0, frontmatterExtraction.lineOffset + 1)
|
||||
const startOfYaml = lines[0].length + 1
|
||||
const frontmatterLines = lines.slice(1, frontmatterExtraction.lineOffset - 1)
|
||||
const rawNoteFrontmatter = FrontmatterLinter.loadYaml(frontmatterExtraction.rawText)
|
||||
if (rawNoteFrontmatter === undefined) {
|
||||
return [
|
||||
{
|
||||
from: 0,
|
||||
to: frontmatterLines.join('\n').length,
|
||||
from: startOfYaml,
|
||||
to: startOfYaml + frontmatterLines.join('\n').length,
|
||||
message: t('editor.linter.frontmatter'),
|
||||
severity: 'error'
|
||||
}
|
||||
|
@ -46,7 +47,7 @@ export class FrontmatterLinter implements Linter {
|
|||
const replacedText = 'tags:\n- ' + tags.join('\n- ')
|
||||
const tagsLineIndex = frontmatterLines.findIndex((value) => value.startsWith('tags: '))
|
||||
const linesBeforeTagsLine = frontmatterLines.slice(0, tagsLineIndex)
|
||||
const from = linesBeforeTagsLine.join('\n').length + 1
|
||||
const from = startOfYaml + linesBeforeTagsLine.join('\n').length + 1
|
||||
const to = from + frontmatterLines[tagsLineIndex].length
|
||||
return [
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue