easy-markdown-editor icon indicating copy to clipboard operation
easy-markdown-editor copied to clipboard

Decouple preview (full) from editor

Open sn3p opened this issue 3 years ago • 2 comments

I'm trying to decouple the full preview from the CodeMirror editor, and add GitHub style write/preview tabs using this method.

Screenshot 2021-02-03 at 17 39 15

For this I need the preview to "autogrow" and render without having to scroll in its container (unless maxHeight options is set). The preview container is nested/appended within the CodeMirror container, and styled as an absolute positioned overlay on top of the editor. Which means the preview has the exact same dimensions as the parent (editor), and doesn't grow with its content.

Is there an option, trick or hack that will achieve this?

sn3p avatar Feb 03 '21 17:02 sn3p

I got it working by hiding CodeMirror-* and make the preview position relative, but am hoping for a less hacky solution:

.editor-toolbar.disabled-for-preview + .CodeMirror > :not(.editor-preview-full) {
  display: none;
}

.editor-preview-full {
  height: auto;
  overflow: visible;
  position: relative;
}

It would be easier if the preview wasn't nested inside the CodeMirror container, but I guess that's too much to ask 😆

But maybe we can introduce top-level classes to make everything easier to style? E.g. preview-full-active and preview-side-active instead of multiple classes all over the place.

So instead of:

.editor-toolbar.disabled-for-preview button:not(.no-disable) { ... }
.editor-preview-full.editor-preview-active { ... }
.editor-preview-side.editor-preview-active-side { ... }

Have something like this:

EasyMDEContainer.preview-full-active .editor-toolbar > *:not(.no-disable) { ... }
EasyMDEContainer.preview-full-active .editor-preview-full { ... }
EasyMDEContainer.preview-side-active .editor-preview-side { ... }

Think this is cleaner and easier to target elements.

sn3p avatar Feb 03 '21 17:02 sn3p

@sn3p I like your hack. I am trying to do just the same :) I am wondering if you ended up with a different solution or kept this one?

Thanks!

artknight avatar Jan 08 '22 00:01 artknight