CAUTION: We don't suggest using this library in production without complete review of codes. You may compromise your website.
Installation:
$ npm install --save hive-content-renderer
Typescript:
import DefaultRenderer from 'hive-content-renderer'
const renderer = new DefaultRenderer({
baseUrl: 'https://hive.blog/',
breaks: true,
skipSanitization: false,
allowInsecureScriptTags: false,
addNofollowToLinks: true,
doNotShowImages: false,
ipfsPrefix: '',
assetsWidth: 640,
assetsHeight: 480,
imageProxyFn: (url: string) => url,
usertagUrlFn: (account: string) => '/@' + account,
hashtagUrlFn: (hashtag: string) => '/trending/' + hashtag,
isLinkSafeFn: (url: string) => true
})
const safeHtmlStr = renderer.render(postContent)
CDN: https://cdn.jsdelivr.net/npm/hive-content-renderer/dist/hive-content-renderer.min.js
<script src="https://cdn.jsdelivr.net/npm/hive-content-renderer/dist/hive-content-renderer.min.js"></script>
<script>
const renderer = new HiveContentRenderer({
baseUrl: "https://hive.blog/",
breaks: true,
skipSanitization: false,
allowInsecureScriptTags: false,
addNofollowToLinks: true,
doNotShowImages: false,
ipfsPrefix: "",
assetsWidth: 640,
assetsHeight: 480,
imageProxyFn: (url) => url,
usertagUrlFn: (account) => "/@" + account,
hashtagUrlFn: (hashtag) => "/trending/" + hashtag,
isLinkSafeFn: (url) => true,
});
$(document).ready(() => {
const renderMarkdownBtnElem = $("#render-button");
const inputElem = $("#input");
const outputElem = $("#output");
const outputMarkupElem = $("#output-markup");
renderMarkdownBtnElem.on("click", () => {
const input = inputElem.val();
const output = renderer.render(input);
console.log("Rendered", output);
outputElem.html(output);
outputMarkupElem.text(output);
});
});
</script>
</body>
</html>