Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

WIP #113

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dist/sir-trevor.css
Original file line number Diff line number Diff line change
Expand Up @@ -483,3 +483,7 @@ ul.st-text-block {

.st-format-btn--Unlink {
text-decoration: line-through; }

.st-format-btn--Strikethrough {
text-decoration: line-through;
font-family: Arial; }
23 changes: 20 additions & 3 deletions dist/sir-trevor.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@
.replace(/\[([^\]]+)\]\(([^\)]+)\)/g,"<a href='$2'>$1</a>")
.replace(/([\W_]|^)(\*\*|__)(?=\S)([^\r]*?\S[\*_]*)\2([\W_]|$)/g, "$1<strong>$3</strong>$4")
.replace(/([\W_]|^)(\*|_)(?=\S)([^\r\*_]*?\S)\2([\W_]|$)/g, "$1<em>$3</em>$4")
.replace(/(?:~~)([^*|_]+)(?:~~)/mg,"<strike>$1</strike>")
.replace(/\n\n/g, "<br>");

// Use custom formatters toHTML functions (if any exist)
Expand Down Expand Up @@ -496,7 +497,8 @@
.replace(/<\/?b>/g,"**")
.replace(/<\/?STRONG>/gi,"**") // Bold
.replace(/<\/?i>/g,"_")
.replace(/<\/?EM>/gi,"_"); // Italic
.replace(/<\/?EM>/gi,"_") // Italics
.replace(/<\/?strike>/gi,"~~"); // Strike

// Use custom formatters toMarkdown functions (if any exist)
var formatName, format;
Expand Down Expand Up @@ -952,7 +954,14 @@
};
},

save: function() { this.toData(); },
save: function() {
this.toData();
},

saveAndReturnData: function() {
this.save();
return this.blockStorage;
},

getData: function() {
return this.blockStorage.data;
Expand Down Expand Up @@ -2032,6 +2041,13 @@
text : "link"
});

var Strikethrough = SirTrevor.Formatter.extend({
title: "strikethrough",
iconName: "strikethrough",
cmd: "strikeThrough",
text : "s"
});

/*
Create our formatters and add a static reference to them
*/
Expand All @@ -2040,6 +2056,7 @@
SirTrevor.Formatters.Underline = new Underline();
SirTrevor.Formatters.Link = new Link();
SirTrevor.Formatters.Unlink = new UnLink();
SirTrevor.Formatters.Strikethrough = new Strikethrough();

})();
/* Marker */
Expand Down Expand Up @@ -2619,7 +2636,7 @@
},

saveBlockStateToStore: function(block) {
var store = block.save();
var store = block.saveAndReturnData();
if(store && !_.isEmpty(store.data)) {
SirTrevor.log("Adding data for block " + block.blockID + " to block store");
this.store("add", this, { data: store });
Expand Down
4 changes: 2 additions & 2 deletions dist/sir-trevor.min.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions spec/javascripts/units/to_html.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ describe("toHTML", function(){
expect(html).toBe("hello!<br>hello!");
});

it("converts strikes to HTML", function(){
var markdown = "~~test strike~~",
html = SirTrevor.toHTML(markdown, "Text");

expect(html).toBe("<strike>test strike</strike>");
});

it("doesn't mess up on links with _ in", function(){
var markdown = "http://google.com/_ and this is_ more text http://google.com/_",
html = SirTrevor.toHTML(markdown, "Text");
Expand Down
7 changes: 7 additions & 0 deletions spec/javascripts/units/to_markdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ describe("toMarkdown", function(){
expect(markdown).toBe("testing\n\n\n\n");
});

it("coverts strikes to newlines", function(){
var html = "<strike>testing</strike>",
markdown = SirTrevor.toMarkdown(html, "Text");

expect(markdown).toBe("~~testing~~");
});

it("coverts br's to newlines", function(){
var html = "testing<br>",
markdown = SirTrevor.toMarkdown(html, "Text");
Expand Down
9 changes: 8 additions & 1 deletion src/block.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ SirTrevor.BlockStore = {
};
},

save: function() { this.toData(); },
save: function() {
this.toData();
},

saveAndReturnData: function() {
this.save();
return this.blockStorage;
},

getData: function() {
return this.blockStorage.data;
Expand Down
8 changes: 8 additions & 0 deletions src/formatters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@
text : "link"
});

var Strikethrough = SirTrevor.Formatter.extend({
title: "strikethrough",
iconName: "strikethrough",
cmd: "strikeThrough",
text : "s"
});

/*
Create our formatters and add a static reference to them
*/
Expand All @@ -60,5 +67,6 @@
SirTrevor.Formatters.Underline = new Underline();
SirTrevor.Formatters.Link = new Link();
SirTrevor.Formatters.Unlink = new UnLink();
SirTrevor.Formatters.Strikethrough = new Strikethrough();

})();
5 changes: 5 additions & 0 deletions src/sass/format-bar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@

.st-format-btn--Unlink {
text-decoration: line-through;
}

.st-format-btn--Strikethrough {
text-decoration: line-through;
font-family: Arial;
}
2 changes: 1 addition & 1 deletion src/sir-trevor-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ SirTrevor.Editor = (function(){
},

saveBlockStateToStore: function(block) {
var store = block.save();
var store = block.saveAndReturnData();
if(store && !_.isEmpty(store.data)) {
SirTrevor.log("Adding data for block " + block.blockID + " to block store");
this.store("add", this, { data: store });
Expand Down
1 change: 1 addition & 0 deletions src/to-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ SirTrevor.toHTML = function(markdown, type) {
.replace(/\[([^\]]+)\]\(([^\)]+)\)/g,"<a href='$2'>$1</a>")
.replace(/([\W_]|^)(\*\*|__)(?=\S)([^\r]*?\S[\*_]*)\2([\W_]|$)/g, "$1<strong>$3</strong>$4")
.replace(/([\W_]|^)(\*|_)(?=\S)([^\r\*_]*?\S)\2([\W_]|$)/g, "$1<em>$3</em>$4")
.replace(/(?:~~)([^*|_]+)(?:~~)/mg,"<strike>$1</strike>")
.replace(/\n\n/g, "<br>");

// Use custom formatters toHTML functions (if any exist)
Expand Down
3 changes: 2 additions & 1 deletion src/to-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ SirTrevor.toMarkdown = function(content, type) {
.replace(/<\/?b>/g,"**")
.replace(/<\/?STRONG>/gi,"**") // Bold
.replace(/<\/?i>/g,"_")
.replace(/<\/?EM>/gi,"_"); // Italic
.replace(/<\/?EM>/gi,"_") // Italics
.replace(/<\/?strike>/gi,"~~"); // Strike

// Use custom formatters toMarkdown functions (if any exist)
var formatName, format;
Expand Down