@11ty/eleventy-plugin-rss @11ty/eleventy-plugin-syntaxhighlightupstream
@ -1,5 +0,0 @@ | |||
const { URL } = require("url"); | |||
module.exports = function(url, base) { | |||
return (new URL(url, base)).toString() | |||
}; |
@ -1,33 +0,0 @@ | |||
class HighlightLines { | |||
constructor(rangeStr) { | |||
this.highlights = this.convertRangeToHash(rangeStr); | |||
} | |||
convertRangeToHash(rangeStr) { | |||
let hash = {}; | |||
if( !rangeStr ) { | |||
return hash; | |||
} | |||
let ranges = rangeStr.split(",").map(function(range) { | |||
return range.trim(); | |||
}); | |||
for(let range of ranges) { | |||
let startFinish = range.split('-'); | |||
let start = parseInt(startFinish[0], 10); | |||
let end = parseInt(startFinish[1] || start, 10); | |||
for( let j = start, k = end; j<=k; j++ ) { | |||
hash[j] = true; | |||
} | |||
} | |||
return hash; | |||
} | |||
isHighlighted(lineNumber) { | |||
return !!this.highlights[lineNumber] | |||
} | |||
} | |||
module.exports = HighlightLines; |
@ -1,22 +0,0 @@ | |||
const posthtml = require('posthtml'); | |||
const urls = require('posthtml-urls') | |||
const absoluteUrl = require("./AbsoluteUrl"); | |||
module.exports = function(htmlContent, base) { | |||
let options = { | |||
eachURL: function(url, attr, element) { | |||
url = url.trim(); | |||
// #anchor in-page | |||
if( url.indexOf("#") === 0 ) { | |||
return url; | |||
} | |||
return absoluteUrl(url, base); | |||
} | |||
}; | |||
let modifier = posthtml().use(urls(options)); | |||
return modifier.process(htmlContent); | |||
}; |
@ -1,83 +0,0 @@ | |||
const HighlightLines = require('./HighlightLines'); | |||
class LiquidHighlight { | |||
constructor(liquidEngine) { | |||
this.liquidEngine = liquidEngine; | |||
this.hooks = []; | |||
this.classHooks = []; | |||
} | |||
addHook(hookFunction) { | |||
this.hooks.push(hookFunction); | |||
} | |||
addClassHook(hookFunction) { | |||
this.classHooks.push(hookFunction); | |||
} | |||
getObject() { | |||
let ret = function(highlighter) { | |||
return { | |||
parse: function(tagToken, remainTokens) { | |||
let split = tagToken.args.split(" "); | |||
this.language = split[0]; | |||
this.highlights = new HighlightLines(split.length === 2 ? split[1] : ""); | |||
this.highlightsAdd = new HighlightLines(split.length === 3 ? split[1] : ""); | |||
this.highlightsRemove = new HighlightLines(split.length === 3 ? split[2] : ""); | |||
this.tokens = []; | |||
var stream = highlighter.liquidEngine.parser.parseStream(remainTokens); | |||
stream | |||
.on('token', token => { | |||
if (token.name === 'endhighlight') { | |||
stream.stop(); | |||
} else { | |||
this.tokens.push(token); | |||
} | |||
}) | |||
.on('end', x => { | |||
throw new Error("tag highlight not closed"); | |||
}); | |||
stream.start(); | |||
}, | |||
render: function(scope, hash) { | |||
let tokens = this.tokens.map(token => token.raw); | |||
let tokenStr = tokens.join('').trim(); | |||
for( let hook of highlighter.hooks ) { | |||
tokenStr = hook.call(this, this.language, tokenStr); | |||
} | |||
let lines = tokenStr.split("\n").map(function(line, j) { | |||
let classHookClasses = []; | |||
for( let classHook of highlighter.classHooks ) { | |||
let ret = classHook(this.language, line, j); | |||
if( ret ) { | |||
classHookClasses.push(ret); | |||
} | |||
} | |||
return '<div class="highlight-line' + | |||
(this.highlights.isHighlighted(j) ? ' highlight-line-active' : '') + | |||
(this.highlightsAdd.isHighlighted(j) ? ' highlight-line-add' : '') + | |||
(this.highlightsRemove.isHighlighted(j) ? ' highlight-line-remove' : '') + | |||
(classHookClasses.length ? " " + classHookClasses.join(" ") : "") + | |||
'">' + | |||
line + | |||
'</div>'; | |||
}.bind(this)); | |||
return Promise.resolve(`<pre class="language-${this.language}"><code class="language-${this.language}">` + lines.join("") + "</code></pre>"); | |||
} | |||
}; | |||
}; | |||
return ret(this); | |||
} | |||
} | |||
module.exports = LiquidHighlight; |
@ -1,16 +0,0 @@ | |||
const LiquidHighlight = require( "./LiquidHighlight" ); | |||
module.exports = function(liquidEngine) { | |||
let highlight = new LiquidHighlight(liquidEngine); | |||
highlight.addClassHook(function(language, line) { | |||
if( language === "dir" ) { | |||
// has trailing slash | |||
if( line.match(/\/$/) !== null ) { | |||
return "highlight-line-isdir"; | |||
} | |||
} | |||
}); | |||
return highlight.getObject(); | |||
}; |
@ -1,12 +0,0 @@ | |||
const Prism = require('prismjs'); | |||
const LiquidHighlight = require( "./LiquidHighlight" ); | |||
module.exports = function(liquidEngine) { | |||
let highlight = new LiquidHighlight(liquidEngine); | |||
highlight.addHook(function(language, htmlStr, lines) { | |||
return Prism.highlight(htmlStr, Prism.languages[ language ]); | |||
}); | |||
return highlight.getObject(); | |||
}; |
@ -1,9 +0,0 @@ | |||
import test from "ava"; | |||
import htmlToAbsUrls from "../HtmlToAbsoluteUrls.js"; | |||
test("Changes a link href", async t => { | |||
t.is((await htmlToAbsUrls(`<a href="#testanchor">Hello</a>`, "http://example.com/")).html, `<a href="#testanchor">Hello</a>`); | |||
t.is((await htmlToAbsUrls(`<a href="/test.html">Hello</a>`, "http://example.com/")).html, `<a href="http://example.com/test.html">Hello</a>`); | |||
t.is((await htmlToAbsUrls(`<img src="/test.png">`, "http://example.com/")).html, `<img src="http://example.com/test.png">`); | |||
t.is((await htmlToAbsUrls(`<a href="http://someotherdomain/">Hello</a>`, "http://example.com/")).html, `<a href="http://someotherdomain/">Hello</a>`); | |||
}); |