BookStack icon indicating copy to clipboard operation
BookStack copied to clipboard

[Feature Request]: Code block line wrap support

Open SmokingCrop opened this issue 3 years ago • 10 comments

Describe the feature you'd like

I would like to have the ability to make a 'block code' format but without horizontal scrollbars. Basically word wrapping that is used in many text editors.

The line-numbering should be empty on lines that are wrapped.

Describe the benefits this feature would bring to BookStack users

This makes the ease of use much higher for readers to view the entire code in one go without having to manually scroll horizontally to view every part of the code/text.

Additional context

Example of word-wrapping in another program: image

SmokingCrop avatar Feb 20 '22 15:02 SmokingCrop

I think this would be a really good addition if it is possible within the current framework

techauthoruk avatar Feb 22 '22 13:02 techauthoruk

+1 for this feature

bloomt avatar Aug 15 '22 14:08 bloomt

I need this too

hambern avatar Feb 02 '23 23:02 hambern

This script in the head makes it work:

<script>
  window.onload = function() {
    let codemirror = document.createElement('script');
	codemirror.src = 'https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.2/codemirror.min.js';
	document.head.appendChild(codemirror);
	
	codemirror.onload = function() {
		let codemirrors = document.querySelectorAll('.CodeMirror');
		codemirrors.forEach(function(codemirror) {
			codemirror.CodeMirror.setOption('lineWrapping', true);
			codemirror.CodeMirror.setOption('wordWrap', true);
		});
	};
  }
</script>

Don't thank me... Thank Open AI ;)

hambern avatar Feb 02 '23 23:02 hambern

This script in the head makes it work:

<script>
  window.onload = function() {
    let codemirror = document.createElement('script');
	codemirror.src = 'https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.2/codemirror.min.js';
	document.head.appendChild(codemirror);
	
	codemirror.onload = function() {
		let codemirrors = document.querySelectorAll('.CodeMirror');
		codemirrors.forEach(function(codemirror) {
			codemirror.CodeMirror.setOption('lineWrapping', true);
			codemirror.CodeMirror.setOption('wordWrap', true);
		});
	};
  }
</script>

Don't thank me... Thank Open AI ;)

This is not working anymore, it seems.

jenny787 avatar May 20 '23 06:05 jenny787

Seems like a good feature.

Some code is just so long and goes off-screen making it harder to read the code.

JavaDogWebDesign avatar Aug 09 '23 13:08 JavaDogWebDesign

Within #4639 I've exposed the newer CodeMirror (code block) instances to allow a route of customization/hacking. As of BookStack v23.10.1 (once released) it should be possible to enable line wrapping via adding this to your "Custom HTML Head Content" customizating setting:

<script>
window.addEventListener('library-cm6::pre-init', event => {
    const detail = event.detail;
    const config = detail.editorViewConfig;
    const EditorView = detail.libEditorView;
    
    if (detail.usage === 'content-code-block') {
        config.extensions.push(EditorView.lineWrapping);
    }
});
</script>

ssddanbrown avatar Nov 01 '23 18:11 ssddanbrown

Within #4639 I've exposed the newer CodeMirror (code block) instances to allow a route of customization/hacking. As of BookStack v23.10.1 (once released) it should be possible to enable line wrapping via adding this to your "Custom HTML Head Content" customizating setting:

<script>
window.addEventListener('library-cm6::pre-init', event => {
    const detail = event.detail;
    const config = detail.editorViewConfig;
    const EditorView = detail.libEditorView;
    
    if (detail.usage === 'content-code-block') {
        config.extensions.push(EditorView.lineWrapping);
    }
});
</script>

thank you, this works great! (tested with v23.12), highly appreciated!

ZAck1387 avatar Jan 04 '24 13:01 ZAck1387