Skip to content

Add line string feature #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
18 changes: 12 additions & 6 deletions src/SourcefileUrlMapPlugin.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
})
}
Expand Down
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};