implement "special symbols" (switch certain strings for utf-8 symbols), fixes #3140
This commit is contained in:
parent
8d512c22ac
commit
6613522097
2 changed files with 53 additions and 0 deletions
|
|
@ -53,6 +53,30 @@
|
|||
return text;
|
||||
});
|
||||
|
||||
// make nice little utf-8 symbols
|
||||
converter.hooks.chain("preConversion", function(text) {
|
||||
var input_strings = [
|
||||
"<->", "->", "<-",
|
||||
"(c)", "(r)", "(tm)",
|
||||
"<3"
|
||||
];
|
||||
var output_symbols = [
|
||||
"↔", "→", "←",
|
||||
"©", "®", "™",
|
||||
"♥"
|
||||
];
|
||||
// quote function from: http://stackoverflow.com/a/494122
|
||||
var quote = function(str) {
|
||||
return str.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
|
||||
};
|
||||
|
||||
_.each(input_strings, function(str, idx) {
|
||||
var r = new RegExp(quote(str), "gi");
|
||||
text = text.replace(r, output_symbols[idx]);
|
||||
});
|
||||
return text;
|
||||
});
|
||||
|
||||
converter.hooks.chain("postConversion", function (text) {
|
||||
return text.replace(/(\"(?:(?:http|https):\/\/)?[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(?:\/\S*)?\")(\>)/g, '$1 target="_blank">')
|
||||
});
|
||||
|
|
|
|||
|
|
@ -46,6 +46,35 @@ describe("app.helpers.textFormatter", function(){
|
|||
})
|
||||
});
|
||||
|
||||
context("symbol conversion", function() {
|
||||
beforeEach(function() {
|
||||
this.input_strings = [
|
||||
"->", "<-", "<->",
|
||||
"(c)", "(r)", "(tm)",
|
||||
"<3"
|
||||
];
|
||||
this.output_symbols = [
|
||||
"→", "←", "↔",
|
||||
"©", "®", "™",
|
||||
"♥"
|
||||
];
|
||||
});
|
||||
|
||||
it("correctly converts the input strings to their corresponding output symbol", function() {
|
||||
_.each(this.input_strings, function(str, idx) {
|
||||
var text = this.formatter.markdownify(str);
|
||||
expect(text).toContain(this.output_symbols[idx]);
|
||||
}, this);
|
||||
});
|
||||
|
||||
it("converts all symbols at once", function() {
|
||||
var text = this.formatter.markdownify(this.input_strings.join(" "));
|
||||
_.each(this.output_symbols, function(sym) {
|
||||
expect(text).toContain(sym);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context("non-ascii url", function() {
|
||||
beforeEach(function() {
|
||||
this.evilUrls = [
|
||||
|
|
|
|||
Loading…
Reference in a new issue