我正在以.md格式为我的Github项目编写自述文件。有没有办法在提交到Github之前测试我的readme.md文件的外观呢?
我正在以.md格式为我的Github项目编写自述文件。有没有办法在提交到Github之前测试我的readme.md文件的外观呢?
Atom 可以轻松地执行操作 - 只需打开Markdown文件,按下Ctrl+Shift+M即可切换到旁边的Markdown预览面板。 它还支持处理HTML和图像。
atom .
并右键单击readme文件>Markdown预览
。 - austinVisual Studio Code提供编辑和预览md文件更改的选项。由于VS Code是平台独立的,因此可以在Windows、Mac和Linux上使用。
在编辑器中按Ctrl+Shift+V键可在视图之间切换。您可以将预览与正在编辑的文件并排显示(Ctrl+K V),并在编辑时实时查看反映更改。
另外...
问:VS Code是否支持GitHub Flavored Markdown?
答:不支持,VS Code使用markdown-it库针对CommonMark Markdown规范进行操作。GitHub正在向CommonMark规范转移。
我通常直接在 GitHub 网站上进行编辑,并单击编辑窗口上方的“预览”。
也许这是自此帖子发布以来新增的新功能。
xxx.md
,然后将您的代码粘贴到其中。
文件扩展名为.md
,因此您可以预览更改。
在完成更新之前,您将一直更新该文件,然后复制文件内容并将其粘贴到原始的readme.md
文件上。 - Mahmoud<div align='center'><img ...></div>
将图片居中对齐,预览时它不会居中显示,而是左对齐。你必须保存才能准确地看到它,这使得预览在我看来不可靠。 - AFOC这个链接已经被证实是相当可靠的:http://tmpvar.com/markdown.html
Mac: 命令 + Shift + V
Windows: Ctrl + Shift + V
在 VS Code 中打开 .md
文件,选择文件后使用上述键盘快捷键。
.../github/
repo-a/
README.md
repo-b/
README.md
etc.
GitHub目录包含“预览”HTML文件:
.../github/
readme.html
http://localhost/github/readme.html?repo-a
或者,您可以将readme.html复制到与README.md相同的目录中,并省略查询字符串:
http://localhost/github/repo-a/readme.html
<!DOCTYPE html>
<!--
Preview a GitHub README.md.
Either:
- Copy this file to a directory that contains repo directories,
and then specify a repo name in the query string.
For example:
http://localhost/github/readme.html?myrepo
or
- Copy this file to the directory that contains a README.md,
and then browse to this file without specifying a query string.
For example:
http://localhost/github/myrepo/readme.html
(or just open this file in your browser directly from
your file system, without HTTP)
-->
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
<meta name="author" content="Graham Hannington"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>GitHub readme preview</title>
<link rel="stylesheet" type="text/css" href="http://primercss.io/docs.css"/>
<script type="text/javascript">
//<![CDATA[
var HTTP_STATUS_OK = 200;
var URL_API_GITHUB_RENDER_MARKDOWN = "https://api.github.com/markdown/raw";
var README_FILE_NAME = "README.md";
var readmeURL;
var queryString = location.search.substring(1);
if (queryString.length > 0) {
readmeURL = queryString + "/" + README_FILE_NAME;
} else {
readmeURL = README_FILE_NAME;
}
// Get Markdown, then render it as HTML
function getThenRenderMarkdown(markdownURL) {
var xhr = new XMLHttpRequest();
xhr.open("GET", markdownURL, true);
xhr.responseType = "text";
xhr.onload = function(e) {
if (this.status == HTTP_STATUS_OK) {
// Response text contains Markdown
renderMarkdown(this.responseText);
}
}
xhr.send();
}
// Use the GitHub API to render Markdown as HTML
function renderMarkdown(markdown) {
var xhr = new XMLHttpRequest();
xhr.open("POST", URL_API_GITHUB_RENDER_MARKDOWN, true);
xhr.responseType = "html";
xhr.onload = function(e) {
if (this.status == HTTP_STATUS_OK) {
document.getElementById("readme").innerHTML = this.response;
}
}
xhr.send(markdown);
}
window.onload = function() {
getThenRenderMarkdown(readmeURL);
}
//]]>
</script>
</head>
<body>
<header class="masthead">
<div class="container">
<span class="masthead-logo"><span class="mega-octicon
octicon-mark-github"></span>GitHub readme preview</span>
</div>
</header>
<div class="container">
<div id="readme" class="markdown-body">
<p>Rendering markdown, please wait...</p>
</div>
<footer class="footer">Rendering by
<a href="https://developer.github.com/v3/markdown/">GitHub</a>,
styling by <a href="http://primercss.io/">Primer</a>.</footer>
</div>
</body>
</html>
我保留了这个原始版本的记录,以供好奇心参考。 这个版本存在以下问题,在当前版本中得到解决:
github目录包含“预览”HTML文件和相关文件:
.../github/
readme-preview.html
github.css
github2.css
octicons.eot
octicons.svg
octicons.woff
我从GitHub下载了CSS和Octicons字体文件:
https://assets-cdn.github.com/assets/github- ... .css
https://assets-cdn.github.com/assets/github2- ... .css
https://github.com/static/fonts/octicons/octicons.* (eot, woff, svg)
<link rel="stylesheet" type="text/css"
href="http://rawgit.com/sindresorhus/github-markdown-css/gh-pages/github-markdown.css">
但最终决定使用GitHub本身的CSS。
这是HTML文件(readme-preview.html):
<!DOCTYPE html>
<!-- Preview a GitHub README.md.
Copy this file to a directory that contains repo directories.
Specify a repo name in the query string. For example:
http://localhost/github/readme-preview.html?myrepo
-->
<html>
<head>
<title>Preview GitHub readme</title>
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<!-- Downloaded copies of the CSS files served by GitHub.
In github.css, the @font-face for font-family:'octicons'
has been edited to refer to local copies of the font files -->
<link rel="stylesheet" type="text/css" href="github.css"/>
<link rel="stylesheet" type="text/css" href="github2.css"/>
<style>
body {
margin-top: 1em;
}
</style>
<script type="text/javascript">
//<![CDATA[
var HTTP_STATUS_OK = 200;
var URL_API_GITHUB_RENDER_MARKDOWN = "https://api.github.com/markdown/raw";
var README_FILE_NAME = "README.md";
var repo = location.search.substring(1);
// Get Markdown, then render it as HTML
function getThenRenderMarkdown() {
var xhr = new XMLHttpRequest();
xhr.open("GET", repo + "/" + README_FILE_NAME, true);
xhr.responseType = "text";
xhr.onload = function(e) {
if (this.status == HTTP_STATUS_OK) {
// Response text contains Markdown
renderMarkdown(this.responseText);
}
}
xhr.send();
}
// Use the GitHub API to render Markdown as HTML
function renderMarkdown(markdown) {
var xhr = new XMLHttpRequest();
xhr.open("POST", URL_API_GITHUB_RENDER_MARKDOWN, true);
xhr.responseType = "html";
xhr.onload = function(e) {
if (this.status == HTTP_STATUS_OK) {
document.getElementById("readme-content").innerHTML = this.response;
}
}
xhr.send(markdown);
}
window.onload = getThenRenderMarkdown;
//]]>
</script>
</head>
<body>
<!-- The following HTML structure was copied from live GitHub page on 2015-12-01,
except for the "readme-content" id of the article element,
which was coined for this preview page.-->
<div class="main-content" role="main">
<div class="container repo-container new-discussion-timeline experiment-repo-nav">
<div class="repository-content">
<div id="readme" class="boxed-group flush clearfix announce instapaper_body md">
<h3><span class="octicon octicon-book"></span>README.md</h3>
<article class="markdown-body entry-content"
itemprop="mainContentOfPage"
id="readme-content"><p>Rendering markdown...</p></article>
</div>
</div>
</div>
</div>
</body>
</html>
README.md
)之前查看其外观。请参见下面的答案。 - VonCREADME.md
而不是README.rst
。 - DanielBell99