Skip to content

Commit 4b883b7

Browse files
authored
Merge pull request #37 from funzin/remove-file-extension
Changed not to look at file extension
2 parents ce992cc + 9d02bed commit 4b883b7

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

spec/js/convert-to-img-tag-spec.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ describe("convertToImgTag", function(){
3838
expect(result).toEqual(null)
3939
})
4040
})
41+
42+
describe('when text does not contain file extension', function () {
43+
beforeEach(function () {
44+
text = "hogehoge![title](https://user-images.githubusercontent.com/test0)\n \
45+
hogehoge![title](https://img.esa.io/uploads/production/pictures/image/test1)"
46+
result = convertToImgTag(text, "")
47+
})
48+
it('should return replaced text', function () {
49+
text = "hogehoge<img src=https://user-images.githubusercontent.com/test0 >\n \
50+
hogehoge<img src=https://img.esa.io/uploads/production/pictures/image/test1 >"
51+
expect(result).toEqual(text)
52+
})
53+
})
4154
})
4255

4356
describe("convertOnlySelectionToImgTag", function(){
@@ -213,13 +226,21 @@ describe('createMarkdownImages', function () {
213226
})
214227
})
215228
})
216-
describe('when text contains only different extension', function () {
229+
describe('when text does not contain file extension', function () {
217230
beforeEach(function () {
218-
text = "hogehoge![title](https://user-images.githubusercontent.com/test.mp3)hogehoge"
231+
text = "hogehoge![title](https://user-images.githubusercontent.com/test)hogehoge"
219232
result = createMarkdownImages(text, "")
220233
})
221-
it('should return null ', function () {
222-
expect(result).toEqual(null)
234+
it('should match one md image ', function () {
235+
let markdownImage = result[0]
236+
let imageURL = "https://user-images.githubusercontent.com/test"
237+
let imageTag = "<img src=https://user-images.githubusercontent.com/test >"
238+
let mdImageText = "![title](https://user-images.githubusercontent.com/test)"
239+
240+
expect(result.length).toEqual(1)
241+
expect(markdownImage.url).toEqual(imageURL)
242+
expect(markdownImage.imageTag).toEqual(imageTag)
243+
expect(markdownImage.mdImageText).toEqual(mdImageText)
223244
})
224245
})
225246
describe('when text contains md image', function () {

src/js/convert-to-img-tag.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ function convertToImgTag(text, params) {
6060

6161
function createMarkdownImages(text, params) {
6262
let markdownImageArray = []
63-
const results = text.match(/\!\[.*?\]\(https:\S+?(jpg|jpeg|png|gif)\)/gmi)
63+
const results = text.match(/\!\[.*?\]\(https:\S+?\)/gmi)
6464
if (results == null) { return null }
6565

6666
for (const mdImage of results) {
67-
const imageURL = mdImage.match(/https:\S+(jpg|jpeg|png|gif)/i)[0]
67+
const imageURL = mdImage.match(/\((\S+)\)/i)[1]
6868
const imageTag = `<img src=${imageURL} ${params}>`
6969
const markdownImage = new MarkdownImage(imageURL, mdImage, imageTag)
7070
markdownImageArray.push(markdownImage)

0 commit comments

Comments
 (0)