UNPKG

@codedoc/core

Version:

Create beautiful modern documentation websites.

53 lines 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.codeLineRef$ = exports.initCodeLineRef = void 0; var rxjs_1 = require("rxjs"); var operators_1 = require("rxjs/operators"); var transport_1 = require("@connectv/sdh/transport"); var renderer_1 = require("../../../transport/renderer"); var component_1 = require("./component"); var commentRegex = new RegExp([ /\/\/\s?\@see\s(.*[^\s])\s*$/, /\/\*\s?\@see\s(.*[^\s])\s*\*\/$/, /\#\@see\s(.*[^\s])\s*$/, /\<\!\-\-\s?\@see\s(.*[^\s])\s*\-\-\>$/, ].map(function (r) { return "(?:" + r.source + ")"; }).join('|')); var mdlinkRegex = /\[(.*)\]\((.*)\)$/; function initCodeLineRef() { transport_1.onReady(function () { var renderer = renderer_1.getRenderer(); var target = new rxjs_1.Subject(); renderer.render(renderer.create(component_1.RefBox, { target: target })).on(document.body); var _exec = function () { document.querySelectorAll('pre>code>div').forEach(function (line$) { var ref = ''; var ref$; line$.querySelectorAll('.token.comment').forEach(function (comment$) { var match = commentRegex.exec(comment$.textContent || ''); if (match) { ref = match.slice(1).find(function (_) { return _; }) || ref; if (ref) ref$ = comment$; } }); if (ref.length > 0 && ref$) { ref$.remove(); var match = mdlinkRegex.exec(ref); if (match) { line$.setAttribute('data-ref', match[2] || ''); line$.setAttribute('data-ref-text', match[1] || ''); } else line$.setAttribute('data-ref', ref); rxjs_1.fromEvent(line$, 'mouseenter').pipe(operators_1.mapTo(line$)).subscribe(target); rxjs_1.fromEvent(line$, 'mouseleave').pipe(operators_1.mapTo(undefined)).subscribe(target); } }); }; _exec(); window.addEventListener('navigation', _exec); }); } exports.initCodeLineRef = initCodeLineRef; exports.codeLineRef$ = transport_1.funcTransport(initCodeLineRef); //# sourceMappingURL=index.js.map