html2js
v0.2.0
Published
simple html2js processer
Downloads
1,809
Readme
html2js
simple html2js processer, i use it solve requirejs text crossdomain
Useage
html2js(source[, options])
Options:
mode
: A string naming js code style. Optional. Possible values:undefined
(default): keep space and carriage of source htmlcompress
: strip the extra spaces or carriage at the beginnings and ends of the linesformat
: format js code as spec
wrap
: A string naming js code wrapper. Optional. Possible values:ignoreScriptTag
: boolean to ignore fix split the script tag when writing it with document write. Defaults tofalse
Example
npm run example
test.html:
<div id="i-am-a-id">
<div class="i-am-a-class">
i am test
</div>
</div>
test.html.js:
/**
* html2js(source, {
* mode: 'default'
* wrap: 'amd'
* })
*/
define(function () {return '<div id="i-am-a-id">\n <div class="i-am-a-class">\n i am test\n </div>\n</div>\n<script>\n var test = \'test\';\n alert(test);\n</'+'script>\n';});
/**
* html2js(source, {
* mode: 'default'
* wrap: 'commonjs'
* })
*/
module.exports = '<div id="i-am-a-id">\n <div class="i-am-a-class">\n i am test\n </div>\n</div>\n<script>\n var test = \'test\';\n alert(test);\n</'+'script>\n';
/**
* html2js(source, {
* mode: 'default'
* wrap: false
* })
*/
'<div id="i-am-a-id">\n <div class="i-am-a-class">\n i am test\n </div>\n</div>\n<script>\n var test = \'test\';\n alert(test);\n</'+'script>\n'
/**
* html2js(source, {
* mode: 'format'
* wrap: 'amd'
* })
*/
define(function () {
return ''
+ '<div id="i-am-a-id">'
+ '<div class="i-am-a-class">'
+ 'i am test'
+ '</div>'
+ '</div>'
+ '<script>'
+ 'var test = \'test\';'
+ 'alert(test);'
+ '</'+'script>'
+ '';
});
/**
* html2js(source, {
* mode: 'format'
* wrap: 'commonjs'
* })
*/
module.exports = ''
+ '<div id="i-am-a-id">'
+ '<div class="i-am-a-class">'
+ 'i am test'
+ '</div>'
+ '</div>'
+ '<script>'
+ 'var test = \'test\';'
+ 'alert(test);'
+ '</'+'script>'
+ '';
/**
* html2js(source, {
* mode: 'format'
* wrap: false
* })
*/
''
+ '<div id="i-am-a-id">'
+ '<div class="i-am-a-class">'
+ 'i am test'
+ '</div>'
+ '</div>'
+ '<script>'
+ 'var test = \'test\';'
+ 'alert(test);'
+ '</'+'script>'
+ ''
/**
* html2js(source, {
* mode: 'compress'
* wrap: 'amd'
* })
*/
define(function () {return '<div id="i-am-a-id"><div class="i-am-a-class">i am test</div></div><script>var test = \'test\';alert(test);</'+'script>';});
/**
* html2js(source, {
* mode: 'compress'
* wrap: 'commonjs'
* })
*/
module.exports = '<div id="i-am-a-id"><div class="i-am-a-class">i am test</div></div><script>var test = \'test\';alert(test);</'+'script>';
/**
* html2js(source, {
* mode: 'compress'
* wrap: false
* })
*/
'<div id="i-am-a-id"><div class="i-am-a-class">i am test</div></div><script>var test = \'test\';alert(test);</'+'script>'
Test
npm test