-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.js
69 lines (59 loc) · 2.11 KB
/
list.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
let isListHighlighted = false;
const addLists = () => {
removeLists();
const lists = [
{ tag: 'ul', label: 'ul' },
{ tag: 'ol', label: 'ol' },
{ tag: 'dl', label: 'dl' },
{ tag: 'li', label: 'li' },
{ tag: 'dd', label: 'dd' },
{ tag: 'dt', label: 'dt' }
];
const tagStyle = 'color:black; font-family:sans-serif; font-weight:bold; font-size:small; background-color:yellow;';
lists.forEach(({ tag, label }) => {
document.querySelectorAll(tag).forEach(el => {
// Create and style the opening tag
const openTag = document.createElement('strong');
openTag.className = 'openSpan';
openTag.style.cssText = tagStyle;
openTag.textContent = `<${label}>`;
// Create and style the closing tag
const closeTag = document.createElement('strong');
closeTag.className = 'closeSpan';
closeTag.style.cssText = tagStyle;
closeTag.textContent = `</${label}>`;
// Insert tags before and after the list element
el.insertAdjacentElement('afterbegin', openTag);
el.insertAdjacentElement('beforeend', closeTag);
});
});
// Highlight <p> elements inside <ul> and <ol>
document.querySelectorAll('ul, ol').forEach(parent => {
parent.querySelectorAll('p').forEach(p => {
p.style.outline = '2px solid red';
p.parentElement.style.outline = '2px solid red';
p.parentElement.insertAdjacentHTML('afterbegin', '<strong class="openSpan" style="color:black;font-family:sans-serif;font-weight:bold;font-size:small;background-color:yellow;">❌ NO CHILD LI</strong>');
});
});
// Add additional styling to lists
document.querySelectorAll('ul, ol, dl').forEach(el => {
el.style.outline = 'green 2px solid';
el.style.padding = '2px';
el.style.listStylePosition = 'inside';
});
};
// Function to remove lists with <strong> tags
const removeLists = () => {
document.querySelectorAll("strong.openSpan, strong.closeSpan").forEach(el => el.remove());
};
// Function to toggle list visibility
export const toggleLists = () => {
if (isListHighlighted) {
removeLists();
alert("List Markers Removed.");
} else {
addLists();
alert("List Markers Added.");
}
isListHighlighted = !isListHighlighted;
};