Skip to content

Commit 5802a2a

Browse files
committed
fix #1
1 parent b750d3d commit 5802a2a

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name := "gitbucket-embedding-plugin"
22
organization := "io.github.gitbucket"
3-
version := "0.1.1"
3+
version := "0.1.2"
44
scalaVersion := "2.13.1"
55
gitbucketVersion := "4.34.0"

src/main/resources/embedding/assets/entry.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ $(function(){
2222
return url.replace("/blob/", "/raw/");
2323
};
2424

25-
function getCommitUrl(url, filename){
25+
function getCommitUrl(url, filepath){
2626
url = url.replace("/blob/", "/commit/")
27-
reg = new RegExp('/' + filename + '#L\\d+(-L\\d+)?$')
27+
reg = new RegExp('/' + filepath + '#L\\d+(-L\\d+)?$')
2828
return url.replace(reg, "")
2929
};
3030

@@ -43,7 +43,7 @@ $(function(){
4343
};
4444

4545
function convertLinks(){
46-
var matchPattern = new RegExp('https?://' + location.host + '(/[\\w-\\.]+)?/([\\w-\\.]+)/([\\w-\\.]+)/blob/([\\w-\\.]+)/([\\w-\\.]+)#L([0-9]+)(-L[0-9]+)?$');
46+
var matchPattern = new RegExp('https?://' + location.host + '(/[\\w-\\.]+)?/([\\w-\\.]+)/([\\w-\\.]+)/blob/([\\w-\\.]+)/([\\w-\\./]+)#L([0-9]+)-?L?([0-9]+)?$');
4747
var elements = $('.markdown-body p a');
4848
var element;
4949
var url;
@@ -57,18 +57,18 @@ $(function(){
5757
let owner = mat[2];
5858
let repo = mat[3];
5959
let commit = mat[4];
60-
let filename = mat[5];
60+
let filepath = mat[5];
6161
let startLine = Number(mat[6]);
6262
let endLine = startLine;
6363
if(typeof mat[7] !== "undefined"){
64-
endLine = Number(mat[7].replace("-L", ""));
64+
endLine = Number(mat[7]);
6565
};
66-
let commitUrl = getCommitUrl(url, filename)
66+
let commitUrl = getCommitUrl(url, filepath)
6767
try{
6868
let content = getContent(url);
6969
let linesAll = content.split("\n");
7070
let lines = linesAll.slice(startLine-1, endLine).join("\n");
71-
let snippetElement = generateSnippetElement(repo, filename, commit, startLine, endLine, lines, url, commitUrl);
71+
let snippetElement = generateSnippetElement(repo, filepath, commit, startLine, endLine, lines, url, commitUrl);
7272
element.insertAdjacentHTML('afterend', snippetElement);
7373
element.remove();
7474
}catch(e){}

src/main/scala/Plugin.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ class Plugin extends gitbucket.core.plugin.Plugin {
99
override val description: String = "Convert link of code to embed snippet"
1010
override val versions: List[Version] = List(
1111
new Version("0.1.0"),
12-
new Version("0.1.1")
12+
new Version("0.1.1"),
13+
new Version("0.1.2")
1314
)
1415

1516
override val assetsMappings: Seq[(String, String)] = Seq("/embedding" -> "/embedding/assets")

0 commit comments

Comments
 (0)