diff --git a/README.md b/README.md index e6e2728..419df10 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,8 @@ The `your-sourcefile-map.json` structure is: There can be one or more mapping rules. For each *Defined in* only the first rule that matches is applied. In the above example the last rule would match all source files that did not start with `modules/module-one`. This compares to the *Simple Prefix* option. +If you need to pass a custom string to indicate the line numeber in the url (defaults to `#L`), you can pass the `--sourcefile-url-lines-str` option. + --- The options are mutually exclusive. It is not possible to use `--sourcefile-url-prefix` and `--sourcefile-url-map` at the same time. diff --git a/src/SourcefileUrlMapPlugin.ts b/src/SourcefileUrlMapPlugin.ts index f890989..7998fd1 100644 --- a/src/SourcefileUrlMapPlugin.ts +++ b/src/SourcefileUrlMapPlugin.ts @@ -1,8 +1,7 @@ import * as Path from 'path' import * as FS from 'fs-extra' -import {Component} from 'typedoc/dist/lib/utils/component' -import {ConverterComponent} from 'typedoc/dist/lib/converter/components' -import {Converter} from 'typedoc/dist/lib/converter/converter' +import {Component, ConverterComponent} from 'typedoc/dist/lib/converter/components'; +import {Converter} from 'typedoc/dist/lib/converter/converter'; import {Context} from 'typedoc/dist/lib/converter/context' import {SourceReference} from 'typedoc/dist/lib/models/sources/file' import {Options} from 'typedoc/dist/lib/utils/options/options' @@ -16,10 +15,13 @@ interface Mapping { export class SourcefileUrlMapPlugin extends ConverterComponent { private mappings: Mapping[] | undefined + private linesStr: string | undefined public initialize(): void { - this.listenTo(this.owner, Converter.EVENT_BEGIN, this.onBegin) + this.listenTo(this.owner, { + [Converter.EVENT_BEGIN]: this.onBegin + }) } private onBegin(): void @@ -29,6 +31,8 @@ export class SourcefileUrlMapPlugin extends ConverterComponent { const mapRelativePath = options.getValue('sourcefile-url-map') const urlPrefix = options.getValue('sourcefile-url-prefix') + this.linesStr = options.getValue('sourcefile-url-lines-str') || '#L' + if ( (typeof mapRelativePath !== 'string') && (typeof urlPrefix !== 'string') ) { return } @@ -49,7 +53,9 @@ export class SourcefileUrlMapPlugin extends ConverterComponent { } // register handler - this.listenTo(this.owner, Converter.EVENT_RESOLVE_END, this.onEndResolve) + this.listenTo(this.owner, { + [Converter.EVENT_RESOLVE_END]: this.onEndResolve, + }) } catch ( e ) { console.error('typedoc-plugin-sourcefile-url: ' + e.message) @@ -124,7 +130,7 @@ export class SourcefileUrlMapPlugin extends ConverterComponent { if ( reflection.sources ) { reflection.sources.forEach((source: SourceReference) => { if (source.file && source.file.url) { - source.url = source.file.url + '#L' + source.line + source.url = source.file.url + this.linesStr + source.line } }) } diff --git a/src/main.js b/src/main.js index d18128f..37b79f4 100644 --- a/src/main.js +++ b/src/main.js @@ -5,6 +5,7 @@ module.exports = function(PluginHost) { app.options.addDeclaration({name: 'sourcefile-url-map'}); app.options.addDeclaration({name: 'sourcefile-url-prefix'}); + app.options.addDeclaration({name: 'sourcefile-url-lines-str'}); app.converter.addComponent('sourcefile-url', plugin.SourcefileUrlMapPlugin); }; \ No newline at end of file