Coder Social home page Coder Social logo

waychan23 / html-to-js.js Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 2 KB

A JavaScript tool to convert HTML code (actually more) into JavaScript string, mostly to save the trivial work of manually conversion espacially when the string cross multiple lines.

JavaScript 100.00%

html-to-js.js's Introduction

***** html-to-js.js *****
Description:

This is merely a very basic string processing util used for converting HTML into Javascript code.
I developed this at the time i was learning how to build a single-page-application. One of the most straightforward functions of the tool is to convert HTML template code into Javascript code of concatenating strings across multiple lines.
There must be some bugs in this small script or more advanced implementation for this purpose. Please let me know if you get one :)

*************************
Example:
...
<body>
...
<textarea id="htmlArea"></textarea>
<textarea id="jsArea"></textarea>
<button onclick="convert()">Convert HTML into JS</button>
...
<script type="text/javascript" src="html-to-js.js"></script>
<script type="text/javascript">
 
 Html2Js.initModule({indentScale:2,lineSeparator:"\n"});
 
 function convert(){
  var htmlCode = document.getElementById("htmlArea").value;
  var jsCode = Html2Js.fromHtmlToJs(htmlCode);
  document.getElementById("jsArea").value = jsCode;
 }

</script>
...
</body>
...
*************************
API:

1. Html2Js : Global Module Object
 * methods:
  1) initModule
    - @param props:Object the map of settings for initialization, here are the available settings:
	props = {
	  indentScale:<Integer>, //the scale factor for indent(whitespace), optional, default 1
	  lineSeparator:<String>, //the line separator for processing the input string, optional, default "\n"
	}
    - @return if the initialization is successful
  2) fromHtmlToJs
    - @param html:String the original string (Maybe HTML) you want to convert into Javascript String
    - @return the resulting String of code for Javascript

html-to-js.js's People

Contributors

waychan23 avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.