angular html5 编辑器,angular-html5

Change your ng-attributes to data-ng-attributes for html5 validation

angular-html5

Change your ng-attributes to data-ng-attributes for HTML5 validation

angular-html5.svg?style=flat

angular-html5.svg?style=flat

angular-html5.svg?style=flat

Ever tried to run an Angular HTML page into w3c validator? Yeah it's a mess.

HTML5 has a preset definition of valid tag elements, and also allows data-attributes.

Angular, being as great as it is, allows you set set custom directives, that don't pass the

w3c validations. Angular default directives come with an option to be named data-something.

If you are like me, it isn't fun using data-ng-include or data-ng-switch and prefer to use the shorter

versions. Using this module, you can easily convert the HTML attributes of Angular (and custom prefixes you want) to

valid HTML5 tags that start with data-something.

Turn this:

...

Into this:

...

HTML5_Logo_256.png

angular-html5 looks for ng- directives by default and can handle the following cases:

You can add additional prefixes using the option customPrefixes.

This plugin plays nice with type="text/ng-template" and won't break it.

Install

Global

$ npm install --global angular-html5

Usage

❯ angular-html5 --help

Usage: angular-html5 [options]

Options:

-h, --help output usage information

-V, --version output the version number

-c, --custom-prefix [prefixes] Optionally add custom prefixes to the list of converted directives.

Examples:

$ angular-html5 index.js

$ angular-html5 --custom-prefix ui --custom-prefix gijo index.js > ./dist/index.js

$ cat index.js | angular-html5 > ./dist/index.js

Programmatic

Install with npm

$ npm install --save-dev angular-html5

Usage

var htmlify = require('angular-html5')();

var str = fs.readFileSync('angular.html', 'utf8');

// test if contents need replacing (testing is quick, replacing is slower)

var needsReplace = htmlify.test(str);

if (needsReplace) {

// get the transformed html string with data- attributes

str = htmlify.replace(str);

}

Usage in build tools

API

var htmlify = require('angular-html5')(params);

API Methods

.test(str)

Test whether a string containing HTML has ng-attributes that can be transformed

to data-ng-attributes.

Usage: htmlify.test(str)

Accepts: string

Returns: Boolean

.replace(str)

Return a transformed string that contains data-ng-attributes or relevant transformed attributes

for customPrefixes.

Usage: htmlify.replace(str)

Accepts: string

Returns: string

API Params

params is an object that contains the following settings:

customPrefixes

Type: Array

Default: [ ]

An array to optionally add custom prefixes to the list of converted directives.

For example: ['ui-', 'gijo-']

By default only ng- prefixes are are handled. Any items you add here will be handled as well.

Note: for this to work - you will need to make sure your directives can load with a data- prefix.

Example Usage:

var str = require('angular-html5')({customPrefixes: ['ui-']}).replace(oldStr);

License

Repository

pgilad/angular-html5

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值