codescape
A node tool to escape characters to html entities and to convert tabs to spaces so that your code indentation and symbols does not change in blogs or websites.
Installation
npm install codescape
Usage
It requires an object as an argument. The parameter object has 4 properties :-
-
'string'
: It specifies the html string. If string is specified then it returns the escaped string. -
'filename'
: It specifies the filename of which contents you want to escape. Only one parameter should be present. It can either befilename
orstring
. The input file will be overwritten. -
'selector'
: It specifies the selection query which we use in jquery. Codescape will select the specified portion of the html based on your selector. If selector is not specified then the whole content will be escaped. -
'callback'
: It is the function which will be called after successful or unsuccessful escaping. It is only valid if you are passing afilename
for escaping. On successful escaping, callback will be passedtrue
otherwisefalse
Example
ALl possible uses of the codescape tool.
var codescape = ;var string = '<p class='example'><code>Some Code</code></p>' ;var selector = 'p.example code' ;var { console ;} ; //string operations var escapedString = ; // string without selectorvar escapedCode = ; //string with selector // file operations //escapes whole file without callback //escapes whole file with callback //escapes only selected portion and replaces that portion of the file with the escaped code without callback //escapes selected portion of file with callback