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

Make squirt recognise spaces before elements #103

Merged
merged 1 commit into from
Mar 17, 2014
Merged

Make squirt recognise spaces before elements #103

merged 1 commit into from
Mar 17, 2014

Conversation

nomicode
Copy link
Contributor

This pull request fixes issue #39 (previously #72) where squirt would not recognise spaces before inline elements such as hyperlinks.

@cameron
Copy link
Owner

cameron commented Mar 17, 2014

Sorry I haven't been engaged with this today—spent most of my dev time banging my head against DNS/SSL issues (with success, thankfully—squirt.io is now https enabled). Have a question about the regex..

@@ -490,7 +490,7 @@ var readability = {
child = node.childNodes[childIdx];
nodeName = child.nodeName.toLowerCase();
if(nodeName == "#text"){
text += child.nodeValue.trim('\n');
text += child.nodeValue.replace(/^\n+/, "").replace(/\n+$/, "");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this different from trim? Looking at the trim docs on MDN, they suggest almost the same regex (/^\s+|\s+$/g). Not sure how this would address the issue of spaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but \s means all whitespace.

Firefox and Chrome:

    > "\n abc \n".trim()
    "abc"

So this is where the spaces are being wrongly removed. If you merge this patch, you'll see that it fixes the problem.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see—trim doesn't accept an argument, so passing '\n' was ineffective...

cameron added a commit that referenced this pull request Mar 17, 2014
Make squirt recognise spaces before elements
@cameron cameron merged commit 660bbc4 into cameron:master Mar 17, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants