0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-06-22 07:08:40 +00:00

fix work on first load for images inside other nodes

This commit is contained in:
Víctor Losada Hernández
2026-05-10 19:35:09 +02:00
parent e521db78ce
commit 793adafe32
2 changed files with 12 additions and 5 deletions
+12 -4
View File
@@ -17,7 +17,17 @@ import {
crosshairCursor,
} from '@codemirror/view';
import { EditorState, Compartment, StateEffect, StateField } from '@codemirror/state';
import { foldAll as foldAllCmd, unfoldAll as unfoldAllCmd, foldGutter, foldKeymap, foldEffect, foldState, syntaxHighlighting } from '@codemirror/language';
import {
foldAll as foldAllCmd,
unfoldAll as unfoldAllCmd,
foldGutter,
foldKeymap,
foldEffect,
foldState,
syntaxHighlighting,
syntaxTree,
ensureSyntaxTree
} from '@codemirror/language';
import { defaultKeymap, history, undo, redo, undoDepth, redoDepth } from '@codemirror/commands';
import { languages } from '@codemirror/language-data';
import { css } from '@codemirror/lang-css';
@@ -41,7 +51,6 @@ import { generalKeymap, markdownKeymap } from './extensions/customKeyMaps.js';
import foldOnPages from './extensions/customFolding.js';
import { customHighlightStyle, tokenizeCustomMarkdown, tokenizeCustomCSS } from './extensions/customHighlight.js';
import { legacyCustomHighlightStyle, legacyTokenizeCustomMarkdown } from './extensions/legacyCustomHighlight.js';
import { syntaxTree } from '@codemirror/language';
const PAGEBREAK_REGEX_V3 = /^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m;
@@ -90,7 +99,7 @@ const createHighlightPlugin = (renderer, tab)=>{
let pageCount = 1;
let snippetCount = 0;
const tree = syntaxTree(view.state);
const tree = ensureSyntaxTree(view.state, view.state.doc.length, 50) || syntaxTree(view.state);
tree.iterate({
enter : (node)=>{
if(node.name === 'Image') {
@@ -120,7 +129,6 @@ const createHighlightPlugin = (renderer, tab)=>{
const to = line.from + tok.to;
const attrs = {};
console.log(tok);
// attach URL only for links
if(tok.type === 'Image' && tok.url) {
@@ -204,7 +204,6 @@ export function tokenizeCustomMarkdown(text) {
let match;
while ((match = injectionRegex.exec(lineText)) !== null) {
console.log(match.indices[1][0]);
tokens.push({
line : lineNumber,
from : match.indices[1][0],