steem-content-renderer
TypeScript icon, indicating that this package has built-in type declarations

2.1.1 • Public • Published

steem-content-renderer

npm License PRs Welcome Chat

👉 Online demo

Portable library that renders steem posts and comments to string. It supports markdown and html and mimics the behaviour of condenser frontend.

Features:

  • supports markdown and html

  • sanitizes html and protects from XSS

Credit: this library is based on the code from condenser. It's aim is to allow other projects display steem content the right way without porting the same code over and over.

Server side usage

Installation:

$ npm install --save steem-content-renderer

Typescript:

import { DefaultRenderer } from "steem-content-renderer";
 
const renderer = new DefaultRenderer({
    baseUrl: "https://steemit.com/",
    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);

Browser usage:

See demo and its source.

        <script src="https://unpkg.com/steem-content-renderer"></script> 
        <script>
            const renderer = new SteemContentRenderer.DefaultRenderer({
                baseUrl: "https://steemit.com/",
                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>

Package Sidebar

Install

npm i steem-content-renderer

Weekly Downloads

24

Version

2.1.1

License

MIT

Unpacked Size

646 kB

Total Files

73

Last publish

Collaborators

  • jblew