spec-md
Version:
Renders Markdown with some additions into an HTML format commonly used for writing technical specification documents. Markdown additions include code syntax highlighting, edit annotations, and the definition of algorithms and grammar productions.
27 lines (22 loc) • 684 B
JavaScript
var styleSheet = document.getElementsByTagName('style')[0].sheet;
var ruleIndex;
function removeHighlight() {
if (ruleIndex) {
styleSheet.deleteRule(ruleIndex);
ruleIndex = void 0;
}
}
function highlightKeyword(name) {
removeHighlight();
ruleIndex = styleSheet.insertRule(
'*[data-name="' + name + '"] { background: rgba(230,215,0,0.12); }',
styleSheet.cssRules.length
);
}
document.documentElement.addEventListener('mouseover', function (event) {
var nameAttribute = event.target.attributes['data-name'];
if (nameAttribute) {
highlightKeyword(nameAttribute.value);
}
});
document.documentElement.addEventListener('mouseout', removeHighlight);