Skip to content

Commit

Permalink
📦 0.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
geminorum committed Jan 22, 2017
1 parent 4bb608b commit ce9aaa9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.12.0
### Added
- new option: `preserve_brackets`
- new option: `preserve_braces`


## 0.11.0
### Added
- new option: kashidas_as_parenthetic.
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ _all options are enabled by default._
- preserve all URI links in the text


* `preserve_brackets`
- preserve strings inside square brackets (`[]`)


* `preserve_braces`
- preserve strings inside curly braces (`{}`)

## License

This software is licensed under the MIT License. [View the license](LICENSE).
36 changes: 35 additions & 1 deletion lib/virastar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Virastar - v0.11.0 - 2017-1-12
* Virastar - v0.12.0 - 2017-01-22
* https://github.com/juvee/virastar
* Licensed: MIT
*/
Expand Down Expand Up @@ -56,6 +56,8 @@
cleanup_begin_and_end: true,
preserve_HTML: true,
preserve_URIs: true,
preserve_brackets: true,
preserve_braces: true,
};

for (var i in options) {
Expand Down Expand Up @@ -92,6 +94,24 @@
});
}

// removing brackets bringing them back at the end of process
if (opts.preserve_brackets) {
var brackets = [];
text = text.replace(/(\[.*?\])/g, function(matched) {
brackets.push(matched);
return "__BRACKETS__PRESERVER__";
});
}

// removing braces bringing them back at the end of process
if (opts.preserve_braces) {
var braces = [];
text = text.replace(/(\{.*?\})/g, function(matched) {
braces.push(matched);
return "__BRACES__PRESERVER__";
});
}

// Windows EOL conversion to Unix format
if (opts.normalize_eol) {
text = text.replace(/(\r?\n)|(\r\n?)/g, '\n');
Expand Down Expand Up @@ -257,6 +277,20 @@
if (opts.cleanup_begin_and_end)
text = text.replace(/^[\s\u200c]+|[\s\u200c]+$/g, '');

// bringing back braces
if (opts.preserve_braces) {
text = text.replace(/__BRACES__PRESERVER__/g, function() {
return braces.shift();
});
}

// bringing back brackets
if (opts.preserve_brackets) {
text = text.replace(/__BRACKETS__PRESERVER__/g, function() {
return brackets.shift();
});
}

// bringing back URIs
if (opts.preserve_URIs) {
text = text.replace(/__URI__PRESERVER__/g, function() {
Expand Down
4 changes: 2 additions & 2 deletions lib/virastar.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ce9aaa9

Please sign in to comment.