├── .gitignore
├── .npmignore
├── .nvmrc
├── .prettierrc.yml
├── .travis.yml
├── LICENSE
├── README.md
├── _dev
└── steem-content-renderer.code-workspace
├── browser-test
├── browser-test.js
└── index.html
├── package-lock.json
├── package.json
├── sample
├── demo-lib.js
├── demo-local.js
└── live-demo.html
├── src
├── Log.ts
├── RendererError.ts
├── index.ts
├── renderers
│ └── default
│ │ ├── DefaultRenderer.spec.test.ts
│ │ ├── DefaultRenderer.ts
│ │ ├── DefaultRendererLocalization.ts
│ │ ├── StaticConfig.ts
│ │ ├── _test
│ │ └── example1.mock.test.ts
│ │ ├── embedder
│ │ ├── AssetEmbedder.ts
│ │ ├── AssetEmbedderOptions.ts
│ │ ├── HtmlDOMParser.spec.test.ts
│ │ ├── HtmlDOMParser.ts
│ │ ├── utils
│ │ │ ├── AccountNameValidator.ts
│ │ │ ├── BadActorList.ts
│ │ │ └── Links.ts
│ │ └── videoembedders
│ │ │ ├── AbstractVideoEmbedder.ts
│ │ │ ├── TwitchEmbedder.ts
│ │ │ ├── VideoEmbedders.ts
│ │ │ ├── VimeoEmbedder.ts
│ │ │ └── YoutubeEmbedder.ts
│ │ └── sanitization
│ │ ├── PreliminarySanitizer.ts
│ │ └── TagTransformingSanitizer.ts
└── security
│ ├── LinkSanitizer.spec.test.ts
│ ├── LinkSanitizer.ts
│ ├── Phishing.ts
│ ├── SecurityChecker.spec.test.ts
│ └── SecurityChecker.ts
├── tsconfig.json
├── tsconfig.lint.json
├── tslint.json
└── webpack.config.js
/.gitignore:
--------------------------------------------------------------------------------
1 | /dist
2 | /.DS_Store
3 |
4 | # Logs
5 | logs
6 | *.log
7 | npm-debug.log*
8 | yarn-debug.log*
9 | yarn-error.log*
10 |
11 | # Runtime data
12 | pids
13 | *.pid
14 | *.seed
15 | *.pid.lock
16 |
17 | # Directory for instrumented libs generated by jscoverage/JSCover
18 | lib-cov
19 |
20 | # Coverage directory used by tools like istanbul
21 | coverage
22 |
23 | # nyc test coverage
24 | .nyc_output
25 |
26 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
27 | .grunt
28 |
29 | # Bower dependency directory (https://bower.io/)
30 | bower_components
31 |
32 | # node-waf configuration
33 | .lock-wscript
34 |
35 | # Compiled binary addons (https://nodejs.org/api/addons.html)
36 | build/Release
37 |
38 | # Dependency directories
39 | node_modules/
40 | jspm_packages/
41 |
42 | # TypeScript v1 declaration files
43 | typings/
44 |
45 | # Optional npm cache directory
46 | .npm
47 |
48 | # Optional eslint cache
49 | .eslintcache
50 |
51 | # Optional REPL history
52 | .node_repl_history
53 |
54 | # Output of 'npm pack'
55 | *.tgz
56 |
57 | # Yarn Integrity file
58 | .yarn-integrity
59 |
60 | # dotenv environment variables file
61 | .env
62 |
63 | # next.js build output
64 | .next
65 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | /_dev
2 | /.travis.yml
3 | /.prettierrc.yml
4 | /TODO
5 | /README.md
6 | /LICENSE
7 | /src
8 | /.DS_Store
9 | /sample
10 | /tslint.json
11 | /tsconfig.lint.json
12 | *.test.ts
13 | /dist/browser/statistics.html
--------------------------------------------------------------------------------
/.nvmrc:
--------------------------------------------------------------------------------
1 | v10
--------------------------------------------------------------------------------
/.prettierrc.yml:
--------------------------------------------------------------------------------
1 | trailingComma: all
2 | tabWidth: 4
3 | semi: true
4 | printWidth: 120
5 | singleQuote: false
6 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | dist: xenial
2 | language: node_js
3 |
4 | branches:
5 | except:
6 | - /^v[0-9]/
7 |
8 | before_install:
9 | - npm i -g npm
10 |
11 | install:
12 | - npm ci
13 |
14 | script:
15 | - NODE_ENV=production npm run build
16 | - npm run test
17 | - node sample/demo-local.js
18 | # Test installation:
19 | - (mkdir ~/libtest && cp ./sample/demo-lib.js ~/libtest/demo-lib.js && cd ~/libtest && npm install $TRAVIS_BUILD_DIR && node demo-lib.js)
20 |
21 | deploy:
22 | - provider: script
23 | script: npm run semantic-release
24 | skip_cleanup: true
25 | on:
26 | tags: false
27 | all_branches: true
28 |
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Wise Team
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # steem-content-renderer
2 |
3 | [](https://www.npmjs.com/package/steem-content-renderer) [](https://github.com/wise-team/steem-content-renderer/blob/master/LICENSE) [](http://makeapullrequest.com) [](https://discordapp.com/invite/CwxQDbG)
4 |
5 | 👉 **[Online demo](https://wise-team.github.io/steem-content-renderer/sample/live-demo.html)**
6 |
7 | Portable library that renders steem posts and comments to string. It supports markdown and html and mimics the behaviour of condenser frontend.
8 |
9 | Features:
10 |
11 | - supports markdown and html
12 |
13 | - sanitizes html and protects from XSS
14 |
15 | **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.
16 |
17 | ## Server side usage
18 |
19 | Installation:
20 |
21 | ```bash
22 | $ npm install --save steem-content-renderer
23 | ```
24 |
25 | **Typescript:**
26 |
27 | ```typescript
28 | import { DefaultRenderer } from "steem-content-renderer";
29 |
30 | const renderer = new DefaultRenderer({
31 | baseUrl: "https://steemit.com/",
32 | breaks: true,
33 | skipSanitization: false,
34 | allowInsecureScriptTags: false,
35 | addNofollowToLinks: true,
36 | doNotShowImages: false,
37 | ipfsPrefix: "",
38 | assetsWidth: 640,
39 | assetsHeight: 480,
40 | imageProxyFn: (url: string) => url,
41 | usertagUrlFn: (account: string) => "/@" + account,
42 | hashtagUrlFn: (hashtag: string) => "/trending/" + hashtag,
43 | isLinkSafeFn: (url: string) => true,
44 | });
45 |
46 | const safeHtmlStr = renderer.render(postContent);
47 | ```
48 |
49 | ## Browser usage:
50 |
51 | See [demo](https://wise-team.github.io/steem-content-renderer/sample/live-demo.html) and [its source](https://github.com/wise-team/steem-content-renderer/blob/master/sample/live-demo.html).
52 |
53 | ```html
54 |
55 |
88 |