Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicated content and indentation in hide-markdown-diff #4052

Merged
merged 11 commits into from
Mar 10, 2021
21 changes: 20 additions & 1 deletion source/features/hide-markdown-diff.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,30 @@

/* Remove decorations on added/changed content */
.rgh-hide-markdown-diff .markdown-body :is(ins, .added, .changed) {
color: inherit !important;
color: var(--color-text-primary) !important;
background: none !important;
box-shadow: none !important;
}

.rgh-hide-markdown-diff .markdown-body code {
color: var(--color-text-primary) !important;
background-color: var(--color-markdown-code-bg) !important;
border: none !important;
}

.rgh-hide-markdown-diff .markdown-body pre code {
background: none !important;
}

.rgh-hide-markdown-diff .markdown-body blockquote :is(ins, .added, .changed) {
color: var(--color-text-tertiary) !important;
}

/* Fix duplicated content issue in changed quote blocks #4035 */
.rgh-hide-markdown-diff .markdown-body .changed > .changed_tag[data-before-tag='blockquote'] ~ p:not([class]):not(:empty) {
display: none !important;
}

/* Only show the toggle when the preview tab is selected */
.rgh-preview-toggle {
display: none !important;
Expand Down
10 changes: 10 additions & 0 deletions source/features/hide-markdown-diff.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import './hide-markdown-diff.css';
import React from 'dom-chef';
import select from 'select-dom';
import delegate from 'delegate-it';
import elementReady from 'element-ready';
import * as pageDetect from 'github-url-detection';

import features from '.';

// Fix missing indentation in changed quote blocks #4035
function fixMissingIndentation(): void {
for (const changedBlockquote of select.all('.show-preview .changed > .changed_tag[data-before-tag="blockquote"]')) {
changedBlockquote.parentElement!.classList.add('ml-3');
}
Comment on lines +12 to +14
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the end I had to rely on some JS to fix the missing indentation issue.

At first I applied a margin on any siblings of .changed_tag[data-before-tag="blockquote"] but this causes issues with inline <ins> elements, so it has to be applied to the diff block wrapper.

}

function togglePreviewResult({delegateTarget: target}: delegate.Event<MouseEvent, HTMLButtonElement>): void {
document.body.classList.toggle('rgh-hide-markdown-diff', target.value === 'enable');
target.classList.add('selected');
Expand All @@ -20,6 +28,8 @@ async function init(): Promise<void> {
</div>
);
delegate(document, '.rgh-preview-button:not(.selected)', 'click', togglePreviewResult);
// Watch for when the content in the "Preview" tab has finished loading
new MutationObserver(fixMissingIndentation).observe((await elementReady('.js-code-editor'))!, {attributeFilter: ['class']});
}

void features.add(__filebasename, {
Expand Down