Gur*_*ofu 6 markdown github npm
假设我们的 GitHub 存储库包含以下 2 个 Markdown 文件:
从README.md中,我们可以通过相对路径或缩短的绝对路径引用SampleDocumentationPage :
See [sample documentation page](Documentation/SampleDocumentationPage.md)
Run Code Online (Sandbox Code Playgroud)
如果我们将包发布到 NPM,README.md将显示在包的主页上,其 URL 如下。
https://www.npmjs.com/package/$SCOPE_NAME$/$PACKAGE_ID$
Run Code Online (Sandbox Code Playgroud)
README.md中的SampleDocumentationPage.md链接是否有效?我想不是,因为SampleDocumentationPage.md的正确绝对路径是
https://github.com/$USER_NAME$/$REPOSITORY_NAME$/blob/master/Documentation/SampleDocumentationPage.md
Run Code Online (Sandbox Code Playgroud)
而相对于npm,SampleDocumentationPage.md的计算 URL为
https://www.npmjs.com/package/$SCOPE_NAME$/$PACKAGE_ID$/Documentation/SampleDocumentationPage.md
Run Code Online (Sandbox Code Playgroud)
除了仅使用绝对路径之外,还有什么可以做的吗?Markdown 中的绝对路径可能很长,如下所示:
<dl>
<dt><a href="https://github.com/TokugawaTakeshi/Yamato-Daiwa-ES-Extensions/blob/master/CoreLibrary/Package/Documentation/Arrays/getArrayElementSatisfiesThePredicateIfSuchElementIsExactlyOne/getArrayElementSatisfiesThePredicateIfSuchElementIsExactlyOne.md">getArrayElementSatisfiesThePredicateIfSuchElementIsExactlyOne</a></dt>
<dd>Returns the element of specified array matching with the predicate if such element is exactly one, otherwise error will be thrown or null will be returned (depending on dedicated option's value).</dd>
<dt><a href="https://github.com/TokugawaTakeshi/Yamato-Daiwa-ES-Extensions/blob/master/CoreLibrary/Package/Documentation/Arrays/getLastElementOfNonEmptyArray/getLastElementOfNonEmptyArray.md">getLastElementOfNonEmptyArray</a></dt>
<dd>Returns the last element of array, herewith <b>UnexpectedEventError</b> will be thrown if target array is empty.</dd>
</dl>
Run Code Online (Sandbox Code Playgroud)
简单的答案是否定的,您不受绝对链接的限制!我不确定它在什么时候发生,但我相信 NPM 会将您的相对链接重写为存储库的绝对链接,如果存储库信息在package.json.
我制作了一个示例包,以便您可以看到它的实际效果: