mirror of
https://github.com/bwya77/collapsible-code-blocks.git
synced 2026-07-22 12:00:25 +00:00
1 line doesnt show the backticks and language
This commit is contained in:
parent
2ae0b54921
commit
07ec40ea40
2 changed files with 16 additions and 4 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "collapsible-code-blocks",
|
||||
"name": "Collapsible Code Blocks",
|
||||
"version": "1.0.4",
|
||||
"version": "1.0.5",
|
||||
"minAppVersion": "0.15.0",
|
||||
"description": "Makes code blocks collapsible in reader view and edit view as well as enabling scroll-able code blocks.",
|
||||
"author": "Bradley Wyatt",
|
||||
|
|
|
|||
|
|
@ -140,9 +140,21 @@ const createFoldField = (settings: CollapsibleCodeBlockSettings) => StateField.d
|
|||
|
||||
const contentDiv = document.createElement('div');
|
||||
contentDiv.className = 'folded-content';
|
||||
const lines = view.state.doc.sliceString(capturedFrom, capturedTo).split('\n')
|
||||
.slice(0, settings.collapsedLines)
|
||||
.join('\n');
|
||||
|
||||
// Get the entire content first
|
||||
const fullContent = view.state.doc.sliceString(capturedFrom, capturedTo);
|
||||
const allLines = fullContent.split('\n');
|
||||
|
||||
// Skip the first line (which contains ```language) and last line if it's closing backticks
|
||||
let codeLines = allLines.slice(1); // Skip first line with backticks
|
||||
|
||||
// Remove the last line if it's closing backticks
|
||||
if (codeLines.length > 0 && codeLines[codeLines.length - 1].trim().startsWith('```')) {
|
||||
codeLines = codeLines.slice(0, -1);
|
||||
}
|
||||
|
||||
// Get the requested number of lines
|
||||
const lines = codeLines.slice(0, settings.collapsedLines).join('\n');
|
||||
contentDiv.textContent = lines;
|
||||
|
||||
const button = document.createElement('div');
|
||||
|
|
|
|||
Loading…
Reference in a new issue