Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
a963721f
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,发现更多精彩内容 >>
提交
a963721f
编写于
9月 02, 2018
作者:
B
Brett Walker
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
render using RedCarpet if legacy_render parameter is set
上级
e41b9994
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
181 addition
and
28 deletion
+181
-28
app/helpers/markup_helper.rb
app/helpers/markup_helper.rb
+3
-3
app/services/preview_markdown_service.rb
app/services/preview_markdown_service.rb
+5
-1
app/views/projects/_wiki.html.haml
app/views/projects/_wiki.html.haml
+2
-1
app/views/projects/blob/edit.html.haml
app/views/projects/blob/edit.html.haml
+1
-1
app/views/projects/blob/preview.html.haml
app/views/projects/blob/preview.html.haml
+2
-1
app/views/projects/blob/viewers/_markup.html.haml
app/views/projects/blob/viewers/_markup.html.haml
+6
-2
app/views/projects/wikis/_form.html.haml
app/views/projects/wikis/_form.html.haml
+3
-1
app/views/projects/wikis/_sidebar.html.haml
app/views/projects/wikis/_sidebar.html.haml
+2
-1
app/views/projects/wikis/show.html.haml
app/views/projects/wikis/show.html.haml
+2
-1
app/views/search/results/_snippet_blob.html.haml
app/views/search/results/_snippet_blob.html.haml
+2
-1
changelogs/unreleased/bw-commonmark-for-files.yml
changelogs/unreleased/bw-commonmark-for-files.yml
+5
-0
spec/features/projects/blobs/blob_show_spec.rb
spec/features/projects/blobs/blob_show_spec.rb
+48
-2
spec/features/projects/blobs/edit_spec.rb
spec/features/projects/blobs/edit_spec.rb
+32
-2
spec/features/projects/wiki/markdown_preview_spec.rb
spec/features/projects/wiki/markdown_preview_spec.rb
+28
-0
spec/features/snippets/show_spec.rb
spec/features/snippets/show_spec.rb
+33
-11
spec/services/preview_markdown_service_spec.rb
spec/services/preview_markdown_service_spec.rb
+7
-0
未找到文件。
app/helpers/markup_helper.rb
浏览文件 @
a963721f
...
...
@@ -111,17 +111,17 @@ module MarkupHelper
prepare_for_rendering
(
html
,
context
)
end
def
render_wiki_content
(
wiki_page
)
def
render_wiki_content
(
wiki_page
,
context
=
{}
)
text
=
wiki_page
.
content
return
''
unless
text
.
present?
context
=
{
context
.
merge!
(
{
pipeline: :wiki
,
project:
@project
,
project_wiki:
@project_wiki
,
page_slug:
wiki_page
.
slug
,
issuable_state_filter_enabled:
true
}
}
)
html
=
case
wiki_page
.
format
...
...
app/services/preview_markdown_service.rb
浏览文件 @
a963721f
...
...
@@ -43,6 +43,10 @@ class PreviewMarkdownService < BaseService
end
def
markdown_engine
CacheMarkdownField
::
MarkdownEngine
.
from_version
(
params
[
:markdown_version
].
to_i
)
if
params
[
:legacy_render
]
:redcarpet
else
CacheMarkdownField
::
MarkdownEngine
.
from_version
(
params
[
:markdown_version
].
to_i
)
end
end
end
app/views/projects/_wiki.html.haml
浏览文件 @
a963721f
...
...
@@ -2,7 +2,8 @@
%div
{
class:
container_class
}
.prepend-top-default.append-bottom-default
.wiki
=
render_wiki_content
(
@wiki_home
)
-
context
=
params
[
:legacy_render
]
?
{
markdown_engine: :redcarpet
}
:
{}
=
render_wiki_content
(
@wiki_home
,
context
)
-
else
-
can_create_wiki
=
can?
(
current_user
,
:create_wiki
,
@project
)
.project-home-empty
{
class:
[(
'row-content-block'
if
can_create_wiki
),
(
'content-block'
unless
can_create_wiki
)]
}
...
...
app/views/projects/blob/edit.html.haml
浏览文件 @
a963721f
...
...
@@ -21,7 +21,7 @@
Write
%li
=
link_to
'#preview'
,
'data-preview-url'
=>
project_preview_blob_path
(
@project
,
@id
)
do
=
link_to
'#preview'
,
'data-preview-url'
=>
project_preview_blob_path
(
@project
,
@id
,
legacy_render:
params
[
:legacy_render
]
)
do
=
editing_preview_title
(
@blob
.
name
)
=
form_tag
(
project_update_blob_path
(
@project
,
@id
),
method: :put
,
class:
'js-quick-submit js-requires-input js-edit-blob-form'
,
data:
blob_editor_paths
)
do
...
...
app/views/projects/blob/preview.html.haml
浏览文件 @
a963721f
...
...
@@ -2,7 +2,8 @@
.diff-content
-
if
markup?
(
@blob
.
name
)
.file-content.wiki
=
markup
(
@blob
.
name
,
@content
)
-
context
=
params
[
:legacy_render
]
?
{
markdown_engine: :redcarpet
}
:
{}
=
markup
(
@blob
.
name
,
@content
,
context
)
-
else
.file-content.code.js-syntax-highlight
-
unless
@diff_lines
.
empty?
...
...
app/views/projects/blob/viewers/_markup.html.haml
浏览文件 @
a963721f
-
blob
=
viewer
.
blob
-
rendered_markup
=
blob
.
rendered_markup
if
blob
.
respond_to?
(
:rendered_markup
)
-
context
=
{}
-
if
params
[
:legacy_render
]
-
context
[
:markdown_engine
]
=
:redcarpet
-
else
-
context
[
:rendered
]
=
blob
.
rendered_markup
if
blob
.
respond_to?
(
:rendered_markup
)
.file-content.wiki
=
markup
(
blob
.
name
,
blob
.
data
,
rendered:
rendered_markup
)
=
markup
(
blob
.
name
,
blob
.
data
,
context
)
app/views/projects/wikis/_form.html.haml
浏览文件 @
a963721f
-
commit_message
=
@page
.
persisted?
?
s_
(
"WikiPageEdit|Update %{page_title}"
)
:
s_
(
"WikiPageCreate|Create %{page_title}"
)
-
commit_message
=
commit_message
%
{
page_title:
@page
.
title
}
-
markdown_version
=
params
[
:legacy_render
]
?
CacheMarkdownField
::
CACHE_REDCARPET_VERSION
:
0
=
form_for
[
@project
.
namespace
.
becomes
(
Namespace
),
@project
,
@page
],
method:
@page
.
persisted?
?
:put
:
:post
,
html:
{
class:
'wiki-form common-note-form prepend-top-default js-quick-submit'
}
do
|
f
|
html:
{
class:
'wiki-form common-note-form prepend-top-default js-quick-submit'
},
data:
{
markdown_version:
markdown_version
}
do
|
f
|
=
form_errors
(
@page
)
-
if
@page
.
persisted?
...
...
app/views/projects/wikis/_sidebar.html.haml
浏览文件 @
a963721f
...
...
@@ -12,7 +12,8 @@
.blocks-container
.block.block-first
-
if
@sidebar_page
=
render_wiki_content
(
@sidebar_page
)
-
context
=
params
[
:legacy_render
]
?
{
markdown_engine: :redcarpet
}
:
{}
=
render_wiki_content
(
@sidebar_page
,
context
)
-
else
%ul
.wiki-pages
=
render
@sidebar_wiki_entries
,
context:
'sidebar'
...
...
app/views/projects/wikis/show.html.haml
浏览文件 @
a963721f
...
...
@@ -26,6 +26,7 @@
.prepend-top-default.append-bottom-default
.wiki
=
render_wiki_content
(
@page
)
-
context
=
params
[
:legacy_render
]
?
{
markdown_engine: :redcarpet
}
:
{}
=
render_wiki_content
(
@page
,
context
)
=
render
'sidebar'
app/views/search/results/_snippet_blob.html.haml
浏览文件 @
a963721f
...
...
@@ -21,7 +21,8 @@
.file-content.wiki
-
snippet_chunks
.
each
do
|
chunk
|
-
unless
chunk
[
:data
].
empty?
=
markup
(
snippet
.
file_name
,
chunk
[
:data
])
-
context
=
params
[
:legacy_render
]
?
{
markdown_engine: :redcarpet
}
:
{}
=
markup
(
snippet
.
file_name
,
chunk
[
:data
],
context
)
-
else
.file-content.code
.nothing-here-block
Empty file
...
...
changelogs/unreleased/bw-commonmark-for-files.yml
0 → 100644
浏览文件 @
a963721f
---
title
:
Render files (`.md`) and wikis using CommonMark
merge_request
:
21228
author
:
type
:
changed
spec/features/projects/blobs/blob_show_spec.rb
浏览文件 @
a963721f
...
...
@@ -5,8 +5,8 @@ describe 'File blob', :js do
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
)
}
def
visit_blob
(
path
,
anchor:
nil
,
ref:
'master'
)
visit
project_blob_path
(
project
,
File
.
join
(
ref
,
path
),
anchor:
anchor
)
def
visit_blob
(
path
,
anchor:
nil
,
ref:
'master'
,
legacy_render:
nil
)
visit
project_blob_path
(
project
,
File
.
join
(
ref
,
path
),
anchor:
anchor
,
legacy_render:
legacy_render
)
wait_for_requests
end
...
...
@@ -142,6 +142,52 @@ describe 'File blob', :js do
end
end
context
'Markdown rendering'
do
before
do
project
.
add_maintainer
(
project
.
creator
)
Files
::
CreateService
.
new
(
project
,
project
.
creator
,
start_branch:
'master'
,
branch_name:
'master'
,
commit_message:
"Add RedCarpet and CommonMark Markdown "
,
file_path:
'files/commonmark/file.md'
,
file_content:
"1. one
\n
- sublist
\n
"
).
execute
end
context
'when rendering default markdown'
do
before
do
visit_blob
(
'files/commonmark/file.md'
)
wait_for_requests
end
it
'renders using CommonMark'
do
aggregate_failures
do
expect
(
page
).
to
have_content
(
"sublist"
)
expect
(
page
).
not_to
have_xpath
(
"//ol//li//ul"
)
end
end
end
context
'when rendering legacy markdown'
do
before
do
visit_blob
(
'files/commonmark/file.md'
,
legacy_render:
1
)
wait_for_requests
end
it
'renders using RedCarpet'
do
aggregate_failures
do
expect
(
page
).
to
have_content
(
"sublist"
)
expect
(
page
).
to
have_xpath
(
"//ol//li//ul"
)
end
end
end
end
context
'Markdown file (stored in LFS)'
do
before
do
project
.
add_maintainer
(
project
.
creator
)
...
...
spec/features/projects/blobs/edit_spec.rb
浏览文件 @
a963721f
...
...
@@ -7,6 +7,7 @@ describe 'Editing file blob', :js do
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
,
source_branch:
'feature'
,
target_branch:
'master'
)
}
let
(
:branch
)
{
'master'
}
let
(
:file_path
)
{
project
.
repository
.
ls_files
(
project
.
repository
.
root_ref
)[
1
]
}
let
(
:readme_file_path
)
{
'README.md'
}
context
'as a developer'
do
let
(
:user
)
{
create
(
:user
)
}
...
...
@@ -20,14 +21,19 @@ describe 'Editing file blob', :js do
def
edit_and_commit
(
commit_changes:
true
)
wait_for_requests
find
(
'.js-edit-blob'
).
click
find
(
'#editor'
)
execute_script
(
'ace.edit("editor").setValue("class NextFeature\nend\n")'
)
fill_editor
(
content:
"class NextFeature
\\
nend
\\
n"
)
if
commit_changes
click_button
'Commit changes'
end
end
def
fill_editor
(
content:
"class NextFeature
\\
nend
\\
n"
)
wait_for_requests
find
(
'#editor'
)
execute_script
(
"ace.edit('editor').setValue('
#{
content
}
')"
)
end
context
'from MR diff'
do
before
do
visit
diffs_project_merge_request_path
(
project
,
merge_request
)
...
...
@@ -63,6 +69,30 @@ describe 'Editing file blob', :js do
expect
(
new_line_count
).
to
be
>
0
end
end
context
'when rendering the preview'
do
it
'renders content with CommonMark'
do
visit
project_edit_blob_path
(
project
,
tree_join
(
branch
,
readme_file_path
))
fill_editor
(
content:
"1. one
\\
n - sublist
\\
n"
)
click_link
'Preview'
wait_for_requests
# the above generates two seperate lists (not embedded) in CommonMark
expect
(
page
).
to
have_content
(
"sublist"
)
expect
(
page
).
not_to
have_xpath
(
"//ol//li//ul"
)
end
it
'renders content with RedCarpet when legacy_render is set'
do
visit
project_edit_blob_path
(
project
,
tree_join
(
branch
,
readme_file_path
),
legacy_render:
1
)
fill_editor
(
content:
"1. one
\\
n - sublist
\\
n"
)
click_link
'Preview'
wait_for_requests
# the above generates a sublist list in RedCarpet
expect
(
page
).
to
have_content
(
"sublist"
)
expect
(
page
).
to
have_xpath
(
"//ol//li//ul"
)
end
end
end
context
'visit blob edit'
do
...
...
spec/features/projects/wiki/markdown_preview_spec.rb
浏览文件 @
a963721f
...
...
@@ -162,6 +162,34 @@ describe 'Projects > Wiki > User previews markdown changes', :js do
expect
(
page
.
html
).
to
include
(
"<a href=
\"
/
#{
project
.
full_path
}
/wikis/title%20with%20spaces
\"
>spaced link</a>"
)
end
end
context
'when rendering the preview'
do
it
'renders content with CommonMark'
do
create_wiki_page
'a-page/b-page/c-page/common-mark'
click_link
'Edit'
fill_in
:wiki_content
,
with:
"1. one
\n
- sublist
\n
"
click_on
"Preview"
# the above generates two seperate lists (not embedded) in CommonMark
expect
(
page
).
to
have_content
(
"sublist"
)
expect
(
page
).
not_to
have_xpath
(
"//ol//li//ul"
)
end
it
'renders content with RedCarpet when legacy_render is set'
do
wiki_page
=
create
(
:wiki_page
,
wiki:
project
.
wiki
,
attrs:
{
title:
'home'
,
content:
"Empty content"
})
visit
(
project_wiki_edit_path
(
project
,
wiki_page
,
legacy_render:
1
))
fill_in
:wiki_content
,
with:
"1. one
\n
- sublist
\n
"
click_on
"Preview"
# the above generates a sublist list in RedCarpet
expect
(
page
).
to
have_content
(
"sublist"
)
expect
(
page
).
to
have_xpath
(
"//ol//li//ul"
)
end
end
end
it
"does not linkify double brackets inside code blocks as expected"
do
...
...
spec/features/snippets/show_spec.rb
浏览文件 @
a963721f
...
...
@@ -68,23 +68,45 @@ describe 'Snippet', :js do
end
end
context
'
with cached Redcarpet html
'
do
let
(
:snippet
)
{
create
(
:personal_snippet
,
:public
,
file_name:
file_name
,
content:
content
,
cached_markdown_version:
CacheMarkdownField
::
CACHE_REDCARPET_VERSION
)
}
context
'
Markdown rendering
'
do
let
(
:snippet
)
{
create
(
:personal_snippet
,
:public
,
file_name:
file_name
,
content:
content
)
}
let
(
:file_name
)
{
'test.md'
}
let
(
:content
)
{
"1. one
\n
- sublist
\n
"
}
it
'renders correctly'
do
expect
(
page
).
to
have_xpath
(
"//ol//li//ul"
)
context
'when rendering default markdown'
do
it
'renders using CommonMark'
do
expect
(
page
).
to
have_content
(
"sublist"
)
expect
(
page
).
not_to
have_xpath
(
"//ol//li//ul"
)
end
end
end
context
'with cached CommonMark html'
do
let
(
:snippet
)
{
create
(
:personal_snippet
,
:public
,
file_name:
file_name
,
content:
content
,
cached_markdown_version:
CacheMarkdownField
::
CACHE_COMMONMARK_VERSION
)
}
let
(
:file_name
)
{
'test.md'
}
let
(
:content
)
{
"1. one
\n
- sublist
\n
"
}
context
'when rendering legacy markdown'
do
before
do
visit
snippet_path
(
snippet
,
legacy_render:
1
)
it
'renders correctly'
do
expect
(
page
).
not_to
have_xpath
(
"//ol//li//ul"
)
wait_for_requests
end
it
'renders using RedCarpet'
do
expect
(
page
).
to
have_content
(
"sublist"
)
expect
(
page
).
to
have_xpath
(
"//ol//li//ul"
)
end
end
context
'with cached CommonMark html'
do
let
(
:snippet
)
{
create
(
:personal_snippet
,
:public
,
file_name:
file_name
,
content:
content
,
cached_markdown_version:
CacheMarkdownField
::
CACHE_COMMONMARK_VERSION
)
}
it
'renders correctly'
do
expect
(
page
).
not_to
have_xpath
(
"//ol//li//ul"
)
end
end
context
'with cached Redcarpet html'
do
let
(
:snippet
)
{
create
(
:personal_snippet
,
:public
,
file_name:
file_name
,
content:
content
,
cached_markdown_version:
CacheMarkdownField
::
CACHE_REDCARPET_VERSION
)
}
it
'renders correctly'
do
expect
(
page
).
to
have_xpath
(
"//ol//li//ul"
)
end
end
end
...
...
spec/services/preview_markdown_service_spec.rb
浏览文件 @
a963721f
...
...
@@ -101,4 +101,11 @@ describe PreviewMarkdownService do
expect
(
result
[
:markdown_engine
]).
to
eq
:common_mark
end
it
'honors the legacy_render parameter'
do
service
=
described_class
.
new
(
project
,
user
,
{
legacy_render:
'1'
})
result
=
service
.
execute
expect
(
result
[
:markdown_engine
]).
to
eq
:redcarpet
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录