Skip to content

Commit c143bb2

Browse files
committed
Adding generic docs js file
1 parent ab1762b commit c143bb2

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

_posts/2020-07-11-create-instance-of-type-net-core.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: post
3-
title: Creating an Instance of Type, 8 Years Later
3+
title: Creating an Instance of a Type, 8 Years Later
44
excerpt: I recently had an enquiry about code in a post from 2012, and thought I'd revisit it. It's better now.
55
tags: [Expression Trees, Performance]
66
images_dir: '2020-07-11/'

assets/js/ao-docs.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
$(function () {
2+
var i, l, terms = document.location.search.substring(1).split('&'), term = '';
3+
for (i = 0, l = terms.length; i < l; ++i) {
4+
term = terms[i].split('=');
5+
if (term[0] === 't') {
6+
term = term[1];
7+
break;
8+
}
9+
}
10+
var hlCode = document.querySelectorAll('pre code.language-cs'),
11+
hlLength = hlCode.length,
12+
termsRegex = new RegExp('\\b(' + term + ')\\b', 'g'),
13+
typeRegex = /(new<\/span>\W+|class<\/span> <span class="hljs-title">|public<\/span>\W+|: <span class="hljs-title">|&lt;)([A-Z][^& \(\[\]]+)( |{|\(|\[\]&gt;|&gt;)/g,
14+
genericTypeRegex = /(I{0,1}Dictionary|IEnumerable|IReadOnlyCollection|I{0,1}Collection|I{0,1}List)&lt;/g,
15+
observer = new MutationObserver(function (mutations) {
16+
for (i = 0, l = mutations.length; i < l; ++i) {
17+
var mutation = mutations[i];
18+
if (mutation.attributeName === 'class') {
19+
var innerHtml = mutation.target.innerHTML
20+
.replace(termsRegex, '<span class="hljs-type">$1</span>')
21+
.replace(typeRegex, '$1<span class="hljs-type">$2</span>$3')
22+
.replace(genericTypeRegex, '<span class="hljs-type">$1</span>&lt;');
23+
mutation.target.innerHTML = innerHtml;
24+
}
25+
}
26+
}),
27+
config = { attributes: true };
28+
29+
for (i = 0; i < hlLength; ++i) {
30+
observer.observe(hlCode[i], config);
31+
}
32+
alert(termsRegex);
33+
});

assets/js/ao-docs.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundleconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,11 @@
3535
"inputFiles": [
3636
"assets/css/docs-styles.css"
3737
]
38+
},
39+
{
40+
"outputFileName": "assets/js/ao-docs.min.js",
41+
"inputFiles": [
42+
"assets/js/ao-docs.js"
43+
]
3844
}
3945
]

0 commit comments

Comments
 (0)