项目作者: writers-mark

项目描述 :
Typescript implementation of core Writer's Mark features.
高级语言: TypeScript
项目地址: git://github.com/writers-mark/writers-mark-ts.git
创建时间: 2020-11-21T14:59:00Z
项目社区:https://github.com/writers-mark/writers-mark-ts

开源协议:ISC License

下载


Writer’s Mark

npm
install size
github actions
Known Vulnerabilities
codecov.io

Core functionalities for Writer’s Mark.

Getting started

Installation

  1. npm install writers-mark

Usage

  1. import {Context} from 'writers-mark';
  2. const ctx = new Context();
  3. // Compile a style.
  4. const style = ctx.compileStyle(styleString);
  5. // Compile a text.
  6. const text = ctx.compileText(contextString, [style]);
  7. // Style and texts are dumb data objects, so they can be serialized.
  8. const styleStr = JSON.stringify(style);
  9. const textStr = JSON.stringify(text);
  10. // ... and deserialized
  11. const recoveredStyle = JSON.parse(styleStr);
  12. const recoveredText = JSON.parse(textStr);
  13. // Deserialized content can be validated.
  14. if(context.isStyleValid(recoveredStyle) && context.isTextValid(recoveredText)) {
  15. // Do something with it
  16. }

Rendering the text as HTML/CSS is not within the scope of this module, please see writers-mark-dom or writers-mark-react for that.

CSS Whitelist

While the library has sane defaults for allowed CSS properties, you are free to override the whitelist.

  1. const ctx = new Context({
  2. para: ['text-align', 'margin', 'margin-left'],
  3. span: ['font-weight'],
  4. cont: [],
  5. });

Safety

The library’s default CSS properties preclude anything that could lead to javascript and/or downloading resources. On top of that, values or keys including semicolons, the sequence url(, or any escape sequence are ignored.

However, This specific library does NOT perform any html escaping by itself. This is delegated to the rendering process.