Initial commit

This commit is contained in:
Josh Bruce 2017-12-01 11:17:22 -05:00
parent 8f9d0b72f5
commit e5b2998326
6 changed files with 2286 additions and 5 deletions

View File

@ -1,6 +1,5 @@
{
"name": "marked",
"version": "0.3.4",
"homepage": "https://github.com/chjj/marked",
"authors": [
"Christopher Jeffrey <chjjeffrey@gmail.com>"

View File

@ -457,7 +457,7 @@ var inline = {
nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
code: /^(`+)([\s\S]*?[^`])\1(?!`)/,
br: /^ {2,}\n(?!\s*$)/,
del: noop,
text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
@ -661,7 +661,7 @@ InlineLexer.prototype.output = function(src) {
// code
if (cap = this.rules.code.exec(src)) {
src = src.substring(cap[0].length);
out += this.renderer.codespan(escape(cap[2], true));
out += this.renderer.codespan(escape(cap[2].trim(), true));
continue;
}
@ -879,6 +879,9 @@ Renderer.prototype.link = function(href, title, text) {
return '';
}
}
if (this.options.baseUrl && !originIndependentUrl.test(href)) {
href = resolveUrl(this.options.baseUrl, href);
}
var out = '<a href="' + href + '"';
if (title) {
out += ' title="' + title + '"';
@ -888,6 +891,9 @@ Renderer.prototype.link = function(href, title, text) {
};
Renderer.prototype.image = function(href, title, text) {
if (this.options.baseUrl && !originIndependentUrl.test(href)) {
href = resolveUrl(this.options.baseUrl, href);
}
var out = '<img src="' + href + '" alt="' + text + '"';
if (title) {
out += ' title="' + title + '"';
@ -1119,6 +1125,30 @@ function replace(regex, opt) {
};
}
function resolveUrl(base, href) {
if (!baseUrls[' ' + base]) {
// we can ignore everything in base after the last slash of its path component,
// but we might need to add _that_
// https://tools.ietf.org/html/rfc3986#section-3
if (/^[^:]+:\/*[^/]*$/.test(base)) {
baseUrls[' ' + base] = base + '/';
} else {
baseUrls[' ' + base] = base.replace(/[^/]*$/, '');
}
}
base = baseUrls[' ' + base];
if (href.slice(0, 2) === '//') {
return base.replace(/:[^]*/, ':') + href;
} else if (href.charAt(0) === '/') {
return base.replace(/(:\/*[^/]*)[^]*/, '$1') + href;
} else {
return base + href;
}
}
baseUrls = {};
originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
function noop() {}
noop.exec = noop;
@ -1253,7 +1283,8 @@ marked.defaults = {
smartypants: false,
headerPrefix: '',
renderer: new Renderer,
xhtml: false
xhtml: false,
baseUrl: null
};
/**

2
marked.min.js vendored

File diff suppressed because one or more lines are too long

2189
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,35 @@
<h1 id="absolutization-of-rfc-3986-uris">Absolutization of RFC 3986 URIs</h1>
<h2 id="absolute-uri">Absolute URI</h2>
<p><a href="http://example.com/"><img src="http://example.com/logo" alt="section 4.3"></a></p>
<h2 id="network-path-reference">Network-path reference</h2>
<p><a href="http://example.com/"><img src="http://example.com/logo" alt="section 4.2"></a></p>
<h2 id="absolute-path">Absolute path</h2>
<p><a href="http://example.com/path/to/content"><img src="http://example.com/path/to/img" alt="section 4.2"></a></p>
<h2 id="relative-path">Relative path</h2>
<p><a href="http://example.com/base/content"><img src="http://example.com/base/img" alt="section 4.2"></a></p>
<h2 id="dot-relative-path">Dot-relative path</h2>
<p><a href="http://example.com/base/./content"><img src="http://example.com/base/./img" alt="section 3.3"></a></p>
<p><a href="http://example.com/base/../content"><img src="http://example.com/base/../img" alt="section 3.3"></a></p>
<h2 id="same-document-query">Same-document query</h2>
<p><a href="?"><img src="?type=image" alt="section 4.4"></a></p>
<h2 id="same-document-fragment">Same-document fragment</h2>
<p><a href="#"><img src="#img" alt="section 4.4"></a></p>
<h2 id="empty">Empty</h2>
<p><a href="">section 4.2</a></p>

View File

@ -0,0 +1,27 @@
# Absolutization of RFC 3986 URIs
## Absolute URI
[![section 4.3](http://example.com/logo)](http://example.com/)
## Network-path reference
[![section 4.2](//example.com/logo)](//example.com/)
## Absolute path
[![section 4.2](/path/to/img)](/path/to/content)
## Relative path
[![section 4.2](img)](content)
## Dot-relative path
[![section 3.3](./img)](./content)
[![section 3.3](../img)](../content)
## Same-document query
[![section 4.4](?type=image)](?)
## Same-document fragment
[![section 4.4](#img)](#)
## Empty
[section 4.2]()