Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
fe78984f
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fe78984f
编写于
6月 02, 2015
作者:
D
Douwe Maan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Actually ignore references in code blocks etc.
上级
5a1aa49b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
51 addition
and
49 deletion
+51
-49
app/helpers/gitlab_markdown_helper.rb
app/helpers/gitlab_markdown_helper.rb
+12
-15
lib/gitlab/reference_extractor.rb
lib/gitlab/reference_extractor.rb
+17
-34
lib/redcarpet/render/gitlab_html.rb
lib/redcarpet/render/gitlab_html.rb
+2
-0
spec/lib/gitlab/reference_extractor_spec.rb
spec/lib/gitlab/reference_extractor_spec.rb
+20
-0
未找到文件。
app/helpers/gitlab_markdown_helper.rb
浏览文件 @
fe78984f
...
...
@@ -41,29 +41,26 @@ module GitlabMarkdownHelper
fragment
.
to_html
.
html_safe
end
MARKDOWN_OPTIONS
=
{
no_intra_emphasis:
true
,
tables:
true
,
fenced_code_blocks:
true
,
strikethrough:
true
,
lax_spacing:
true
,
space_after_headers:
true
,
superscript:
true
,
footnotes:
true
}.
freeze
def
markdown
(
text
,
options
=
{})
unless
@markdown
&&
options
==
@options
@options
=
options
options
.
merge!
(
# Handled further down the line by Gitlab::Markdown::SanitizationFilter
escape_html:
false
)
# see https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderers-for-lunch
rend
=
Redcarpet
::
Render
::
GitlabHTML
.
new
(
self
,
user_color_scheme_class
,
options
)
# see https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use
@markdown
=
Redcarpet
::
Markdown
.
new
(
rend
,
no_intra_emphasis:
true
,
tables:
true
,
fenced_code_blocks:
true
,
strikethrough:
true
,
lax_spacing:
true
,
space_after_headers:
true
,
superscript:
true
,
footnotes:
true
)
@markdown
=
Redcarpet
::
Markdown
.
new
(
rend
,
MARKDOWN_OPTIONS
)
end
@markdown
.
render
(
text
).
html_safe
...
...
lib/gitlab/reference_extractor.rb
浏览文件 @
fe78984f
module
Gitlab
# Extract possible GFM references from an arbitrary String for further processing.
class
ReferenceExtractor
attr_accessor
:project
,
:current_user
,
:references
attr_accessor
:project
,
:current_user
def
initialize
(
project
,
current_user
=
nil
)
@project
=
project
...
...
@@ -9,48 +9,31 @@ module Gitlab
end
def
analyze
(
text
)
@_text
=
text
.
dup
references
.
clear
@text
=
markdown
.
render
(
text
.
dup
)
end
def
users
result
=
pipeline_result
(
:user
)
result
.
uniq
%i(user label issue merge_request snippet commit commit_range)
.
each
do
|
type
|
define_method
(
"
#{
type
}
s"
)
do
references
[
type
]
end
end
def
labels
result
=
pipeline_result
(
:label
)
result
.
uniq
end
def
issues
# TODO (rspeicher): What about external issues?
result
=
pipeline_result
(
:issue
)
result
.
uniq
end
def
merge_requests
result
=
pipeline_result
(
:merge_request
)
result
.
uniq
end
private
def
snippets
result
=
pipeline_result
(
:snippet
)
result
.
uniq
def
markdown
@markdown
||=
Redcarpet
::
Markdown
.
new
(
Redcarpet
::
Render
::
HTML
,
GitlabMarkdownHelper
::
MARKDOWN_OPTIONS
)
end
def
commit
s
result
=
pipeline_result
(
:commit
)
result
.
uniq
end
def
reference
s
@references
||=
Hash
.
new
do
|
references
,
type
|
type
=
type
.
to_sym
return
references
[
type
]
if
references
.
has_key?
(
type
)
def
commit_ranges
result
=
pipeline_result
(
:commit_range
)
result
.
uniq
references
[
type
]
=
pipeline_result
(
type
).
uniq
end
end
private
# Instantiate and call HTML::Pipeline with a single reference filter type,
# returning the result
#
...
...
@@ -69,7 +52,7 @@ module Gitlab
}
pipeline
=
HTML
::
Pipeline
.
new
([
filter
],
context
)
result
=
pipeline
.
call
(
@
_
text
)
result
=
pipeline
.
call
(
@text
)
result
[
:references
][
filter_type
]
end
...
...
lib/redcarpet/render/gitlab_html.rb
浏览文件 @
fe78984f
...
...
@@ -10,6 +10,8 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
@options
=
options
.
dup
@options
.
reverse_merge!
(
# Handled further down the line by Gitlab::Markdown::SanitizationFilter
escape_html:
false
project:
@template
.
instance_variable_get
(
"@project"
)
)
...
...
spec/lib/gitlab/reference_extractor_spec.rb
浏览文件 @
fe78984f
...
...
@@ -16,6 +16,26 @@ describe Gitlab::ReferenceExtractor do
expect
(
subject
.
users
).
to
eq
([
@u_foo
,
@u_bar
,
@u_offteam
])
end
it
'ignores user mentions inside specific elements'
do
@u_foo
=
create
(
:user
,
username:
'foo'
)
@u_bar
=
create
(
:user
,
username:
'bar'
)
@u_offteam
=
create
(
:user
,
username:
'offteam'
)
project
.
team
<<
[
@u_foo
,
:reporter
]
project
.
team
<<
[
@u_bar
,
:guest
]
subject
.
analyze
(
%Q{
Inline code: `@foo`
Code block:
```
@bar
```
}
)
expect
(
subject
.
users
).
to
eq
([])
end
it
'accesses valid issue objects'
do
@i0
=
create
(
:issue
,
project:
project
)
@i1
=
create
(
:issue
,
project:
project
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录