Fixed print rendering of nested code annotations

This commit is contained in:
squidfunk 2021-12-04 12:33:58 +01:00
parent 732565b3af
commit 67f7301e0a
6 changed files with 21 additions and 14 deletions

View File

@ -213,7 +213,7 @@
</script> </script>
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<script src="{{ 'assets/javascripts/bundle.cb647d62.min.js' | url }}"></script> <script src="{{ 'assets/javascripts/bundle.82d444e5.min.js' | url }}"></script>
{% for path in config["extra_javascript"] %} {% for path in config["extra_javascript"] %}
<script src="{{ path | url }}"></script> <script src="{{ path | url }}"></script>
{% endfor %} {% endfor %}

View File

@ -63,10 +63,14 @@ export function watchMedia(query: string): Observable<boolean> {
* @returns Print observable * @returns Print observable
*/ */
export function watchPrint(): Observable<boolean> { export function watchPrint(): Observable<boolean> {
const media = matchMedia("print")
return merge( return merge(
fromEvent(window, "beforeprint").pipe(mapTo(true)), fromEvent(window, "beforeprint").pipe(mapTo(true)),
fromEvent(window, "afterprint").pipe(mapTo(false)) fromEvent(window, "afterprint").pipe(mapTo(false))
) )
.pipe(
startWith(media.matches)
)
} }
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */

View File

@ -26,6 +26,7 @@ import {
Observable, Observable,
Subject, Subject,
defer, defer,
distinctUntilChanged,
distinctUntilKeyChanged, distinctUntilKeyChanged,
finalize, finalize,
map, map,
@ -195,11 +196,11 @@ export function mountCodeBlock(
mergeWith(watchElementSize(container) mergeWith(watchElementSize(container)
.pipe( .pipe(
takeUntil(push$.pipe(takeLast(1))), takeUntil(push$.pipe(takeLast(1))),
switchMap(({ width, height }) => width && height map(({ width, height }) => width && height),
? annotations$ distinctUntilChanged(),
: EMPTY switchMap(active => active ? annotations$ : EMPTY)
) )
)) )
) )
} }
} }

View File

@ -28,7 +28,6 @@ import {
finalize, finalize,
merge, merge,
share, share,
startWith,
takeLast, takeLast,
takeUntil takeUntil
} from "rxjs" } from "rxjs"
@ -100,6 +99,11 @@ function swap(source: HTMLElement, target: HTMLElement): void {
/** /**
* Mount code annotation list * Mount code annotation list
* *
* This function analyzes the given container code block and checks for markers
* referring to elements in the given code annotation list. If no markers are
* found, the list is left untouched. Otherwise, list elements are rendered as
* code annotations inside the code block.
*
* @param el - Code annotation list element * @param el - Code annotation list element
* @param container - Containing code block element * @param container - Containing code block element
* @param options - Options * @param options - Options
@ -107,9 +111,8 @@ function swap(source: HTMLElement, target: HTMLElement): void {
* @returns Code annotation list component observable * @returns Code annotation list component observable
*/ */
export function mountAnnotationList( export function mountAnnotationList(
el: HTMLElement, container: HTMLElement, options: MountOptions el: HTMLElement, container: HTMLElement, { print$ }: MountOptions
): Observable<Component<Annotation>> { ): Observable<Component<Annotation>> {
const { print$ } = options
/* Find and replace all markers with empty annotations */ /* Find and replace all markers with empty annotations */
const annotations = new Map<number, HTMLElement>() const annotations = new Map<number, HTMLElement>()
@ -130,7 +133,6 @@ export function mountAnnotationList(
/* Handle print mode - see https://bit.ly/3rgPdpt */ /* Handle print mode - see https://bit.ly/3rgPdpt */
print$ print$
.pipe( .pipe(
startWith(false),
takeUntil(done$.pipe(takeLast(1))) takeUntil(done$.pipe(takeLast(1)))
) )
.subscribe(active => { .subscribe(active => {