Skip to content

Commit

Permalink
🆕 preserve frontmatter
Browse files Browse the repository at this point in the history
  • Loading branch information
geminorum committed Feb 2, 2020
1 parent 048f876 commit 30307b8
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/virastar.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
preserve_brackets: false,
preserve_comments: true,
preserve_entities: true,
preserve_frontmatter: true,
preserve_HTML: true,
preserve_nbsps: true,
preserve_URIs: true,
Expand Down Expand Up @@ -191,6 +192,15 @@
// single space padding on the end of string
text = text + ' ';

// removing frontmatter to bring back at the end of process
if (opts.preserve_frontmatter) {
var frontmatter = [];
text = text.replace(/^---[\S\s]*---\s*/g, function (matched) {
frontmatter.push(matched);
return '__FRONTMATTER__PRESERVER__';
});
}

// removing HTML tags to bring them back at the end of process
// @props: @wordpress/wordcount
if (opts.preserve_HTML) {
Expand Down Expand Up @@ -478,6 +488,13 @@
});
}

// bringing back frontmatter
if (opts.preserve_frontmatter) {
text = text.replace(/__FRONTMATTER__PRESERVER__/g, function () {
return frontmatter.shift();
});
}

return text;
},

Expand Down

0 comments on commit 30307b8

Please sign in to comment.