Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
47e4abf4
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
47e4abf4
编写于
3月 25, 2017
作者:
G
Guillaume Gomez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix plain_summary_line function
上级
cba67ad8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
51 addition
and
34 deletion
+51
-34
src/librustdoc/html/markdown.rs
src/librustdoc/html/markdown.rs
+51
-33
src/rustc/rustdoc.rs
src/rustc/rustdoc.rs
+0
-1
未找到文件。
src/librustdoc/html/markdown.rs
浏览文件 @
47e4abf4
...
...
@@ -106,11 +106,19 @@ fn collapse_whitespace(s: &str) -> String {
macro_rules!
event_loop_break
{
(
$parser:expr
,
$toc_builder:expr
,
$shorter:expr
,
$buf:expr
,
$
(
$end_event:pat
)|
*
)
=>
{{
event_loop_break
(
$parser
,
$toc_builder
,
$shorter
,
$buf
,
false
,
$
(
$end_event:pat
)|
*
);
}};
(
$parser:expr
,
$toc_builder:expr
,
$shorter:expr
,
$buf:expr
,
$escape:expr
,
$
(
$end_event:pat
)|
*
)
=>
{{
while
let
Some
(
event
)
=
$parser
.next
()
{
match
event
{
$
(
$end_event
)|
*
=>
break
,
Event
::
Text
(
ref
s
)
=>
{
$buf
.push_str
(
s
);
if
$escape
{
$buf
.push_str
(
&
escape
(
s
));
}
else
{
$buf
.push_str
(
s
);
}
}
Event
::
SoftBreak
|
Event
::
HardBreak
if
!
$buf
.is_empty
()
=>
{
$buf
.push
(
' '
);
...
...
@@ -127,6 +135,13 @@ pub fn render(w: &mut fmt::Formatter,
s
:
&
str
,
print_toc
:
bool
,
shorter
:
MarkdownOutputStyle
)
->
fmt
::
Result
{
fn
escape
(
entry
:
&
str
)
->
String
{
entry
.replace
(
"<"
,
"<"
)
.replace
(
"'"
,
"'"
)
.replace
(
">"
,
">"
)
.replace
(
"&"
,
"&"
)
}
fn
block
(
parser
:
&
mut
Parser
,
buffer
:
&
mut
String
,
lang
:
&
str
)
{
let
mut
origtext
=
String
::
new
();
while
let
Some
(
event
)
=
parser
.next
()
{
...
...
@@ -208,7 +223,7 @@ fn dont_escape(c: u8) -> bool {
fn
header
(
parser
:
&
mut
Parser
,
buffer
:
&
mut
String
,
toc_builder
:
&
mut
Option
<
TocBuilder
>
,
shorter
:
MarkdownOutputStyle
,
level
:
i32
)
{
let
mut
ret
=
String
::
new
();
event_loop_break!
(
parser
,
toc_builder
,
shorter
,
ret
,
Event
::
End
(
Tag
::
Header
(
_
)));
event_loop_break!
(
parser
,
toc_builder
,
shorter
,
ret
,
true
,
Event
::
End
(
Tag
::
Header
(
_
)));
ret
=
ret
.trim_right
()
.to_owned
();
let
id
=
ret
.clone
();
...
...
@@ -241,28 +256,28 @@ fn header(parser: &mut Parser, buffer: &mut String, toc_builder: &mut Option<Toc
fn
codespan
(
parser
:
&
mut
Parser
,
buffer
:
&
mut
String
,
toc_builder
:
&
mut
Option
<
TocBuilder
>
,
shorter
:
MarkdownOutputStyle
)
{
let
mut
content
=
String
::
new
();
event_loop_break!
(
parser
,
toc_builder
,
shorter
,
content
,
Event
::
End
(
Tag
::
Code
));
event_loop_break!
(
parser
,
toc_builder
,
shorter
,
content
,
true
,
Event
::
End
(
Tag
::
Code
));
buffer
.push_str
(
&
format!
(
"<code>{}</code>"
,
Escape
(
&
collapse_whitespace
(
content
.trim_right
()))));
}
fn
link
(
parser
:
&
mut
Parser
,
buffer
:
&
mut
String
,
toc_builder
:
&
mut
Option
<
TocBuilder
>
,
shorter
:
MarkdownOutputStyle
,
url
:
&
str
,
mut
title
:
String
)
{
event_loop_break!
(
parser
,
toc_builder
,
shorter
,
title
,
Event
::
End
(
Tag
::
Link
(
_
,
_
)));
event_loop_break!
(
parser
,
toc_builder
,
shorter
,
title
,
true
,
Event
::
End
(
Tag
::
Link
(
_
,
_
)));
buffer
.push_str
(
&
format!
(
"<a href=
\"
{}
\"
>{}</a>"
,
url
,
title
));
}
fn
paragraph
(
parser
:
&
mut
Parser
,
buffer
:
&
mut
String
,
toc_builder
:
&
mut
Option
<
TocBuilder
>
,
shorter
:
MarkdownOutputStyle
)
{
let
mut
content
=
String
::
new
();
event_loop_break!
(
parser
,
toc_builder
,
shorter
,
content
,
Event
::
End
(
Tag
::
Paragraph
));
event_loop_break!
(
parser
,
toc_builder
,
shorter
,
content
,
true
,
Event
::
End
(
Tag
::
Paragraph
));
buffer
.push_str
(
&
format!
(
"<p>{}</p>"
,
content
.trim_right
()));
}
fn
cell
(
parser
:
&
mut
Parser
,
buffer
:
&
mut
String
,
toc_builder
:
&
mut
Option
<
TocBuilder
>
,
shorter
:
MarkdownOutputStyle
)
{
let
mut
content
=
String
::
new
();
event_loop_break!
(
parser
,
toc_builder
,
shorter
,
content
,
event_loop_break!
(
parser
,
toc_builder
,
shorter
,
content
,
true
,
Event
::
End
(
Tag
::
TableHead
)
|
Event
::
End
(
Tag
::
Table
(
_
))
|
Event
::
End
(
Tag
::
TableRow
)
|
...
...
@@ -336,7 +351,7 @@ fn table(parser: &mut Parser, buffer: &mut String, toc_builder: &mut Option<TocB
fn
blockquote
(
parser
:
&
mut
Parser
,
buffer
:
&
mut
String
,
toc_builder
:
&
mut
Option
<
TocBuilder
>
,
shorter
:
MarkdownOutputStyle
)
{
let
mut
content
=
String
::
new
();
event_loop_break!
(
parser
,
toc_builder
,
shorter
,
content
,
Event
::
End
(
Tag
::
BlockQuote
));
event_loop_break!
(
parser
,
toc_builder
,
shorter
,
content
,
true
,
Event
::
End
(
Tag
::
BlockQuote
));
buffer
.push_str
(
&
format!
(
"<blockquote>{}</blockquote>"
,
content
.trim_right
()));
}
...
...
@@ -347,7 +362,7 @@ fn list_item(parser: &mut Parser, buffer: &mut String, toc_builder: &mut Option<
match
event
{
Event
::
End
(
Tag
::
Item
)
=>
break
,
Event
::
Text
(
ref
s
)
=>
{
content
.push_str
(
s
);
content
.push_str
(
&
escape
(
s
)
);
}
x
=>
{
looper
(
parser
,
&
mut
content
,
Some
(
x
),
toc_builder
,
shorter
);
...
...
@@ -377,14 +392,14 @@ fn list(parser: &mut Parser, buffer: &mut String, toc_builder: &mut Option<TocBu
fn
emphasis
(
parser
:
&
mut
Parser
,
buffer
:
&
mut
String
,
toc_builder
:
&
mut
Option
<
TocBuilder
>
,
shorter
:
MarkdownOutputStyle
)
{
let
mut
content
=
String
::
new
();
event_loop_break!
(
parser
,
toc_builder
,
shorter
,
content
,
Event
::
End
(
Tag
::
Emphasis
));
event_loop_break!
(
parser
,
toc_builder
,
shorter
,
content
,
true
,
Event
::
End
(
Tag
::
Emphasis
));
buffer
.push_str
(
&
format!
(
"<em>{}</em>"
,
content
));
}
fn
strong
(
parser
:
&
mut
Parser
,
buffer
:
&
mut
String
,
toc_builder
:
&
mut
Option
<
TocBuilder
>
,
shorter
:
MarkdownOutputStyle
)
{
let
mut
content
=
String
::
new
();
event_loop_break!
(
parser
,
toc_builder
,
shorter
,
content
,
Event
::
End
(
Tag
::
Strong
));
event_loop_break!
(
parser
,
toc_builder
,
shorter
,
content
,
true
,
Event
::
End
(
Tag
::
Strong
));
buffer
.push_str
(
&
format!
(
"<strong>{}</strong>"
,
content
));
}
...
...
@@ -644,9 +659,12 @@ fn next(&mut self) -> Option<String> {
Event
::
Start
(
Tag
::
Link
(
_
,
ref
t
))
if
!
self
.is_first
=>
{
(
Some
(
t
.as_ref
()
.to_owned
()),
1
)
}
Event
::
Start
(
Tag
::
Code
)
=>
(
Some
(
"`"
.to_owned
()),
1
),
Event
::
End
(
Tag
::
Code
)
=>
(
Some
(
"`"
.to_owned
()),
-
1
),
Event
::
Start
(
Tag
::
Header
(
_
))
=>
(
None
,
1
),
Event
::
Text
(
ref
s
)
if
self
.is_in
>
0
=>
(
Some
(
s
.as_ref
()
.to_owned
()),
0
),
Event
::
End
(
Tag
::
Link
(
_
,
ref
t
))
=>
(
Some
(
t
.as_ref
()
.to_owned
()),
-
1
),
Event
::
End
(
Tag
::
Paragraph
)
=>
(
None
,
-
1
),
Event
::
End
(
Tag
::
Paragraph
)
|
Event
::
End
(
Tag
::
Header
(
_
))
=>
(
None
,
-
1
),
_
=>
(
None
,
0
),
};
if
is_in
>
0
||
(
is_in
<
0
&&
self
.is_in
>
0
)
{
...
...
@@ -728,17 +746,17 @@ fn t(input: &str, expect: &str) {
reset_ids
(
true
);
}
t
(
"# Foo bar"
,
"
\n
<h1 id='foo-bar' class='section-header'
>
\
<a href=
'#foo-bar'
>Foo bar</a></h1>"
);
t
(
"## Foo-bar_baz qux"
,
"
\n
<h2 id='foo-bar_baz-qux' class=
\'
section-
\
header
'><a href='#foo-bar_baz-qux'
>Foo-bar_baz qux</a></h2>"
);
t
(
"# Foo bar"
,
"
<h1 id=
\"
foo-bar
\"
class=
\"
section-header
\"
>
\
<a href=
\"
#foo-bar
\"
>Foo bar</a></h1>"
);
t
(
"## Foo-bar_baz qux"
,
"
<h2 id=
\"
foo-bar_baz-qux
\"
class=
\"
section-
\
header
\"
><a href=
\"
#foo-bar_baz-qux
\"
>Foo-bar_baz qux</a></h2>"
);
t
(
"### **Foo** *bar* baz!?!& -_qux_-%"
,
"
\n
<h3 id='foo-bar-baz--_qux_-' class='section-header'
>
\
<a href=
'#foo-bar-baz--_qux_-'
><strong>Foo</strong>
\
"
<h3 id=
\"
foo-bar-baz--_qux_-
\"
class=
\"
section-header
\"
>
\
<a href=
\"
#foo-bar-baz--_qux_-
\"
><strong>Foo</strong>
\
<em>bar</em> baz!?!& -_qux_-%</a></h3>"
);
t
(
"####**Foo?** &
\\
*bar?!* _`baz`_ ❤ #qux"
,
"
\n
<h4 id='foo--bar--baz--qux' class='section-header'
>
\
<a href=
'#foo--bar--baz--qux'
><strong>Foo?</strong> & *bar?!*
\
"
<h4 id=
\"
foo--bar--baz--qux
\"
class=
\"
section-header
\"
>
\
<a href=
\"
#foo--bar--baz--qux
\"
><strong>Foo?</strong> & *bar?!*
\
<em><code>baz</code></em> ❤ #qux</a></h4>"
);
}
...
...
@@ -750,18 +768,18 @@ fn t(input: &str, expect: &str) {
}
let
test
=
||
{
t
(
"# Example"
,
"
\n
<h1 id='example' class='section-header'
>
\
<a href=
'#example'
>Example</a></h1>"
);
t
(
"# Panics"
,
"
\n
<h1 id='panics' class='section-header'
>
\
<a href=
'#panics'
>Panics</a></h1>"
);
t
(
"# Example"
,
"
\n
<h1 id='example-1' class='section-header'
>
\
<a href=
'#example-1'
>Example</a></h1>"
);
t
(
"# Main"
,
"
\n
<h1 id='main-1' class='section-header'
>
\
<a href=
'#main-1'
>Main</a></h1>"
);
t
(
"# Example"
,
"
\n
<h1 id='example-2' class='section-header'
>
\
<a href=
'#example-2'
>Example</a></h1>"
);
t
(
"# Panics"
,
"
\n
<h1 id='panics-1' class='section-header'
>
\
<a href=
'#panics-1'
>Panics</a></h1>"
);
t
(
"# Example"
,
"
<h1 id=
\"
example
\"
class=
\"
section-header
\"
>
\
<a href=
\"
#example
\"
>Example</a></h1>"
);
t
(
"# Panics"
,
"
<h1 id=
\"
panics
\"
class=
\"
section-header
\"
>
\
<a href=
\"
#panics
\"
>Panics</a></h1>"
);
t
(
"# Example"
,
"
<h1 id=
\"
example-1
\"
class=
\"
section-header
\"
>
\
<a href=
\"
#example-1
\"
>Example</a></h1>"
);
t
(
"# Main"
,
"
<h1 id=
\"
main-1
\"
class=
\"
section-header
\"
>
\
<a href=
\"
#main-1
\"
>Main</a></h1>"
);
t
(
"# Example"
,
"
<h1 id=
\"
example-2
\"
class=
\"
section-header
\"
>
\
<a href=
\"
#example-2
\"
>Example</a></h1>"
);
t
(
"# Panics"
,
"
<h1 id=
\"
panics-1
\"
class=
\"
section-header
\"
>
\
<a href=
\"
#panics-1
\"
>Panics</a></h1>"
);
};
test
();
reset_ids
(
true
);
...
...
@@ -789,7 +807,7 @@ fn t(input: &str, expect: &str) {
assert_eq!
(
output
,
expect
);
}
t
(
"`Struct<'a, T>`"
,
"<p><code>Struct<'a, T></code></p>
\n
"
);
t
(
"Struct<'a, T>"
,
"<p>Struct<'a, T></p>
\n
"
);
t
(
"`Struct<'a, T>`"
,
"<p><code>Struct<'a, T></code></p>"
);
t
(
"Struct<'a, T>"
,
"<p>Struct<'a, T></p>"
);
}
}
src/rustc/rustdoc.rs
浏览文件 @
47e4abf4
...
...
@@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(rustdoc)]
#![feature(rustc_private)]
extern
crate
rustdoc
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录