Skip to content
This repository has been archived by the owner on Jan 7, 2024. It is now read-only.

Content renderer for Hive posts and comments. Markdown + HTML

License

Notifications You must be signed in to change notification settings

mahdiyari/hive-content-renderer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hive-content-renderer

CAUTION: We don't suggest using this library in production without complete review of codes. You may compromise your website.

Server side usage

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)

Browser usage:

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>

About

Content renderer for Hive posts and comments. Markdown + HTML

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%