Skip to content

simple indent sanitization for multi line strings

License

Notifications You must be signed in to change notification settings

cdxOo/block-quote

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@cdxoo/block-quote

Simple indent sanitization for multi line strings via tag for template literals in es6.

Installation

npm install --save @cdxoo/block-quote

Usage

const bq = require('@cdxoo/block-quote');
    
let str1 = bq`
    alice
        foo
        bar
    bob
        baz
`;
//    | <- beginning of the line
// => |alice
//    |    foo
//    |    bar
//    |bob
//    |    baz

// also works when code itself is indented deeper
// and placeholders are used; e.g.:
let getInner = () => (
    (
        (
            bq`
                inner {
                    foo
                    bar
                }
            `
        )
    )
);
let str1 = bq`
    outer {
        ${ getInner() }
    }
`;
// => |outer {
//    |    inner {
//    |        foo
//    |        bar
//    |    }
//    |}