debian-mirror-gitlab/app/assets/javascripts/search/highlight_blob_search_result.js
2021-03-11 19:13:27 +05:30

15 lines
485 B
JavaScript

export default (search = '') => {
const highlightLineClass = 'hll';
const contentBody = document.getElementById('content-body');
const searchTerm = search.toLowerCase();
const blobs = contentBody.querySelectorAll('.blob-result');
blobs.forEach((blob) => {
const lines = blob.querySelectorAll('.line');
lines.forEach((line) => {
if (line.textContent.toLowerCase().includes(searchTerm)) {
line.classList.add(highlightLineClass);
}
});
});
};