1.0.2 • Published 2 years ago

richtext-parse-to-unity-egret v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

richtext-parse-to-unity-egret

中文 | English

Introduction

richtext-parse-to-unity-egret is a library of tools for converting web rich text into formats supported by game engines (unity, egret). Simple compatibility with older rich text editors,Recommend using wangEditor open source rich text editor V4 or V5 version

Usage

  • browser

<script src="richtext-parse-to-unity-egret.js"></script>
<script>
  const { parseUnity, parseEgret } = window['richtext-parse-to-unity-egret']
</script>
  • node
$ npm i -g npm
$ npm i richtext-parse-to-unity-egret
// require of two methods
const { parseUnity, parseEgret } = require('richtext-parse-to-unity-egret');

/***
 * @description The following are used as unity example
 * @params htmlStr It's a web rich text field
 * @params setting{sizeMap} Configuration: Configuration font size conversion
 * */ 
const unityText = parseUnity(htmlStr: string, {
  sizeMap: {
    1: 32,
    2: 28,
    3: 26,
    4: 20,
    5: 16,
    6: 14,
    7: 12,
  }
})·

Format support (to be followed up...)

unityegret
Font size✔️✔️
Font color✔️✔️
Bold✔️✔️
Underline✔️
Italic✔️
Line spacing✔️
Left/Centre/Right✔️
Jump link(Jump to internal/jump to external)✔️✔️

Jump-Rule

web rich text formatting

<!-- Jump to internal <a name="#Jump code"> -->
<a name="#125,151|2003,197|200003,114" type="gameSystemLink">example</a>

<!-- Jump to external <a name="#Jump link"> -->
<a name="#www.baidu.com" type="gameSystemLink">example</a>

To unity format

// Jump to internal
<link=openSystem__@@__125,151|2003,197|200003,114>example</link>

// Jump to external
<link=openUrl__@@__www.baidu.com>example</link>

To egret format

//  Jump to internal
<a href='event:openURL_125,151|2003,197|200003,114'>example</a>

//  Jump to external
<a href='event:openURL_www.baidu.com'>example</a>

Related links