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

Updated regex pattern for better match #902

Merged
merged 1 commit into from
Mar 4, 2017

Conversation

jozjan
Copy link
Contributor

@jozjan jozjan commented Feb 23, 2017

Fix to match markdown img tag that contains:

  1. space in the filename
  2. alt and title

such as:

![arduino with a photoresistor](images/arduino with a photoresistor.png "Arduino Physical Layout")

that normally renders to:

<img src="images/arduino with a photoresistor.png" alt="arduino with a photoresistor" title="Arduino Physical Layout">

Fix to match markdown img tag that contains:
1. space in the filename
2. alt and title
such as:
![arduino with a photoresistor](images/arduino with a photoresistor.png
\"Arduino Physical Layout\")
@juhasch
Copy link
Member

juhasch commented Feb 25, 2017

Thanks. Yes, I guess the regex can definitely be improved.
In your approach you removed the ability to add additional parameters like width=50px.
Could you add that again ?

@jozjan
Copy link
Contributor Author

jozjan commented Feb 27, 2017

Hi @juhasch , can you please give me an example of such situation?

I guess the simplified regex '<img\s+src="([^"]+)"' should only match the the img tag followed with a space and the src attribute with the image uri inside the quotes. No other character inside the img tag is being matched.
If such match is found, the regex.sub() will only replace the matched string - thus not touching other possible attributes such as alt, width, etc. in the remaining part of the img tag.
Maybe I am missing something :-/

@juhasch
Copy link
Member

juhasch commented Mar 4, 2017

OK, I took a closer look. You are right, it works as it should.
I was thinking of something like <img src="myimage.jpg" width="50%" />

@juhasch juhasch merged commit aab9670 into ipython-contrib:master Mar 4, 2017
@jozjan jozjan deleted the html_embed_fix branch March 6, 2017 08:58
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