tangled
alpha
login
or
join now
evbogue.com
/
wiredove
1
fork
atom
a demonstration replicated social networking web app built with anproto
wiredove.net/
social
ed25519
protocols
1
fork
atom
overview
issues
pulls
pipelines
Scope syntax highlighting to newly rendered content
Everett Bogue
1 month ago
d47b43e6
78e4751e
+26
-11
2 changed files
expand all
collapse all
unified
split
render.js
route.js
+26
-1
render.js
···
7
7
import { noteSeen } from './sync.js'
8
8
import { promptKeypair } from './identify.js'
9
9
import { addBlockedAuthor, addHiddenHash, addMutedAuthor, isBlockedAuthor, removeHiddenHash, removeMutedAuthor, shouldHideMessage } from './moderation.js'
10
10
-
import { ensureQRious } from './lazy_vendor.js'
10
10
+
import { ensureHighlight, ensureQRious } from './lazy_vendor.js'
11
11
import { addReplyToIndex, ensureReplyIndex, getReplyCount, getRepliesForParent } from './reply_index.js'
12
12
13
13
export const render = {}
···
68
68
timestampObserver.observe(element)
69
69
}
70
70
71
71
+
const highlightCodeIn = async (container) => {
72
72
+
if (!container) { return }
73
73
+
const nodes = Array.from(container.querySelectorAll('pre code, pre'))
74
74
+
if (!nodes.length) { return }
75
75
+
let hljs
76
76
+
try {
77
77
+
hljs = await ensureHighlight()
78
78
+
} catch (err) {
79
79
+
console.warn('highlight load failed', err)
80
80
+
return
81
81
+
}
82
82
+
if (!hljs || typeof hljs.highlightElement !== 'function') { return }
83
83
+
nodes.forEach((node) => {
84
84
+
const target = node.matches('pre') && node.querySelector('code')
85
85
+
? node.querySelector('code')
86
86
+
: node
87
87
+
if (!target || target.dataset.hljsDone === 'true') { return }
88
88
+
hljs.highlightElement(target)
89
89
+
target.dataset.hljsDone = 'true'
90
90
+
})
91
91
+
}
92
92
+
71
93
const updateReplyCount = (parentHash) => {
72
94
const target = replyCountTargets.get(parentHash)
73
95
if (!target) { return }
···
573
595
: state.baseYaml.body
574
596
state.currentBody = bodySource
575
597
state.contentDiv.innerHTML = await renderBody(bodySource, baseReply)
598
598
+
await highlightCodeIn(state.contentDiv)
576
599
hydrateReplyPreviews(state.contentDiv)
577
600
if (!currentEdit) {
578
601
await applyProfile(state.contentHash, state.baseYaml)
···
1045
1068
div.classList.remove('material-symbols-outlined')
1046
1069
const bioHtml = await markdown(yaml.bio)
1047
1070
div.innerHTML = `<p><strong>New bio:</strong></p>${bioHtml}`
1071
1071
+
await highlightCodeIn(div)
1048
1072
await applyProfile(contentHash, yaml)
1049
1073
await queueLinkedHashes(yaml)
1050
1074
return
···
1061
1085
updateReplyCount(yaml.reply)
1062
1086
}
1063
1087
div.innerHTML = await renderBody(yaml.body, yaml.reply)
1088
1088
+
await highlightCodeIn(div)
1064
1089
hydrateReplyPreviews(div)
1065
1090
await applyProfile(contentHash, yaml)
1066
1091
await queueLinkedHashes(yaml)
-10
route.js
···
13
13
import { noteInterest } from './sync.js'
14
14
import { isBlockedAuthor } from './moderation.js'
15
15
import { buildProfileHeader } from './profile_header.js'
16
16
-
import { ensureHighlight } from './lazy_vendor.js'
17
16
18
17
const HOME_SEED_COUNT = 3
19
18
const HOME_BACKFILL_DEPTH = 6
···
229
228
await render.blob(src, { hash, opened })
230
229
}
231
230
}
232
232
-
setTimeout(() => {
233
233
-
void ensureHighlight().then((hljs) => {
234
234
-
if (hljs && typeof hljs.highlightAll === 'function') {
235
235
-
hljs.highlightAll()
236
236
-
}
237
237
-
}).catch((err) => {
238
238
-
console.warn('highlight load failed', err)
239
239
-
})
240
240
-
}, 100)
241
231
}
242
232
243
233
window.onhashchange = async () => {