@@ -11,6 +11,11 @@ object SourceLink:
1111 val SubPath = " ([^=]+)=(.+)" .r
1212 val KnownProvider = raw " (\w+):\/\/([^\/]+)\/([^\/]+) " .r
1313 val BrokenKnownProvider = raw " (\w+):\/\/.+ " .r
14+ val ScalaDocPatten = raw " €\{(TPL_NAME|TPL_NAME|FILE_PATH|FILE_EXT|FILE_LINE|FILE_PATH_EXT)\} " .r
15+ val SupportedScalaDocPatternReplacements = Map (
16+ " €{FILE_PATH_EXT}" -> " {{ path }}" ,
17+ " €{FILE_LINE}" -> " {{ line }}"
18+ )
1419
1520 def githubTemplate (organization : String , repo : String )(revision : String ) =
1621 s """ https://github.com/ $organization/ $repo/{{ operation | replace: "view", "blob" }}/ $revision/{{ path }}#L{{ line }} """ .stripMargin
@@ -22,8 +27,8 @@ object SourceLink:
2227 private def parseLinkDefinition (s : String ): Option [SourceLink ] = ???
2328
2429 def parse (string : String , revision : Option [String ]): Either [String , SourceLink ] =
25- def asRawTemplate =
26- try Right (SourceLink (None ,Template .parse(string ))) catch
30+ def asTemplate ( template : String ) =
31+ try Right (SourceLink (None ,Template .parse(template ))) catch
2732 case e : RuntimeException =>
2833 Left (s " Failed to parse template: ${e.getMessage}" )
2934
@@ -49,7 +54,14 @@ object SourceLink:
4954 Right (SourceLink (Some (Paths .get(prefix)), template))
5055 case BrokenKnownProvider (" gitlab" | " github" ) =>
5156 Left (s " Does not match known provider syntax: `<name>://organization/repository` " )
52- case template => asRawTemplate
57+ case scaladocSetting if ScalaDocPatten .findFirstIn(scaladocSetting).nonEmpty =>
58+ val all = ScalaDocPatten .findAllIn(scaladocSetting)
59+ val (supported, unsupported) = all.partition(SupportedScalaDocPatternReplacements .contains)
60+ if unsupported.nonEmpty then Left (s " Unsupported patterns from scaladoc format are used: ${unsupported.mkString(" " )}" )
61+ else asTemplate(supported.foldLeft(string)((template, pattern) =>
62+ template.replace(pattern, SupportedScalaDocPatternReplacements (pattern))))
63+
64+ case template => asTemplate(template)
5365
5466
5567type Operation = " view" | " edit"
@@ -86,8 +98,12 @@ object SourceLinks:
8698 |where <source-link> is one of following:
8799 | - `github://<organization>/<repository>` (requires revision to be specified as argument for scala3doc)
88100 | - `gitlab://<organization>/<repository>` (requires revision to be specified as argument for scala3doc)
101+ | - <scaladoc-template>
89102 | - <template>
90103 |
104+ |<scaladoc-template> is a format for `doc-source-url` parameter scaladoc.
105+ |NOTE: We only supports `€{FILE_PATH_EXT}` and €{FILE_LINE} patterns
106+ |
91107 |<template> is a liqid template string that can accepts follwoing arguments:
92108 | - `operation`: either "view" or "edit"
93109 | - `path`: relative path of file to provide link to
0 commit comments