Fixed highlighted lines adding blank lines when copying

This commit is contained in:
squidfunk 2021-12-19 13:40:16 +01:00
parent 368cad0955
commit be0a36d1b0
7 changed files with 27 additions and 22 deletions

View File

@ -34,7 +34,7 @@
{% endif %}
{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.052bca4c.min.css' | url }}">
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.edf004c2.min.css' | url }}">
{% if config.theme.palette %}
{% set palette = config.theme.palette %}
<link rel="stylesheet" href="{{ 'assets/stylesheets/palette.e6a45f82.min.css' | url }}">
@ -213,7 +213,7 @@
</script>
{% endblock %}
{% block scripts %}
<script src="{{ 'assets/javascripts/bundle.adc5bf89.min.js' | url }}"></script>
<script src="{{ 'assets/javascripts/bundle.9ab3d63a.min.js' | url }}"></script>
{% for path in config["extra_javascript"] %}
<script src="{{ path | url }}"></script>
{% endfor %}

View File

@ -52,24 +52,14 @@ interface SetupOptions {
/**
* Extract text to copy
*
* This function hides annotations prior to extracting the text from the given
* code block, so they're not included in the text that is copied to clipboard.
*
* @param el - HTML element
*
* @returns Extracted text
*/
function extract(el: HTMLElement): string {
const annotations = getElements(".md-annotation", el)
for (const annotation of annotations)
annotation.hidden = true
/* Extract text and show annotations */
el.setAttribute("data-md-copying", "")
const text = el.innerText
for (const annotation of annotations)
annotation.hidden = false
/* Return extracted text */
el.removeAttribute("data-md-copying")
return text
}

View File

@ -210,6 +210,21 @@
position: absolute;
visibility: hidden;
}
// Copying in progress - this class is set before the content is copied and
// removed after copying is done to mitigate whitespace-related issues.
code[data-md-copying] {
// Remove highlighted lines - see https://bit.ly/32iVGWh
.hll {
display: contents;
}
// Remove code annotation
.md-annotation {
display: none;
}
}
}
// ----------------------------------------------------------------------------