Welcome to mirror list, hosted at ThFree Co, Russian Federation.

link_dependencies.js « plugins « source_viewer « components « vue_shared « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fca2616f069ba82289a4dd14bb683680f0606a23 (plain)
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
import packageJsonLinker from './utils/package_json_linker';
import gemspecLinker from './utils/gemspec_linker';
import godepsJsonLinker from './utils/godeps_json_linker';
import gemfileLinker from './utils/gemfile_linker';
import podspecJsonLinker from './utils/podspec_json_linker';
import composerJsonLinker from './utils/composer_json_linker';

const DEPENDENCY_LINKERS = {
  package_json: packageJsonLinker,
  gemspec: gemspecLinker,
  godeps_json: godepsJsonLinker,
  gemfile: gemfileLinker,
  podspec_json: podspecJsonLinker,
  composer_json: composerJsonLinker,
};

/**
 * Highlight.js plugin for generating links to dependencies when viewing dependency files.
 *
 * Plugin API: https://github.com/highlightjs/highlight.js/blob/main/docs/plugin-api.rst
 *
 * @param {Object} result - an object that represents the highlighted result from Highlight.js
 * @param {String} fileType - a string containing the file type
 * @param {String} rawContent - raw (non-highlighted) file content
 */
export default (result, fileType, rawContent) => {
  if (DEPENDENCY_LINKERS[fileType]) {
    try {
      // eslint-disable-next-line no-param-reassign
      result.value = DEPENDENCY_LINKERS[fileType](result, rawContent);
    } catch (e) {
      // Shallowed (do nothing), in this case the original unlinked dependencies will be rendered.
    }
  }
};