Steps to Reproduce
- Create a new plugin from the template or just use any existing plugin and copy the following code to
onload
function
this.registerMarkdownCodeBlockProcessor('test', (source, el, ctx) => {
console.log('start processing test...');
// present the diff directly in the editor
el.insertAdjacentHTML('afterbegin', '<div><p>TEST</p></div>');
});
- Load the plugin in Obsidian and create a new file with its content a title and a “test” code block
- Type a line with several chars in the code block, e.g. a to z as I used. Then copy and paste this line 1000 times (type
dd1000P
in vim mode). Now your markdown file looks like
# This is a test
```test
abcdefghijklmnopqrstuvwxyz
... (repeat 1000 times)
abcdefghijklmnopqrstuvwxyz
```
- Close and reopen that file in live preview mode.
Expected Result
After reopening the file, the cursor is located at the header line, the code block should be replaced by an HTML div block with the word “TEST”, and the console output should contain the string “start processing test…”.
Actual Result
Neither the code block changed nor the console output.
Live Preview
Meanwhile, if we just scroll the text to a position near the end of the code block, the expected result appears. However, the issue remains after we close and reopen the file.
Live Preview after Scrolling
Since we did not do anything other than scroll the text, it seems like the content of the code block was not fully loaded until we scrolled the text to the end of the block.
If we change to the reading view, we can directly get the expected result, even if we remain the live preview in a split window.
Live Preview and Reading View
Additional Information
Although I can scroll over 500 lines with the issue remaining, I will get the expected result if I only create a block with 500 lines.
Scroll over 500 lines in Live Preview
This issue affects lots of plugins that use the funtion registerMarkdownCodeBlockProcessor
. I have tested QAMichaelPeng/obsidian-graphviz and gregzuro/obsidian-kroki with the example Linux Kernel Diagram given by Graphviz, and artisticat1/obsidian-tikzjax with the example Poincare Diagram posted on Texample.
I also find that @Hajiku shares a very similar issue which deals with ‘PosterProcessor’.
P.S. Every time before I close and reopen the file, I clear the console in order not to count the number of the string occurrences.
Environment
SYSTEM INFO:
Obsidian version: v1.1.9
Installer version: v1.0.0
Operating system: Darwin Kernel Version 22.2.0: Fri Nov 11 02:03:51 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T6000 22.2.0
Login status: not logged in
Insider build toggle: off
Live preview: on
Legacy editor: off
Base theme: dark
Community theme: none
Snippets enabled: 1
Restricted mode: off
Plugins installed: 8
Plugins enabled: 1
1: Graphviz Plugin v0.0.1