-
Notifications
You must be signed in to change notification settings - Fork 798
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
Allow permalinking to lines #43
Conversation
This breaks JavaDoc styling. |
@ammaraskar Ok here's a kind-of fix: // Injects code with line spans in to the code box
haste.prototype.setCode = function(code) {
var lines = new Array();
// Will contain the parent classes
var currentContainerClasses = [];
$.each(code.split("\n"), function (index, value) {
// Line numbers aren't 0 based :)
var index = index + 1;
// Use a string containing all parent classes, or just line if there's none
var classString = currentContainerClasses.length == 0 ? 'line' : currentContainerClasses.join(' ');
lines[index] = "<span class='" + classString + "' rel='L" + index + "'>" + value + "</span>\n";
// Count opened and closed spans
var open = value.match(new RegExp('<span','g'));
var close = value.match(new RegExp('<\\/span>','g'));
var openCount = open ? open.length : 0;
var closeCount = close ? close.length : 0;
if (openCount > closeCount) {
// New parent class !
var firstClassOfValue = value.split(new RegExp('<\\/span>','g'))[0].match(new RegExp('<span class="([a-zA-Z]+)">'))[1];
currentContainerClasses.push(firstClassOfValue);
} else if (openCount < closeCount) {
// Closed a span !
currentContainerClasses.pop();
}
});
this.$code.html(lines.join(""));
} It maybe lacks some checks, but it's working. Thanks to SpaceEmotion and kiwhen for helping me with the strange things that regex are. |
Feature request: Can you implement section highlighting like with github? I mean when you shift-click a line and highlight a whole section. |
👍 |
Any update? |
Thanks for the contribution! |
Ohey this thing, so the issue mentioned above where it breaks the highlighter on occasion is caused by the fact that I decided to use s for links as seen here: https://github.com/seejohnrun/haste-server/pull/43/files#diff-48f187de8cdff79f6b6ec3a932963c25R235 Sometimes this causes the highlighter's own span tags to be closed off prematurely. I'll probably be able to update this later in the week according to any input from you and that request above to highlight sections |
@ammaraskar couldn't we use a different element type than just a flat span? |
@@ -201,6 +227,16 @@ haste.prototype.removeLineNumbers = function() { | |||
$('#linenos').html('>'); | |||
}; | |||
|
|||
// Injects code with line spans in to the code box | |||
haste.prototype.setCode = function(code) { | |||
var lines = new Array(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change to []
Can I expect this to come soon? |
@gt-c Just given the age of the PR we'll need some cleanup here / shouldn't be too hard to get it up to date but it'll be a bit before I have time personally |
ok :D thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ammaraskar
Thank you for contributing!
Can you please verify @seejohnrun comments and also one of my own?
Also, please update the branch with latest master
changes.
|
||
.line.highlight { | ||
background-color: #004A5E; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please fix EOL?
This PR is stale because it has been open for 30 days with no activity. |
This PR was closed because it has been inactive for 14 days since being marked as stale. |
Allows you to click on lines and grab a hash based permalink to it in your url bar, much like in github.
Demonstration: http://paste.md-5.net/pomiqeyeye.cs#L17
There is one hack in here I'm not real proud of: https://github.com/seejohnrun/haste-server/pull/43/files#L3R21 but I can't really figure out a nice way to work around that properly. Basically when you change the hash, it calls the pop event because the history changes. Feel free to offer any better solutions to the problem if you have any.