GithubHelp home page GithubHelp logo

Comments (11)

gregjacobs avatar gregjacobs commented on May 24, 2024

It shouldn't touch any attribute. Do you have an example where it is?

from autolinker.js.

alphatwit avatar alphatwit commented on May 24, 2024

I was mistaken about the cause. It works fine with the src attribute alone, but my tag contains more stuff.

<img src='http://terryshoemaker.files.wordpress.com/2013/03/placeholder1.jpg' style=' height: 22px; background-color: rgb(0, 188, 204); border-radius: 7px; padding: 2px; margin: 0px 2px;'>

turns into

<img src="&lt;a href=&quot;http://terryshoemaker.files.wordpress.com/2013/03/placeholder1.jpg&quot; target=&quot;_blank&quot;&gt;terryshoemaker.files.wordpress.com/2013/03/placeholder1.jpg&lt;/a&gt;" style=" height: 22px; background-color: rgb(0, 188, 204); border-radius: 7px; padding: 2px; margin: 0px 2px;">

from autolinker.js.

gregjacobs avatar gregjacobs commented on May 24, 2024

Anything happen differently if you remove the whitespace before height: 22px?

from autolinker.js.

gregjacobs avatar gregjacobs commented on May 24, 2024

(still a bug either way btw, just curious. Might be able to take a look tomorrow)

from autolinker.js.

alphatwit avatar alphatwit commented on May 24, 2024

Yeah, removing the space does fix it.

I'm using AngularJS, so I've got a bit in the html that has nested and escaped quotes, so that space sneaks in there somehow.

from autolinker.js.

gregjacobs avatar gregjacobs commented on May 24, 2024

Hey @alphatwit. So sorry for the late reply. I finally got a chance to look at this.

However, I can't seem to reproduce the issue. Are you using the latest version? If so, can you post more of your HTML? Perhaps another tag that surrounds your image is causing the problem. Also, can you post the options that you're using?

Thanks,
Greg

from autolinker.js.

juliomenendez avatar juliomenendez commented on May 24, 2024

Same thing was happening to me with this piece of HTML:

Just a flower image <img src="https://farm9.staticflickr.com/8378/8578790632_83c6471f3f_b.jpg" />

The problem is the htmlRegex wasn't recognizing the IMG tag with attributes. I changed that regular expression to one way simpler:

htmlRegex : /<(\/)?([0-9a-zA-Z:]+)(?:\s+[^>]+)*\s*>/g,

In yours you are trying to parse the attributes but never use them so, sorry for asking but, what's the point? @alphatwit give this regular expression a try please.

from autolinker.js.

alphatwit avatar alphatwit commented on May 24, 2024

I've changed my code since then, but it was something like this:

<form class="approval-form" name="thumbsUp" ng-submit="postApproval()"> <button type="submit"> <img class="thumbs-up" ng-click="comment.body='<img src=\'http://example.com/api-public/images/wg/w/Rating_and_Approval/icon-thumbs-up.png\' style=\'height: 22px; background-color: rgb(0, 188, 204); border-radius: 7px; padding: 2px; margin: 0px 2px;\'>'+comment.body;" ng-src="http://example.com/api-public/images/wg/w/Rating_and_Approval/icon-thumbs-up.png"> </button> </form>

from autolinker.js.

juliomenendez avatar juliomenendez commented on May 24, 2024

Ah, got it, the issue in your HTML is with the IMG tag quoted inside the comment.body. In that case I'd recommend move the click implementation to the controller instead of the template and run Autolinker.link on the comment element after that.

from autolinker.js.

alphatwit avatar alphatwit commented on May 24, 2024

It's just prepending the html as a string to the comment.body. The mess of quotes and escaped quotes is because I'm doing it all in the template. That gets sent to the server. This is the code that is supposed to display the stuff inside comment.body

'<p ng-class="{\'message-snippet\':true}">' + '<span ng-bind-html = "message.data.body | autoLinker | unsafe"></span>'+ '</p >' +

At some point that space makes it into the style attribute and that causes the thing to break.

from autolinker.js.

gregjacobs avatar gregjacobs commented on May 24, 2024

@juliomenendez, in your example, the img tag's src attribute wasn't actually the problem. The htmlRegex in Autolinker wasn't handling self-closing tags.. Whoops! I'm surprised nobody noticed this until now. Fixed in 0.11.1

The reason for the more-complex htmlRegex in the code is to try to handle as many cases as possible. The simpler regex wouldn't work correctly if an attribute had a > character within it :)

@alphatwit, are you still having a problem? I wouldn't recommend having tags within tags, although copying/pasting your example seems to still autolink correctly. If you're still having a problem, can you copy/paste the html that is produced by your template before autolinking?

from autolinker.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.