Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
7c3aeb10
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
7c3aeb10
编写于
8月 20, 2019
作者:
M
Matt Bierner
提交者:
GitHub
8月 20, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #77151 from connor4312/feat/markdown-render-command
feat(markdown): add render command (fixes #75612)
上级
1429e818
3c42f565
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
81 addition
and
9 deletion
+81
-9
extensions/markdown-language-features/package.json
extensions/markdown-language-features/package.json
+2
-1
extensions/markdown-language-features/src/commands/index.ts
extensions/markdown-language-features/src/commands/index.ts
+1
-0
extensions/markdown-language-features/src/commands/renderDocument.ts
...markdown-language-features/src/commands/renderDocument.ts
+30
-0
extensions/markdown-language-features/src/extension.ts
extensions/markdown-language-features/src/extension.ts
+1
-0
extensions/markdown-language-features/src/markdownEngine.ts
extensions/markdown-language-features/src/markdownEngine.ts
+15
-8
extensions/markdown-language-features/src/test/engine.test.ts
...nsions/markdown-language-features/src/test/engine.test.ts
+32
-0
未找到文件。
extensions/markdown-language-features/package.json
浏览文件 @
7c3aeb10
...
...
@@ -24,6 +24,7 @@
"onCommand:markdown.showLockedPreviewToSide"
,
"onCommand:markdown.showSource"
,
"onCommand:markdown.showPreviewSecuritySelector"
,
"onCommand:markdown.render"
,
"onWebviewPanel:markdown.preview"
],
"contributes"
:
{
...
...
@@ -328,4 +329,4 @@
"webpack"
:
"^4.1.0"
,
"webpack-cli"
:
"^2.0.10"
}
}
\ No newline at end of file
}
extensions/markdown-language-features/src/commands/index.ts
浏览文件 @
7c3aeb10
...
...
@@ -10,3 +10,4 @@ export { RefreshPreviewCommand } from './refreshPreview';
export
{
ShowPreviewSecuritySelectorCommand
}
from
'
./showPreviewSecuritySelector
'
;
export
{
MoveCursorToPositionCommand
}
from
'
./moveCursorToPosition
'
;
export
{
ToggleLockCommand
}
from
'
./toggleLock
'
;
export
{
RenderDocument
}
from
'
./renderDocument
'
;
extensions/markdown-language-features/src/commands/renderDocument.ts
0 → 100644
浏览文件 @
7c3aeb10
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
*
as
vscode
from
'
vscode
'
;
import
{
Command
}
from
'
../commandManager
'
;
import
{
MarkdownEngine
}
from
'
../markdownEngine
'
;
import
{
SkinnyTextDocument
}
from
'
../tableOfContentsProvider
'
;
export
class
RenderDocument
implements
Command
{
public
readonly
id
=
'
markdown.render
'
;
public
constructor
(
private
readonly
engine
:
MarkdownEngine
)
{
}
public
async
execute
(
document
?:
SkinnyTextDocument
|
string
):
Promise
<
string
|
undefined
>
{
if
(
!
document
)
{
if
(
!
vscode
.
window
.
activeTextEditor
)
{
return
;
}
document
=
vscode
.
window
.
activeTextEditor
.
document
;
}
return
this
.
engine
.
render
(
document
);
}
}
extensions/markdown-language-features/src/extension.ts
浏览文件 @
7c3aeb10
...
...
@@ -83,6 +83,7 @@ function registerMarkdownCommands(
commandManager
.
register
(
new
commands
.
ShowPreviewSecuritySelectorCommand
(
previewSecuritySelector
,
previewManager
));
commandManager
.
register
(
new
commands
.
OpenDocumentLinkCommand
(
engine
));
commandManager
.
register
(
new
commands
.
ToggleLockCommand
(
previewManager
));
commandManager
.
register
(
new
commands
.
RenderDocument
(
engine
));
return
commandManager
;
}
extensions/markdown-language-features/src/markdownEngine.ts
浏览文件 @
7c3aeb10
...
...
@@ -118,7 +118,7 @@ export class MarkdownEngine {
return
md
;
}
private
tokenize
(
private
tokenize
Document
(
document
:
SkinnyTextDocument
,
config
:
MarkdownItConfig
,
engine
:
MarkdownIt
...
...
@@ -131,16 +131,23 @@ export class MarkdownEngine {
this
.
currentDocument
=
document
.
uri
;
this
.
_slugCount
=
new
Map
<
string
,
number
>
();
const
text
=
document
.
getText
();
const
tokens
=
engine
.
parse
(
text
.
replace
(
UNICODE_NEWLINE_REGEX
,
''
),
{});
const
tokens
=
this
.
tokenizeString
(
document
.
getText
(),
engine
);
this
.
_tokenCache
.
update
(
document
,
config
,
tokens
);
return
tokens
;
}
public
async
render
(
document
:
SkinnyTextDocument
):
Promise
<
string
>
{
const
config
=
this
.
getConfig
(
document
.
uri
);
private
tokenizeString
(
text
:
string
,
engine
:
MarkdownIt
)
{
return
engine
.
parse
(
text
.
replace
(
UNICODE_NEWLINE_REGEX
,
''
),
{});
}
public
async
render
(
document
:
SkinnyTextDocument
|
string
):
Promise
<
string
>
{
const
config
=
this
.
getConfig
(
typeof
document
===
'
string
'
?
undefined
:
document
.
uri
);
const
engine
=
await
this
.
getEngine
(
config
);
return
engine
.
renderer
.
render
(
this
.
tokenize
(
document
,
config
,
engine
),
{
const
tokens
=
typeof
document
===
'
string
'
?
this
.
tokenizeString
(
document
,
engine
)
:
this
.
tokenizeDocument
(
document
,
config
,
engine
);
return
engine
.
renderer
.
render
(
tokens
,
{
...(
engine
as
any
).
options
,
...
config
},
{});
...
...
@@ -149,14 +156,14 @@ export class MarkdownEngine {
public
async
parse
(
document
:
SkinnyTextDocument
):
Promise
<
Token
[]
>
{
const
config
=
this
.
getConfig
(
document
.
uri
);
const
engine
=
await
this
.
getEngine
(
config
);
return
this
.
tokenize
(
document
,
config
,
engine
);
return
this
.
tokenize
Document
(
document
,
config
,
engine
);
}
public
cleanCache
():
void
{
this
.
_tokenCache
.
clean
();
}
private
getConfig
(
resource
:
vscode
.
Uri
):
MarkdownItConfig
{
private
getConfig
(
resource
?
:
vscode
.
Uri
):
MarkdownItConfig
{
const
config
=
vscode
.
workspace
.
getConfiguration
(
'
markdown
'
,
resource
);
return
{
breaks
:
config
.
get
<
boolean
>
(
'
preview.breaks
'
,
false
),
...
...
extensions/markdown-language-features/src/test/engine.test.ts
0 → 100644
浏览文件 @
7c3aeb10
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
*
as
assert
from
'
assert
'
;
import
*
as
vscode
from
'
vscode
'
;
import
'
mocha
'
;
import
{
InMemoryDocument
}
from
'
./inMemoryDocument
'
;
import
{
createNewMarkdownEngine
}
from
'
./engine
'
;
const
testFileName
=
vscode
.
Uri
.
file
(
'
test.md
'
);
suite
(
'
markdown.engine
'
,
()
=>
{
suite
(
'
rendering
'
,
()
=>
{
const
input
=
'
# hello
\n\n
world!
'
;
const
output
=
'
<h1 id="hello" data-line="0" class="code-line">hello</h1>
\n
'
+
'
<p data-line="2" class="code-line">world!</p>
\n
'
;
test
(
'
Renders a document
'
,
async
()
=>
{
const
doc
=
new
InMemoryDocument
(
testFileName
,
input
);
const
engine
=
createNewMarkdownEngine
();
assert
.
strictEqual
(
await
engine
.
render
(
doc
),
output
);
});
test
(
'
Renders a string
'
,
async
()
=>
{
const
engine
=
createNewMarkdownEngine
();
assert
.
strictEqual
(
await
engine
.
render
(
input
),
output
);
});
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录